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: // OpenGIS dependencies
020: import org.geotools.event.AbstractGTComponent;
021: import org.geotools.resources.Utilities;
022: import org.opengis.util.Cloneable;
023:
024: /**
025: * Provides a Java representation of the PointSymbolizer. This defines how
026: * points are to be rendered.
027: *
028: * @author Ian Turton, CCG
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/PointSymbolizerImpl.java $
030: * @version $Id: PointSymbolizerImpl.java 20703 2006-07-24 16:57:44Z jgarnett $
031: */
032: public class PointSymbolizerImpl extends AbstractGTComponent implements
033: PointSymbolizer, Cloneable {
034: private String geometryPropertyName = null;
035: private Graphic graphic = new GraphicImpl();
036:
037: /**
038: * Creates a new instance of DefaultPointSymbolizer
039: */
040: protected PointSymbolizerImpl() {
041: }
042:
043: public String getGeometryPropertyName() {
044: return geometryPropertyName;
045: }
046:
047: /**
048: * Sets the Geometry Property Name.
049: *
050: * @param name The Geometry Property Name.
051: */
052: public void setGeometryPropertyName(String name) {
053: geometryPropertyName = name;
054: fireChanged();
055: }
056:
057: /**
058: * Provides the graphical-symbolization parameter to use for the point
059: * geometry.
060: *
061: * @return The Graphic to be used when drawing a point
062: */
063: public Graphic getGraphic() {
064: return graphic;
065: }
066:
067: /**
068: * Setter for property graphic.
069: *
070: * @param graphic New value of property graphic.
071: */
072: public void setGraphic(Graphic graphic) {
073: if (this .graphic == graphic) {
074: return;
075: }
076:
077: Graphic old = this .graphic;
078: this .graphic = graphic;
079: fireChildChanged("graphic", graphic, old);
080: }
081:
082: /**
083: * Accept a StyleVisitor to perform an operation on this symbolizer.
084: *
085: * @param visitor The StyleVisitor to accept.
086: */
087: public void accept(StyleVisitor visitor) {
088: visitor.visit(this );
089: }
090:
091: /**
092: * Creates a deep copy clone.
093: *
094: * @return The deep copy clone.
095: *
096: * @throws RuntimeException DOCUMENT ME!
097: */
098: public Object clone() {
099: PointSymbolizerImpl clone;
100:
101: try {
102: clone = (PointSymbolizerImpl) super .clone();
103: clone.graphic = (Graphic) ((Cloneable) graphic).clone();
104: } catch (CloneNotSupportedException e) {
105: throw new RuntimeException(e); // this should never happen.
106: }
107:
108: return clone;
109: }
110:
111: /**
112: * Generates the hashcode for the PointSymbolizer
113: *
114: * @return the hashcode
115: */
116: public int hashCode() {
117: final int PRIME = 1000003;
118: int result = 0;
119:
120: if (geometryPropertyName != null) {
121: result = (PRIME * result) + geometryPropertyName.hashCode();
122: }
123:
124: if (graphic != null) {
125: result = (PRIME * result) + graphic.hashCode();
126: }
127:
128: return result;
129: }
130:
131: /**
132: * Checks this PointSymbolizerImpl with another for equality.
133: *
134: * <p>
135: * Two PointSymbolizers are equal if the have the same geometry property
136: * name and their graphic object is equal.
137: * </p>
138: *
139: * <p>
140: * Note: this method only works for other instances of PointSymbolizerImpl,
141: * not other implementors of PointSymbolizer
142: * </p>
143: *
144: * @param oth The object to compare with this PointSymbolizerImpl for
145: * equality.
146: *
147: * @return True of oth is a PointSymbolizerImpl that is equal.
148: */
149: public boolean equals(Object oth) {
150: if (this == oth) {
151: return true;
152: }
153:
154: if (oth instanceof PointSymbolizerImpl) {
155: PointSymbolizerImpl other = (PointSymbolizerImpl) oth;
156:
157: return Utilities.equals(geometryPropertyName,
158: other.geometryPropertyName)
159: && Utilities.equals(graphic, other.graphic);
160: }
161:
162: return false;
163: }
164: }
|