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