001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-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; either
009: * version 2.1 of the License, or (at your option) any later version.
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.renderer.lite;
017:
018: import java.util.ArrayList;
019: import java.util.Collections;
020: import java.util.HashSet;
021: import java.util.List;
022: import java.util.Set;
023:
024: import org.geotools.geometry.jts.LiteShape2;
025: import org.geotools.renderer.style.TextStyle2D;
026:
027: import com.vividsolutions.jts.geom.Geometry;
028:
029: /**
030: * The Labelling information that is put in the label cache.
031: *
032: * @author jeichar
033: * @author dblasby
034: * @author simone giannecchini * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/render/src/main/java/org/geotools/renderer/lite/LabelCacheItem.java $
035: */
036: public final class LabelCacheItem implements Comparable {
037: TextStyle2D textStyle;
038: List geoms = new ArrayList();
039: double priority = 0.0;
040: int spaceAround = 0;
041: String label;
042: private Set layerIds = new HashSet();
043:
044: public String getLabel() {
045: return label;
046: }
047:
048: public void setLabel(String l) {
049: label = l;
050: }
051:
052: /**
053: * space around - "dont put any label near me by this # of pixels"
054: */
055: public int getSpaceAround() {
056: return spaceAround;
057: }
058:
059: /**
060: * space around - "dont put any label near me by this # of pixels"
061: */
062: public void setSpaceAround(int space) {
063: spaceAround = space;
064: }
065:
066: public double getPriority() {
067: return priority;
068: }
069:
070: public void setPriority(double d) {
071: priority = d;
072: }
073:
074: /**
075: * Construct <code>LabelCacheItem</code>.
076: */
077: public LabelCacheItem(String layerId, TextStyle2D textStyle,
078: LiteShape2 shape, String label) {
079: this .textStyle = textStyle;
080: this .geoms.add(shape.getGeometry());
081: this .label = label;
082: this .layerIds.add(layerId);
083: }
084:
085: /**
086: * Return a modifiable set of ids
087: * @return
088: */
089: public Set getLayerIds() {
090: return Collections.synchronizedSet(layerIds);
091: }
092:
093: /**
094: * The list of geometries this item maintains
095: */
096: public List getGeoms() {
097: return geoms;
098: }
099:
100: /**
101: * The textstyle that is used to label the shape.
102: */
103: public TextStyle2D getTextStyle() {
104: return textStyle;
105: }
106:
107: /**
108: * @see java.lang.Object#equals(java.lang.Object)
109: */
110: public boolean equals(Object arg0) {
111: if (arg0 instanceof String) {
112: String label = (String) arg0;
113: return label.equals(textStyle.getLabel());
114: }
115: if (arg0 instanceof LabelCacheItem) {
116: LabelCacheItem item = (LabelCacheItem) arg0;
117: return textStyle.getLabel().equals(
118: ((LabelCacheItem) arg0).getTextStyle().getLabel());
119: }
120: if (arg0 instanceof TextStyle2D) {
121: TextStyle2D text = (TextStyle2D) arg0;
122: return textStyle.getLabel().equals(text.getLabel());
123: }
124: return false;
125: }
126:
127: /**
128: * @see java.lang.Object#hashCode()
129: */
130: public int hashCode() {
131: return textStyle.getLabel().hashCode();
132: }
133:
134: /**
135: * Returns an example geometry from the list of geometries.
136: */
137: public Geometry getGeometry() {
138: return (Geometry) geoms.get(0);
139: }
140:
141: /* (non-Javadoc)
142: * @see java.lang.Comparable#compareTo(java.lang.Object)
143: */
144: public int compareTo(Object o) {
145: LabelCacheItem other = (LabelCacheItem) o;
146: return Double.compare(this.getPriority(), other.getPriority());
147: }
148: }
|