001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.styling;
017:
018: // OpenGIS dependencies
019: import org.geotools.event.AbstractGTComponent;
020: import org.geotools.resources.Utilities;
021: import org.opengis.util.Cloneable;
022:
023: /**
024: * Provides a representation of a PolygonSymbolizer in an SLD Document. A
025: * PolygonSymbolizer defines how a polygon geometry should be rendered.
026: *
027: * @author James Macgill, CCG
028: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/PolygonSymbolizerImpl.java $
029: * @version $Id: PolygonSymbolizerImpl.java 20703 2006-07-24 16:57:44Z jgarnett $
030: */
031: public class PolygonSymbolizerImpl extends AbstractGTComponent
032: implements PolygonSymbolizer, Cloneable {
033: private Fill fill = new FillImpl();
034: private Stroke stroke = new StrokeImpl();
035: private String geometryPropertyName = null;
036:
037: /**
038: * Creates a new instance of DefaultPolygonStyler
039: */
040: protected PolygonSymbolizerImpl() {
041: }
042:
043: /**
044: * This property defines the geometry to be used for styling.<br>
045: * The property is optional and if it is absent (null) then the "default"
046: * geometry property of the feature should be used. Geometry types other
047: * than inherently area types can be used. If a line is used then the line
048: * string is closed for filling (only) by connecting its end point to its
049: * start point. The geometryPropertyName is the name of a geometry
050: * property in the Feature being styled. Typically, features only have
051: * one geometry so, in general, the need to select one is not required.
052: * Note: this moves a little away from the SLD spec which provides an
053: * XPath reference to a Geometry object, but does follow it in spirit.
054: *
055: * @return String The name of the attribute in the feature being styled
056: * that should be used. If null then the default geometry should
057: * be used.
058: */
059: public String getGeometryPropertyName() {
060: return geometryPropertyName;
061: }
062:
063: /**
064: * Sets the GeometryPropertyName.
065: *
066: * @param name The name of the GeometryProperty.
067: *
068: * @see #PolygonSymbolizerImpl.geometryPropertyName()
069: */
070: public void setGeometryPropertyName(String name) {
071: geometryPropertyName = name;
072: fireChanged();
073: }
074:
075: /**
076: * Provides the graphical-symbolization parameter to use to fill the area
077: * of the geometry.
078: *
079: * @return The Fill style to use when rendering the area.
080: */
081: public Fill getFill() {
082: return fill;
083: }
084:
085: /**
086: * Sets the graphical-symbolization parameter to use to fill the area of
087: * the geometry.
088: *
089: * @param fill The Fill style to use when rendering the area.
090: */
091: public void setFill(Fill fill) {
092: if (this .fill == fill) {
093: return;
094: }
095:
096: Fill old = this .fill;
097: this .fill = fill;
098: fireChildChanged("fill", fill, old);
099: }
100:
101: /**
102: * Provides the graphical-symbolization parameter to use for the outline of
103: * the Polygon.
104: *
105: * @return The Stroke style to use when rendering lines.
106: */
107: public Stroke getStroke() {
108: return stroke;
109: }
110:
111: /**
112: * Sets the graphical-symbolization parameter to use for the outline of the
113: * Polygon.
114: *
115: * @param stroke The Stroke style to use when rendering lines.
116: */
117: public void setStroke(Stroke stroke) {
118: if (this .stroke == stroke) {
119: return;
120: }
121:
122: Stroke old = this .stroke;
123: this .stroke = stroke;
124: fireChildChanged("stroke", stroke, old);
125: }
126:
127: /**
128: * Accepts a StyleVisitor to perform some operation on this LineSymbolizer.
129: *
130: * @param visitor The visitor to accept.
131: */
132: public void accept(StyleVisitor visitor) {
133: visitor.visit(this );
134: }
135:
136: /**
137: * Creates a deep copy clone. TODO: Need to complete the deep copy,
138: * currently only shallow copy.
139: *
140: * @return The deep copy clone.
141: *
142: * @throws RuntimeException DOCUMENT ME!
143: */
144: public Object clone() {
145: PolygonSymbolizerImpl clone;
146:
147: try {
148: clone = (PolygonSymbolizerImpl) super .clone();
149:
150: if (fill != null) {
151: clone.fill = (Fill) ((Cloneable) fill).clone();
152: }
153:
154: if (stroke != null) {
155: clone.stroke = (Stroke) ((Cloneable) stroke).clone();
156: }
157: } catch (CloneNotSupportedException e) {
158: throw new RuntimeException(e); // this should never happen.
159: }
160:
161: return clone;
162: }
163:
164: /**
165: * Generates a hashcode for the PolygonSymbolizerImpl.
166: *
167: * @return A hashcode.
168: */
169: public int hashCode() {
170: final int PRIME = 1000003;
171: int result = 0;
172:
173: if (fill != null) {
174: result = (PRIME * result) + fill.hashCode();
175: }
176:
177: if (stroke != null) {
178: result = (PRIME * result) + stroke.hashCode();
179: }
180:
181: if (geometryPropertyName != null) {
182: result = (PRIME * result) + geometryPropertyName.hashCode();
183: }
184:
185: return result;
186: }
187:
188: /**
189: * Compares this PolygonSymbolizerImpl with another.
190: *
191: * <p>
192: * Two PolygonSymbolizerImpls are equal if they have the same
193: * geometryProperty, fill and stroke.
194: * </p>
195: *
196: * @param oth the object to compare against.
197: *
198: * @return true if oth is equal to this object.
199: */
200: public boolean equals(Object oth) {
201: if (this == oth) {
202: return true;
203: }
204:
205: if (oth instanceof PolygonSymbolizerImpl) {
206: PolygonSymbolizerImpl other = (PolygonSymbolizerImpl) oth;
207:
208: return Utilities.equals(this .geometryPropertyName,
209: other.geometryPropertyName)
210: && Utilities.equals(fill, other.fill)
211: && Utilities.equals(stroke, other.stroke);
212: }
213:
214: return false;
215: }
216: }
|