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/HaloImpl.java $
033: * @version $Id: HaloImpl.java 27862 2007-11-12 19:51:19Z desruisseaux $
034: */
035: public class HaloImpl extends AbstractGTComponent implements Halo,
036: 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 Fill fill = new FillImpl();
042: private Expression radius = null;
043:
044: public HaloImpl() {
045: this (CommonFactoryFinder.getFilterFactory(GeoTools
046: .getDefaultHints()));
047: }
048:
049: public HaloImpl(FilterFactory factory) {
050: filterFactory = factory;
051: init();
052: }
053:
054: public void setFilterFactory(FilterFactory factory) {
055: filterFactory = factory;
056: init();
057: }
058:
059: private void init() {
060: try {
061: radius = filterFactory.literal(1);
062: } catch (org.geotools.filter.IllegalFilterException ife) {
063: LOGGER.severe("Failed to build defaultHalo: " + ife);
064: }
065:
066: fill.setColor(filterFactory.literal("#FFFFFF")); // default halo is white
067: }
068:
069: /**
070: * Getter for property fill.
071: *
072: * @return Value of property fill.
073: */
074: public org.geotools.styling.Fill getFill() {
075: return fill;
076: }
077:
078: /**
079: * Setter for property fill.
080: *
081: * @param fill New value of property fill.
082: */
083: public void setFill(org.geotools.styling.Fill fill) {
084: Fill old = this .fill;
085: this .fill = fill;
086: fireChildChanged("fill", fill, old);
087: }
088:
089: /**
090: * Getter for property radius.
091: *
092: * @return Value of property radius.
093: */
094: public Expression getRadius() {
095: return radius;
096: }
097:
098: /**
099: * Setter for property radius.
100: *
101: * @param radius New value of property radius.
102: */
103: public void setRadius(Expression radius) {
104: Expression old = this .radius;
105: this .radius = radius;
106: fireChildChanged("radius", radius, old);
107: }
108:
109: public void accept(StyleVisitor visitor) {
110: visitor.visit(this );
111: }
112:
113: /**
114: * Creates a deep copy clone of the Halo.
115: *
116: * @return The clone.
117: *
118: * @throws RuntimeException DOCUMENT ME!
119: */
120: public Object clone() {
121: try {
122: HaloImpl clone = (HaloImpl) super .clone();
123: clone.fill = (Fill) ((Cloneable) fill).clone();
124:
125: return clone;
126: } catch (CloneNotSupportedException e) {
127: throw new RuntimeException("This will never happen");
128: }
129: }
130:
131: /**
132: * Compares this HaloImpl with another for equality.
133: *
134: * @param obj THe other HaloImpl.
135: *
136: * @return True if they are equal. They are equal if their fill and radius
137: * is equal.
138: *
139: * @see java.lang.Object#equals(java.lang.Object)
140: */
141: public boolean equals(Object obj) {
142: if (this == obj) {
143: return true;
144: }
145:
146: if (obj instanceof HaloImpl) {
147: HaloImpl other = (HaloImpl) obj;
148:
149: return Utilities.equals(radius, other.radius)
150: && Utilities.equals(fill, other.fill);
151: }
152:
153: return false;
154: }
155:
156: /* (non-Javadoc)
157: * @see java.lang.Object#hashCode()
158: */
159: public int hashCode() {
160: final int PRIME = 37;
161: int result = 17;
162:
163: if (radius != null) {
164: result = (result * PRIME) + radius.hashCode();
165: }
166:
167: if (fill != null) {
168: result = (result * PRIME) + fill.hashCode();
169: }
170:
171: return result;
172: }
173: }
|