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.opengis.util.Cloneable;
021:
022: /**
023: * Provides a representation of a LineSymbolizer in an SLD Document. A
024: * LineSymbolizer defines how a line geometry should be rendered.
025: *
026: * @author James Macgill
027: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/LineSymbolizerImpl.java $
028: * @version $Id: LineSymbolizerImpl.java 20703 2006-07-24 16:57:44Z jgarnett $
029: */
030: public class LineSymbolizerImpl extends AbstractGTComponent implements
031: LineSymbolizer, Cloneable {
032: private Stroke stroke = null;
033: private String geometryName = null;
034:
035: /**
036: * Creates a new instance of DefaultLineSymbolizer
037: */
038: protected LineSymbolizerImpl() {
039: }
040:
041: /**
042: * This property defines the geometry to be used for styling.<br>
043: * The property is optional and if it is absent (null) then the "default"
044: * geometry property of the feature should be used. Geometry types other
045: * than inherently linear types can be used. If a point geometry is used,
046: * it should be interpreted as a line of zero length and two end caps. If
047: * a polygon is used (or other "area" type) then its closed outline should
048: * be used as the line string (with no end caps). The geometryPropertyName
049: * is the name of a geometry property in the Feature being styled.
050: * Typically, features only have one geometry so, in general, the need to
051: * select one is not required. Note: this moves a little away from the SLD
052: * spec which provides an XPath reference to a Geometry object, but does
053: * follow it in spirit.
054: *
055: * @return The name of the attribute in the feature being styled that
056: * should be used. If null then the default geometry should be
057: * used.
058: */
059: public String getGeometryPropertyName() {
060: return geometryName;
061: }
062:
063: /**
064: * Sets the GeometryPropertyName.
065: *
066: * @param name The name of the geometryProperty.
067: *
068: * @see #LineSymbolizerImpl.geometryPropertyName()
069: */
070: public void setGeometryPropertyName(String name) {
071: geometryName = name;
072: fireChanged();
073: }
074:
075: /**
076: * Provides the graphical-symbolization parameter to use for the linear
077: * geometry.
078: *
079: * @return The Stroke style to use when rendering lines.
080: */
081: public Stroke getStroke() {
082: return stroke;
083: }
084:
085: /**
086: * Sets the graphical-symbolization parameter to use for the linear
087: * geometry.
088: *
089: * @param stroke The Stroke style to use when rendering lines.
090: */
091: public void setStroke(Stroke stroke) {
092: if (this .stroke == stroke) {
093: return;
094: }
095:
096: Stroke old = this .stroke;
097: this .stroke = stroke;
098: fireChildChanged("stroke", stroke, old);
099: }
100:
101: /**
102: * Accepts a StyleVisitor to perform some operation on this LineSymbolizer.
103: *
104: * @param visitor The visitor to accept.
105: */
106: public void accept(StyleVisitor visitor) {
107: visitor.visit(this );
108: }
109:
110: /**
111: * Creates a deep copy clone.
112: *
113: * @return The deep copy clone.
114: *
115: * @throws RuntimeException DOCUMENT ME!
116: */
117: public Object clone() {
118: LineSymbolizerImpl clone;
119:
120: try {
121: clone = (LineSymbolizerImpl) super .clone();
122:
123: if (stroke != null) {
124: clone.stroke = (Stroke) stroke.clone();
125: }
126: } catch (CloneNotSupportedException e) {
127: throw new RuntimeException(e); // this should never happen.
128: }
129:
130: return clone;
131: }
132:
133: /**
134: * Generates a hashcode for the LineSymbolizerImpl.
135: *
136: * @return A hashcode.
137: */
138: public int hashCode() {
139: final int PRIME = 1000003;
140: int result = 0;
141:
142: if (stroke != null) {
143: result = (PRIME * result) + stroke.hashCode();
144: }
145:
146: if (geometryName != null) {
147: result = (PRIME * result) + geometryName.hashCode();
148: }
149:
150: return result;
151: }
152:
153: /**
154: * Compares this LineSymbolizerImpl with another for equality.
155: *
156: * <p>
157: * Two LineSymbolizerImpls are equal if they have the same
158: * geometryPropertyName and the same stroke.
159: * </p>
160: *
161: * @param oth The other LineSymbolizerImpl
162: *
163: * @return True if this and oth are equal.
164: */
165: public boolean equals(Object oth) {
166: if (this == oth) {
167: return true;
168: }
169:
170: if (oth == null) {
171: return false;
172: }
173:
174: if (oth.getClass() != getClass()) {
175: return false;
176: }
177:
178: LineSymbolizerImpl other = (LineSymbolizerImpl) oth;
179:
180: if (this .geometryName == null) {
181: if (other.geometryName != null) {
182: return false;
183: }
184: } else {
185: if (!this .geometryName.equals(other.geometryName)) {
186: return false;
187: }
188: }
189:
190: if (this .stroke == null) {
191: if (other.stroke != null) {
192: return false;
193: }
194: } else {
195: if (!this .stroke.equals(other.stroke)) {
196: return false;
197: }
198: }
199:
200: return true;
201: }
202: }
|