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