svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialIntervalLegend.java @ 28962
History | View | Annotate | Download (9.69 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
package com.iver.cit.gvsig.fmap.rendering; |
42 |
|
43 |
import java.awt.Color; |
44 |
|
45 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
46 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
47 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
48 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
49 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
50 |
import com.iver.utiles.StringUtilities; |
51 |
import com.iver.utiles.XMLEntity; |
52 |
|
53 |
|
54 |
/**
|
55 |
* <p>VectorialIntervalLegend (which should be better called GraduatedColorLegend) is
|
56 |
* a legend that allows to classify ranges of values using a color gradient based
|
57 |
* on a value.<b>
|
58 |
* </p>
|
59 |
* <p>
|
60 |
* The color gradient will be calculated according the starting color, the
|
61 |
* ending color and the amount of intervals.
|
62 |
* </p>
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
public class VectorialIntervalLegend extends AbstractIntervalLegend { |
66 |
private Color startColor = Color.red; |
67 |
private Color endColor = Color.blue; |
68 |
/**
|
69 |
* Constructor method
|
70 |
*/
|
71 |
public VectorialIntervalLegend() {
|
72 |
//defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* Constructor method
|
77 |
*
|
78 |
* @param type type of the shape.
|
79 |
*/
|
80 |
public VectorialIntervalLegend(int type) { |
81 |
setShapeType(type); |
82 |
} |
83 |
|
84 |
public XMLEntity getXMLEntity() {
|
85 |
XMLEntity xml = new XMLEntity();
|
86 |
xml.putProperty("className", this.getClass().getName()); |
87 |
xml.putProperty("useDefaultSymbolB", useDefaultSymbol);
|
88 |
if (getDefaultSymbol() == null) { |
89 |
xml.putProperty("useDefaultSymbol", 0); |
90 |
} else {
|
91 |
xml.putProperty("useDefaultSymbol", 1); |
92 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
93 |
} |
94 |
|
95 |
xml.putProperty("fieldName", fieldNames[0]); |
96 |
xml.putProperty("index", index);
|
97 |
|
98 |
xml.putProperty("intervalType", intervalType);
|
99 |
xml.putProperty("numKeys", keys.size());
|
100 |
|
101 |
if (keys.size() > 0) { |
102 |
xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName()); |
103 |
|
104 |
String[] sk = new String[keys.size()]; |
105 |
|
106 |
for (int i = 0; i < keys.size(); i++) { |
107 |
sk[i] = ((IInterval) keys.get(i)).toString(); |
108 |
} |
109 |
|
110 |
xml.putProperty("keys", getValues());
|
111 |
|
112 |
for (int i = 0; i < keys.size(); i++) { |
113 |
xml.addChild(getSymbols()[i].getXMLEntity()); |
114 |
} |
115 |
} |
116 |
|
117 |
xml.putProperty("shapeType", shapeType);
|
118 |
|
119 |
xml.putProperty("startColor", StringUtilities.color2String(startColor));
|
120 |
xml.putProperty("endColor", StringUtilities.color2String(endColor));
|
121 |
|
122 |
///xml.putProperty("numSymbols", symbols.size());
|
123 |
///xml.putProperty("indexs", getIndexs());
|
124 |
///xml.putProperty("values", getValues());
|
125 |
return xml;
|
126 |
} |
127 |
|
128 |
|
129 |
public void setXMLEntity03(XMLEntity xml) { |
130 |
fieldNames = new String[] {xml.getStringProperty("fieldName")}; |
131 |
index = xml.getIntProperty("index");
|
132 |
|
133 |
if (xml.contains("intervalType")) { /* TODO Esta condici?n es para |
134 |
poder cargar la versi?n 0.3,
|
135 |
se puede eliminar cuando ya
|
136 |
no queramos soportar esta
|
137 |
versi?n. */
|
138 |
intervalType = xml.getIntProperty("intervalType");
|
139 |
} |
140 |
|
141 |
int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
142 |
|
143 |
if (useDefaultSymbol == 1) { |
144 |
setDefaultSymbol( SymbologyFactory.createSymbolFromXML(xml.getChild(0), null)); |
145 |
} else {
|
146 |
setDefaultSymbol(null);
|
147 |
} |
148 |
|
149 |
int numKeys = xml.getIntProperty("numKeys"); |
150 |
|
151 |
if (numKeys > 0) { |
152 |
String className = xml.getStringProperty("tipoValueKeys"); |
153 |
String[] sk = xml.getStringArrayProperty("keys"); |
154 |
IInterval auxInterval; |
155 |
|
156 |
for (int i = 0; i < numKeys; i++) { |
157 |
auxInterval = FInterval.create(sk[i]); |
158 |
symbols.put(auxInterval, |
159 |
SymbologyFactory.createSymbolFromXML(xml.getChild(i + useDefaultSymbol), null));
|
160 |
keys.add(auxInterval); |
161 |
System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
162 |
SymbologyFactory.createSymbolFromXML(xml.getChild(i + useDefaultSymbol), null)
|
163 |
.getDescription()); |
164 |
} |
165 |
} |
166 |
|
167 |
shapeType = xml.getIntProperty("shapeType");
|
168 |
|
169 |
startColor = StringUtilities.string2Color(xml.getStringProperty( |
170 |
"startColor"));
|
171 |
endColor = StringUtilities.string2Color(xml.getStringProperty( |
172 |
"endColor"));
|
173 |
} |
174 |
|
175 |
|
176 |
public void setXMLEntity(XMLEntity xml) { |
177 |
fieldNames = new String[] {xml.getStringProperty("fieldName")}; |
178 |
index = xml.getIntProperty("index");
|
179 |
|
180 |
if (xml.contains("intervalType")) { //TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n. |
181 |
intervalType = xml.getIntProperty("intervalType");
|
182 |
} |
183 |
useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbolB");
|
184 |
int hasDefaultSymbol = xml.getIntProperty("useDefaultSymbol"); |
185 |
|
186 |
if (hasDefaultSymbol == 1) { |
187 |
setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null)); |
188 |
} else {
|
189 |
setDefaultSymbol(null);
|
190 |
} |
191 |
|
192 |
int numKeys = xml.getIntProperty("numKeys"); |
193 |
|
194 |
if (numKeys > 0) { |
195 |
String[] sk = xml.getStringArrayProperty("keys"); |
196 |
IInterval auxInterval; |
197 |
|
198 |
for (int i = 0; i < numKeys; i++) { |
199 |
auxInterval = FInterval.create(sk[i]); |
200 |
symbols.put(auxInterval, |
201 |
SymbologyFactory.createSymbolFromXML(xml.getChild(i + hasDefaultSymbol), null));
|
202 |
keys.add(auxInterval); |
203 |
System.out.println("auxInterval =" + auxInterval + "Symbol =" + |
204 |
SymbologyFactory.createSymbolFromXML(xml.getChild(i + hasDefaultSymbol), null)
|
205 |
.getDescription()); |
206 |
} |
207 |
} |
208 |
if (xml.contains("shapeType")){ |
209 |
shapeType = xml.getIntProperty("shapeType");
|
210 |
} |
211 |
startColor = StringUtilities.string2Color(xml.getStringProperty( |
212 |
"startColor"));
|
213 |
endColor = StringUtilities.string2Color(xml.getStringProperty( |
214 |
"endColor"));
|
215 |
} |
216 |
|
217 |
|
218 |
public ILegend cloneLegend() throws XMLException { |
219 |
return LegendFactory.createFromXML(getXMLEntity());
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* Returns the final color
|
224 |
* @return Color final color.
|
225 |
* @uml.property name="endColor"
|
226 |
*/
|
227 |
public Color getEndColor() { |
228 |
return endColor;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Inserts the final color.
|
233 |
* @param endColor final color.
|
234 |
* @uml.property name="endColor"
|
235 |
*/
|
236 |
public void setEndColor(Color endColor) { |
237 |
this.endColor = endColor;
|
238 |
} |
239 |
|
240 |
/**
|
241 |
* Returns the initial color.
|
242 |
* @return Color initial color.
|
243 |
* @uml.property name="startColor"
|
244 |
*/
|
245 |
public Color getStartColor() { |
246 |
return startColor;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* Inserts the initial color
|
251 |
* @param startColor initial color.
|
252 |
* @uml.property name="startColor"
|
253 |
*/
|
254 |
public void setStartColor(Color startColor) { |
255 |
this.startColor = startColor;
|
256 |
} |
257 |
|
258 |
public int getShapeType() { |
259 |
return shapeType;
|
260 |
} |
261 |
|
262 |
public void setShapeType(int shapeType) { |
263 |
if (this.shapeType != shapeType) { |
264 |
setDefaultSymbol(SymbologyFactory. |
265 |
createDefaultSymbolByShapeType(shapeType)); |
266 |
this.shapeType = shapeType;
|
267 |
} |
268 |
} |
269 |
|
270 |
|
271 |
public String getClassName() { |
272 |
return getClass().getName();
|
273 |
} |
274 |
|
275 |
//
|
276 |
/**
|
277 |
* <p>This method does not exist officially. But what it does is just apply the
|
278 |
* values of a VectorialIntervalLegend to other so, It is not needed to
|
279 |
* replicate the code of populating the legend in every panel that produces
|
280 |
* a legend by intervals.<br>
|
281 |
* </p>
|
282 |
* <p>
|
283 |
* ok this method is messy, but it's useful ;-)
|
284 |
* </p>
|
285 |
*/
|
286 |
public static void initializeVectorialIntervalLegend( |
287 |
AbstractIntervalLegend srcLegend, |
288 |
AbstractIntervalLegend targetLegend) { |
289 |
targetLegend.shapeType = srcLegend.shapeType; |
290 |
targetLegend.symbols = srcLegend.symbols; |
291 |
targetLegend.keys = srcLegend.keys; |
292 |
targetLegend.index = srcLegend.index; |
293 |
targetLegend.setClassifyingFieldNames(srcLegend.getClassifyingFieldNames()); |
294 |
targetLegend.setClassifyingFieldTypes(srcLegend.getClassifyingFieldTypes()); |
295 |
targetLegend.fieldId = srcLegend.fieldId; |
296 |
targetLegend.defaultSymbol = srcLegend.defaultSymbol; |
297 |
targetLegend.dataSource = srcLegend.dataSource; |
298 |
targetLegend.intervalType = srcLegend.intervalType; |
299 |
targetLegend.useDefaultSymbol = srcLegend.useDefaultSymbol; |
300 |
} |
301 |
|
302 |
} |