root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / GraduatedSymbolLegend.java @ 18335
History | View | Annotate | Download (6.65 KB)
1 | 10679 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | *
|
||
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 11704 | jaume | * Revision 1.3 2007-05-17 09:32:06 jaume
|
47 | * *** empty log message ***
|
||
48 | *
|
||
49 | * Revision 1.2 2007/03/09 11:20:56 jaume
|
||
50 | 10679 | jaume | * Advanced symbology (start committing)
|
51 | *
|
||
52 | * Revision 1.1.2.4 2007/02/15 16:23:44 jaume
|
||
53 | * *** empty log message ***
|
||
54 | *
|
||
55 | * Revision 1.1.2.3 2007/02/14 15:53:35 jaume
|
||
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | * Revision 1.1.2.2 2007/02/13 16:19:19 jaume
|
||
59 | * graduated symbol legends (start commiting)
|
||
60 | *
|
||
61 | * Revision 1.1.2.1 2007/02/12 15:15:20 jaume
|
||
62 | * refactored interval legend and added graduated symbol legend
|
||
63 | *
|
||
64 | *
|
||
65 | */
|
||
66 | package com.iver.cit.gvsig.fmap.rendering; |
||
67 | |||
68 | 14279 | jdominguez | import com.iver.cit.gvsig.fmap.core.FShape; |
69 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
70 | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
||
71 | import com.iver.cit.gvsig.fmap.core.styles.SimpleMarkerFillPropertiesStyle; |
||
72 | import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
||
73 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
74 | import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol; |
||
75 | 10679 | jaume | import com.iver.utiles.StringUtilities; |
76 | import com.iver.utiles.XMLEntity; |
||
77 | |||
78 | |||
79 | /**
|
||
80 | 14421 | jvidal | * <p>GraduatedSymbolLegend is a legend that allows to classify ranges of
|
81 | 10679 | jaume | * values using a value with symbol sizes.<b>
|
82 | * </p>
|
||
83 | * <p>
|
||
84 | * The symbol size will be calculated according the min size, the
|
||
85 | * max size and the amount of intervals. So for a min size of 1, a max size
|
||
86 | * of 5, and 5 intervals, symbol sizes will be [1, 2, 3, 4, 5].
|
||
87 | * </p>
|
||
88 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
89 | */
|
||
90 | public class GraduatedSymbolLegend extends VectorialIntervalLegend { |
||
91 | private double maxSymbolSize; |
||
92 | private double minSymbolSize; |
||
93 | 14279 | jdominguez | private ISymbol templateSymbol;
|
94 | 10679 | jaume | /**
|
95 | 14279 | jdominguez | * DefaultConstructor
|
96 | */
|
||
97 | public GraduatedSymbolLegend() {
|
||
98 | super();
|
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Convenience constructor.
|
||
103 | *
|
||
104 | * Creates a new instance of GraduatedSymbolLegend from a VectorialIntervalLegend by
|
||
105 | * taking the same fields.
|
||
106 | * @param leg
|
||
107 | */
|
||
108 | public GraduatedSymbolLegend(VectorialIntervalLegend leg) {
|
||
109 | this.shapeType = leg.shapeType;
|
||
110 | this.symbols = leg.symbols;
|
||
111 | this.keys = leg.keys;
|
||
112 | this.index = leg.index;
|
||
113 | 16187 | jdominguez | this.setClassifyingFieldNames(leg.getClassifyingFieldNames());
|
114 | this.setClassifyingFieldTypes(leg.getClassifyingFieldTypes());
|
||
115 | 14279 | jdominguez | this.fieldId = leg.fieldId;
|
116 | this.defaultSymbol = leg.defaultSymbol;
|
||
117 | this.dataSource = leg.dataSource;
|
||
118 | this.intervalType = leg.intervalType;
|
||
119 | this.useDefaultSymbol = leg.useDefaultSymbol;
|
||
120 | } |
||
121 | |||
122 | /**
|
||
123 | 10679 | jaume | * Returns the max symbol size. Combined with the min symbol size and
|
124 | * the interval count, will produce the symbol sizes.
|
||
125 | * @return double, the max size.
|
||
126 | */
|
||
127 | public double getMaxSymbolSize() { |
||
128 | return maxSymbolSize;
|
||
129 | } |
||
130 | |||
131 | /**
|
||
132 | * Returns the min symbol size. Combined with the max symbol size and
|
||
133 | * the interval count, will produce the symbol sizes.
|
||
134 | * @return double, the min size.
|
||
135 | */
|
||
136 | public double getMinSymbolSize() { |
||
137 | return minSymbolSize;
|
||
138 | } |
||
139 | |||
140 | /**
|
||
141 | * Sets the max symbol size. Combined with the min symbol size and
|
||
142 | * the interval count, will produce the symbol sizes.
|
||
143 | */
|
||
144 | public void setMaxSymbolSize(double size) { |
||
145 | this.maxSymbolSize = size;
|
||
146 | } |
||
147 | |||
148 | /**
|
||
149 | * Sets the min symbol size. Combined with the max symbol size and
|
||
150 | * the interval count, will produce the symbol sizes.
|
||
151 | */
|
||
152 | public void setMinSymbolSize(double size) { |
||
153 | this.minSymbolSize = size;
|
||
154 | } |
||
155 | |||
156 | public XMLEntity getXMLEntity() {
|
||
157 | XMLEntity xml = super.getXMLEntity();
|
||
158 | |||
159 | xml.putProperty("className", getClass().getName());
|
||
160 | xml.putProperty("maxSymbolSize", maxSymbolSize);
|
||
161 | xml.putProperty("minSymbolSize", minSymbolSize);
|
||
162 | |||
163 | 14279 | jdominguez | if (templateSymbol != null) { |
164 | XMLEntity templateXML = templateSymbol.getXMLEntity(); |
||
165 | templateXML.putProperty("id", "templateSymbol"); |
||
166 | xml.addChild(templateXML); |
||
167 | } |
||
168 | |||
169 | 10679 | jaume | // remove unuseful properties from supertype
|
170 | xml.remove("startColor");
|
||
171 | xml.remove("endColor");
|
||
172 | return xml;
|
||
173 | } |
||
174 | |||
175 | public void setXMLEntity(XMLEntity xml) { |
||
176 | // patch for avoid errors in call to supertype's
|
||
177 | // setXMLEntity(XMLEntity)
|
||
178 | xml.putProperty("startColor",
|
||
179 | StringUtilities.color2String(super.getStartColor()));
|
||
180 | xml.putProperty("endColor",
|
||
181 | StringUtilities.color2String(super.getEndColor()));
|
||
182 | 14279 | jdominguez | |
183 | 10679 | jaume | // end patch
|
184 | super.setXMLEntity(xml);
|
||
185 | maxSymbolSize = xml.getDoubleProperty("maxSymbolSize");
|
||
186 | minSymbolSize = xml.getDoubleProperty("minSymbolSize");
|
||
187 | 14279 | jdominguez | |
188 | if (xml.firstChild("id", "templateSymbol") != null) { |
||
189 | XMLEntity templateXML = xml.firstChild("id", "templateSymbol"); |
||
190 | templateSymbol = SymbologyFactory.createSymbolFromXML(templateXML, "templateSymbol");
|
||
191 | } |
||
192 | 10679 | jaume | } |
193 | 14279 | jdominguez | |
194 | @Override
|
||
195 | public ISymbol getSymbolByFeature(IFeature feat) {
|
||
196 | ISymbol theSymbol = super.getSymbolByFeature(feat);
|
||
197 | |||
198 | if (feat.getGeometry().getGeometryType() == FShape.POLYGON && theSymbol instanceof IMarkerSymbol) { |
||
199 | // transform it to a fill symbol
|
||
200 | MarkerFillSymbol aux = new MarkerFillSymbol();
|
||
201 | // tell the fill style to draw the IMarkerSymbol
|
||
202 | // as a IFillSymbol centering it in the shape polygon
|
||
203 | // centroid and applying offset (if any).
|
||
204 | aux.setMarker((IMarkerSymbol) theSymbol); |
||
205 | SimpleMarkerFillPropertiesStyle p = new SimpleMarkerFillPropertiesStyle();
|
||
206 | p.setFillStyle(SimpleMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
||
207 | aux.setMarkerFillProperties(p); |
||
208 | theSymbol = aux; |
||
209 | } |
||
210 | return theSymbol;
|
||
211 | } |
||
212 | |||
213 | 14421 | jvidal | /**
|
214 | * Sets the default symbol.
|
||
215 | * @param symbol
|
||
216 | */
|
||
217 | 14279 | jdominguez | public void setTemplateSymbol(ISymbol symbol) { |
218 | this.templateSymbol = symbol;
|
||
219 | } |
||
220 | 14421 | jvidal | /**
|
221 | * Obtains the template symbol
|
||
222 | * @return
|
||
223 | */
|
||
224 | 14279 | jdominguez | public ISymbol getTemplateSymbol() {
|
225 | return templateSymbol;
|
||
226 | } |
||
227 | 10679 | jaume | } |