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.factory.CommonFactoryFinder;
022: import org.geotools.factory.GeoTools;
023: import org.geotools.resources.Utilities;
024: import org.opengis.filter.FilterFactory;
025: import org.opengis.filter.expression.Expression;
026: import org.opengis.util.Cloneable;
027:
028: /**
029: * DOCUMENT ME!
030: *
031: * @author Ian Turton, CCG
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/styling/PointPlacementImpl.java $
033: * @version $Id: PointPlacementImpl.java 27862 2007-11-12 19:51:19Z desruisseaux $
034: */
035: public class PointPlacementImpl extends AbstractGTComponent implements
036: PointPlacement, Cloneable {
037: /** The logger for the default core module. */
038: private static final java.util.logging.Logger LOGGER = org.geotools.util.logging.Logging
039: .getLogger("org.geotools.core");
040:
041: // TODO: make container ready
042: private final FilterFactory filterFactory;
043: private AnchorPoint anchorPoint = new AnchorPointImpl();
044: private Displacement displacement = new DisplacementImpl();
045: private Expression rotation = null;
046:
047: public PointPlacementImpl() {
048: this (CommonFactoryFinder.getFilterFactory(GeoTools
049: .getDefaultHints()));
050: }
051:
052: public PointPlacementImpl(FilterFactory factory) {
053: filterFactory = factory;
054: try {
055: rotation = filterFactory.literal(new Integer(0));
056: } catch (org.geotools.filter.IllegalFilterException ife) {
057: LOGGER.severe("Failed to build defaultPointPlacement: "
058: + ife);
059: }
060: }
061:
062: /**
063: * Returns the AnchorPoint which identifies the location inside a text
064: * label to use as an "anchor" for positioning it relative to a point
065: * geometry.
066: *
067: * @return Label's AnchorPoint.
068: */
069: public org.geotools.styling.AnchorPoint getAnchorPoint() {
070: return anchorPoint;
071: }
072:
073: /**
074: * Setter for property anchorPoint.
075: *
076: * @param anchorPoint New value of property anchorPoint.
077: */
078: public void setAnchorPoint(
079: org.geotools.styling.AnchorPoint anchorPoint) {
080: if (anchorPoint == null) {
081: this .anchorPoint = new AnchorPointImpl();
082: } else {
083: this .anchorPoint = anchorPoint;
084: }
085:
086: fireChanged();
087: }
088:
089: /**
090: * Returns the Displacement which gives X and Y offset displacements to use
091: * for rendering a text label near a point.
092: *
093: * @return The label displacement.
094: */
095: public Displacement getDisplacement() {
096: return displacement;
097: }
098:
099: /**
100: * Setter for property displacement.
101: *
102: * @param displacement New value of property displacement.
103: */
104: public void setDisplacement(Displacement displacement) {
105: if (displacement == null) {
106: this .displacement = new DisplacementImpl();
107: } else {
108: this .displacement = displacement;
109: }
110:
111: fireChanged();
112: }
113:
114: /**
115: * Returns the rotation of the label.
116: *
117: * @return The rotation of the label.
118: */
119: public Expression getRotation() {
120: return rotation;
121: }
122:
123: /**
124: * Setter for property rotation.
125: *
126: * @param rotation New value of property rotation.
127: */
128: public void setRotation(Expression rotation) {
129: this .rotation = rotation;
130: fireChanged();
131: }
132:
133: public void accept(StyleVisitor visitor) {
134: visitor.visit(this );
135: }
136:
137: /* (non-Javadoc)
138: * @see Cloneable#clone()
139: */
140: public Object clone() {
141: try {
142: PointPlacementImpl clone = (PointPlacementImpl) super
143: .clone();
144: clone.anchorPoint = (AnchorPoint) ((Cloneable) anchorPoint)
145: .clone();
146: clone.displacement = (Displacement) ((Cloneable) displacement)
147: .clone();
148:
149: return clone;
150: } catch (CloneNotSupportedException e) {
151: throw new RuntimeException("Won't happen");
152: }
153: }
154:
155: /* (non-Javadoc)
156: * @see java.lang.Object#equals(java.lang.Object)
157: */
158: public boolean equals(Object obj) {
159: if (this == obj) {
160: return true;
161: }
162:
163: if (obj instanceof PointPlacementImpl) {
164: PointPlacementImpl other = (PointPlacementImpl) obj;
165:
166: return Utilities.equals(anchorPoint, other.anchorPoint)
167: && Utilities.equals(displacement,
168: other.displacement)
169: && Utilities.equals(rotation, other.rotation);
170: }
171:
172: return false;
173: }
174:
175: /* (non-Javadoc)
176: * @see java.lang.Object#hashCode()
177: */
178: public int hashCode() {
179: final int PRIME = 37;
180: int result = 17;
181:
182: if (anchorPoint != null) {
183: result = (result * PRIME) + anchorPoint.hashCode();
184: }
185:
186: if (displacement != null) {
187: result = (result * PRIME) + displacement.hashCode();
188: }
189:
190: if (rotation != null) {
191: result = (result * PRIME) + rotation.hashCode();
192: }
193:
194: return result;
195: }
196: }
|