/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2002-2006, GeoTools Project Managment Committee (PMC)
 *    (C) 2002, Centre for Computational Geography
 *    
 *    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;
 *    version 2.1 of the License.
 *
 *    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.
 */
package org.geotools.styling;


// J2SE dependencies
//import java.util.logging.Logger;
// OpenGIS dependencies
import org.geotools.event.AbstractGTComponent;
import org.geotools.resources.Utilities;
import org.opengis.filter.expression.Expression;
import org.opengis.util.Cloneable;


/**
 * Provides a Java representation of the Font element of an SLD.
 *
 * @author Ian Turton, CCG
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/FontImpl.java $
 * @version $Id: FontImpl.java 27862 2007-11-12 19:51:19Z desruisseaux $
 */
public class FontImpl extends AbstractGTComponent implements Font, Cloneable {
    /** The logger for the default core module. */

    //private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geotools.core");
    private Expression fontFamily = null;
    private Expression fontSize = null;
    private Expression fontStyle = null;
    private Expression fontWeight = null;

    /**
     * Creates a new instance of DefaultFont
     */
    protected FontImpl() {
    }

    /**
     * Getter for property fontFamily.
     *
     * @return Value of property fontFamily.
     */
    public Expression getFontFamily() {
        return fontFamily;
    }

    /**
     * Setter for property fontFamily.
     *
     * @param fontFamily New value of property fontFamily.
     */
    public void setFontFamily(Expression fontFamily) {
        this.fontFamily = fontFamily;
        fireChanged();
    }

    /**
     * Getter for property fontSize.
     *
     * @return Value of property fontSize.
     */
    public Expression getFontSize() {
        return fontSize;
    }

    /**
     * Setter for property fontSize.
     *
     * @param fontSize New value of property fontSize.
     */
    public void setFontSize(Expression fontSize) {
        this.fontSize = fontSize;
        fireChanged();
    }

    /**
     * Getter for property fontStyle.
     *
     * @return Value of property fontStyle.
     */
    public Expression getFontStyle() {
        return fontStyle;
    }

    /**
     * Setter for property fontStyle.
     *
     * @param fontStyle New value of property fontStyle.
     */
    public void setFontStyle(Expression fontStyle) {
        this.fontStyle = fontStyle;
        fireChanged();
    }

    /**
     * Getter for property fontWeight.
     *
     * @return Value of property fontWeight.
     */
    public Expression getFontWeight() {
        return fontWeight;
    }

    /**
     * Setter for property fontWeight.
     *
     * @param fontWeight New value of property fontWeight.
     */
    public void setFontWeight(Expression fontWeight) {
        this.fontWeight = fontWeight;
        fireChanged();
    }

    /**
     * Creates a clone of the font.
     *
     * @see Cloneable#clone()
     */
    public Object clone() {
        try {
            // all the members are immutable expression
            // super.clone() is enough.
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException("This should not happen", e);
        }
    }

    /**
     * Generates the hashcode for the font.
     *
     * @return the hash code.
     */
    public int hashCode() {
        final int PRIME = 1000003;
        int result = 0;

        if (fontFamily != null) {
            result = (PRIME * result) + fontFamily.hashCode();
        }

        if (fontSize != null) {
            result = (PRIME * result) + fontSize.hashCode();
        }

        if (fontStyle != null) {
            result = (PRIME * result) + fontStyle.hashCode();
        }

        if (fontWeight != null) {
            result = (PRIME * result) + fontWeight.hashCode();
        }

        return result;
    }

    /**
     * Compares this font with another for equality.  Two fonts are equal if
     * their family, style, weight  and size are equal.
     *
     * @param oth DOCUMENT ME!
     *
     * @return True if this and oth are equal.
     */
    public boolean equals(Object oth) {
        if (this == oth) {
            return true;
        }

        if (oth == null) {
            return false;
        }

        if (oth instanceof FontImpl) {
            FontImpl other = (FontImpl) oth;

            return Utilities.equals(this.fontFamily, other.fontFamily)
            && Utilities.equals(this.fontSize, other.fontSize)
            && Utilities.equals(this.fontStyle, other.fontStyle)
            && Utilities.equals(this.fontWeight, other.fontWeight);
        }

        return false;
    }
}
