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