001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2002, Centre for Computational Geography
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.styling;
018:
019: // J2SE dependencies
020: //import java.util.logging.Logger;
021: // OpenGIS dependencies
022: import org.geotools.event.AbstractGTComponent;
023: import org.geotools.resources.Utilities;
024: import org.opengis.filter.expression.Expression;
025: import org.opengis.util.Cloneable;
026:
027: /**
028: * Provides a Java representation of the Font element of an SLD.
029: *
030: * @author Ian Turton, CCG
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/FontImpl.java $
032: * @version $Id: FontImpl.java 27862 2007-11-12 19:51:19Z desruisseaux $
033: */
034: public class FontImpl extends AbstractGTComponent implements Font,
035: Cloneable {
036: /** The logger for the default core module. */
037:
038: //private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.geotools.core");
039: private Expression fontFamily = null;
040: private Expression fontSize = null;
041: private Expression fontStyle = null;
042: private Expression fontWeight = null;
043:
044: /**
045: * Creates a new instance of DefaultFont
046: */
047: protected FontImpl() {
048: }
049:
050: /**
051: * Getter for property fontFamily.
052: *
053: * @return Value of property fontFamily.
054: */
055: public Expression getFontFamily() {
056: return fontFamily;
057: }
058:
059: /**
060: * Setter for property fontFamily.
061: *
062: * @param fontFamily New value of property fontFamily.
063: */
064: public void setFontFamily(Expression fontFamily) {
065: this .fontFamily = fontFamily;
066: fireChanged();
067: }
068:
069: /**
070: * Getter for property fontSize.
071: *
072: * @return Value of property fontSize.
073: */
074: public Expression getFontSize() {
075: return fontSize;
076: }
077:
078: /**
079: * Setter for property fontSize.
080: *
081: * @param fontSize New value of property fontSize.
082: */
083: public void setFontSize(Expression fontSize) {
084: this .fontSize = fontSize;
085: fireChanged();
086: }
087:
088: /**
089: * Getter for property fontStyle.
090: *
091: * @return Value of property fontStyle.
092: */
093: public Expression getFontStyle() {
094: return fontStyle;
095: }
096:
097: /**
098: * Setter for property fontStyle.
099: *
100: * @param fontStyle New value of property fontStyle.
101: */
102: public void setFontStyle(Expression fontStyle) {
103: this .fontStyle = fontStyle;
104: fireChanged();
105: }
106:
107: /**
108: * Getter for property fontWeight.
109: *
110: * @return Value of property fontWeight.
111: */
112: public Expression getFontWeight() {
113: return fontWeight;
114: }
115:
116: /**
117: * Setter for property fontWeight.
118: *
119: * @param fontWeight New value of property fontWeight.
120: */
121: public void setFontWeight(Expression fontWeight) {
122: this .fontWeight = fontWeight;
123: fireChanged();
124: }
125:
126: /**
127: * Creates a clone of the font.
128: *
129: * @see Cloneable#clone()
130: */
131: public Object clone() {
132: try {
133: // all the members are immutable expression
134: // super.clone() is enough.
135: return super .clone();
136: } catch (CloneNotSupportedException e) {
137: throw new RuntimeException("This should not happen", e);
138: }
139: }
140:
141: /**
142: * Generates the hashcode for the font.
143: *
144: * @return the hash code.
145: */
146: public int hashCode() {
147: final int PRIME = 1000003;
148: int result = 0;
149:
150: if (fontFamily != null) {
151: result = (PRIME * result) + fontFamily.hashCode();
152: }
153:
154: if (fontSize != null) {
155: result = (PRIME * result) + fontSize.hashCode();
156: }
157:
158: if (fontStyle != null) {
159: result = (PRIME * result) + fontStyle.hashCode();
160: }
161:
162: if (fontWeight != null) {
163: result = (PRIME * result) + fontWeight.hashCode();
164: }
165:
166: return result;
167: }
168:
169: /**
170: * Compares this font with another for equality. Two fonts are equal if
171: * their family, style, weight and size are equal.
172: *
173: * @param oth DOCUMENT ME!
174: *
175: * @return True if this and oth are equal.
176: */
177: public boolean equals(Object oth) {
178: if (this == oth) {
179: return true;
180: }
181:
182: if (oth == null) {
183: return false;
184: }
185:
186: if (oth instanceof FontImpl) {
187: FontImpl other = (FontImpl) oth;
188:
189: return Utilities.equals(this .fontFamily, other.fontFamily)
190: && Utilities.equals(this .fontSize, other.fontSize)
191: && Utilities
192: .equals(this .fontStyle, other.fontStyle)
193: && Utilities.equals(this .fontWeight,
194: other.fontWeight);
195: }
196:
197: return false;
198: }
199: }
|