/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2017, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
 * Other names may be trademarks of their respective owners.]
 *
 */

package org.jfree.chart.ui;

import java.io.ObjectStreamException;
import java.io.Serializable;

/**
 * Used to indicate either the foreground or background layer.
 */
public final class Layer implements Serializable {

    /** For serialization. */
    private static final long serialVersionUID = -1470104570733183430L;
    
    /** Foreground. */
    public static final Layer FOREGROUND = new Layer("Layer.FOREGROUND");

    /** Background. */
    public static final Layer BACKGROUND = new Layer("Layer.BACKGROUND");

    /** The name. */
    private String name;

    /**
     * Private constructor.
     *
     * @param name  the name.
     */
    private Layer(String name) {
        this.name = name;
    }

    /**
     * Returns a string representing the object.
     *
     * @return The string.
     */
    @Override
    public String toString() {
        return this.name;
    }

    /**
     * Returns {@code true} if this object is equal to the specified 
     * object, and {@code false} otherwise.
     *
     * @param o  the other object.
     *
     * @return A boolean.
     */
    public boolean equals(Object o) {

        if (this == o) {
            return true;
        }
        if (!(o instanceof Layer)) {
            return false;
        }

        Layer layer = (Layer) o;
        if (!this.name.equals(layer.name)) {
            return false;
        }

        return true;

    }

    /**
     * Returns a hash code value for the object.
     *
     * @return the hashcode
     */
    @Override
    public int hashCode() {
        return this.name.hashCode();
    }

    /**
     * Ensures that serialization returns the unique instances.
     * 
     * @return The object.
     * 
     * @throws ObjectStreamException if there is a problem.
     */
    private Object readResolve() throws ObjectStreamException {
        Layer result = null;
        if (this.equals(Layer.FOREGROUND)) {
            result = Layer.FOREGROUND;
        }
        else if (this.equals(Layer.BACKGROUND)) {
            result = Layer.BACKGROUND;
        }
        return result;
    }
    
}



@@ -1255,76 +1255,8 @@
 i;%0A%0A
-import java.io.ObjectStreamException;%0Aimport java.io.Serializable;%0A%0A
 /**%0A
@@ -1333,235 +1333,59 @@
 lic 
-final class Layer implements Serializable %7B%0A%0A    /** For serialization. */%0A    private static final long serialVersionUID = -1470104570733183430L;%0A    %0A    /** Foreground. */%0A    public static final Layer FOREGROUND = new Layer
+enum Layer %7B%0A%0A    /** Foreground. */%0A    FOREGROUND
 (%22La
@@ -1392,33 +1392,33 @@
 yer.FOREGROUND%22)
-;
+,
 %0A%0A    /** Backgr
@@ -1434,56 +1434,18 @@
     
-public static final Layer BACKGROUND = new Layer
+BACKGROUND
 (%22La
@@ -1609,16 +1609,22 @@
 e Layer(
+final 
 String n
@@ -1844,1219 +1844,8 @@
  %7D%0A%0A
-    /**%0A     * Returns %7B@code true%7D if this object is equal to the specified %0A     * object, and %7B@code false%7D otherwise.%0A     *%0A     * @param o  the other object.%0A     *%0A     * @return A boolean.%0A     */%0A    public boolean equals(Object o) %7B%0A%0A        if (this == o) %7B%0A            return true;%0A        %7D%0A        if (!(o instanceof Layer)) %7B%0A            return false;%0A        %7D%0A%0A        Layer layer = (Layer) o;%0A        if (!this.name.equals(layer.name)) %7B%0A            return false;%0A        %7D%0A%0A        return true;%0A%0A    %7D%0A%0A    /**%0A     * Returns a hash code value for the object.%0A     *%0A     * @return the hashcode%0A     */%0A    @Override%0A    public int hashCode() %7B%0A        return this.name.hashCode();%0A    %7D%0A%0A    /**%0A     * Ensures that serialization returns the unique instances.%0A     * %0A     * @return The object.%0A     * %0A     * @throws ObjectStreamException if there is a problem.%0A     */%0A    private Object readResolve() throws ObjectStreamException %7B%0A        Layer result = null;%0A        if (this.equals(Layer.FOREGROUND)) %7B%0A            result = Layer.FOREGROUND;%0A        %7D%0A        else if (this.equals(Layer.BACKGROUND)) %7B%0A            result = Layer.BACKGROUND;%0A        %7D%0A        return result;%0A    %7D%0A    %0A
 %7D%0A%0A%0A

Convert to enum