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/DisplacementImpl.java $
033: * @version $Id: DisplacementImpl.java 27862 2007-11-12 19:51:19Z desruisseaux $
034: */
035: public class DisplacementImpl extends AbstractGTComponent implements
036: Displacement, 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: private FilterFactory filterFactory;
041: private Expression displacementX = null;
042: private Expression displacementY = null;
043:
044: public DisplacementImpl() {
045: this (CommonFactoryFinder.getFilterFactory(GeoTools
046: .getDefaultHints()));
047: }
048:
049: public DisplacementImpl(FilterFactory factory) {
050: filterFactory = factory;
051:
052: try {
053: displacementX = filterFactory.literal(0);
054: displacementY = filterFactory.literal(0);
055: } catch (org.geotools.filter.IllegalFilterException ife) {
056: LOGGER
057: .severe("Failed to build defaultDisplacement: "
058: + ife);
059: }
060: }
061:
062: public void setFilterFactory(FilterFactory factory) {
063: filterFactory = factory;
064:
065: try {
066: displacementX = filterFactory.literal(0);
067: displacementY = filterFactory.literal(0);
068: } catch (org.geotools.filter.IllegalFilterException ife) {
069: LOGGER
070: .severe("Failed to build defaultDisplacement: "
071: + ife);
072: }
073:
074: fireChanged();
075: }
076:
077: /**
078: * Setter for property displacementX.
079: *
080: * @param displacementX New value of property displacementX.
081: */
082: public void setDisplacementX(Expression displacementX) {
083: this .displacementX = displacementX;
084: fireChanged();
085: }
086:
087: /**
088: * Setter for property displacementY.
089: *
090: * @param displacementY New value of property displacementY.
091: */
092: public void setDisplacementY(Expression displacementY) {
093: this .displacementY = displacementY;
094: fireChanged();
095: }
096:
097: /**
098: * Getter for property displacementX.
099: *
100: * @return Value of property displacementX.
101: */
102: public Expression getDisplacementX() {
103: return displacementX;
104: }
105:
106: /**
107: * Getter for property displacementY.
108: *
109: * @return Value of property displacementY.
110: */
111: public Expression getDisplacementY() {
112: return displacementY;
113: }
114:
115: public void accept(StyleVisitor visitor) {
116: visitor.visit(this );
117: }
118:
119: /* (non-Javadoc)
120: * @see org.opengis.util.Cloneable#clone()
121: */
122: public Object clone() {
123: try {
124: return super .clone();
125: } catch (CloneNotSupportedException e) {
126: throw new RuntimeException("Will not happen");
127: }
128: }
129:
130: /* (non-Javadoc)
131: * @see java.lang.Object#equals(java.lang.Object)
132: */
133: public boolean equals(Object obj) {
134: if (this == obj) {
135: return true;
136: }
137:
138: if (obj instanceof DisplacementImpl) {
139: DisplacementImpl other = (DisplacementImpl) obj;
140:
141: return Utilities.equals(displacementX, other.displacementX)
142: && Utilities.equals(displacementY,
143: other.displacementY);
144: }
145:
146: return false;
147: }
148:
149: /* (non-Javadoc)
150: * @see java.lang.Object#hashCode()
151: */
152: public int hashCode() {
153: final int PRIME = 37;
154: int result = 17;
155:
156: if (displacementX != null) {
157: result = (result * PRIME) + displacementX.hashCode();
158: }
159:
160: if (displacementY != null) {
161: result = (result * PRIME) + displacementY.hashCode();
162: }
163:
164: return result;
165: }
166: }
|