svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / VectorialUniqueValueLegend.java @ 30754
History | View | Annotate | Download (19.5 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 org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Comparator; |
46 |
import java.util.Iterator; |
47 |
import java.util.TreeMap; |
48 |
|
49 |
import org.gvsig.fmap.dal.feature.Feature; |
50 |
import org.gvsig.fmap.mapcontext.MapContextException; |
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
52 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
53 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
54 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
55 |
import org.gvsig.utils.XMLEntity; |
56 |
import org.gvsig.utils.XMLException; |
57 |
import org.slf4j.Logger; |
58 |
import org.slf4j.LoggerFactory; |
59 |
|
60 |
/**
|
61 |
* Vectorial legend for unique values
|
62 |
*
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
//public class VectorialUniqueValueLegend implements IVectorialUniqueValueLegend {
|
66 |
public class VectorialUniqueValueLegend extends AbstractClassifiedVectorLegend implements IVectorialUniqueValueLegend { |
67 |
|
68 |
final static private Logger logger = LoggerFactory.getLogger(VectorialUniqueValueLegend.class); |
69 |
// protected int fieldId;
|
70 |
// protected DataSource dataSource;
|
71 |
// protected FeatureStore featureStore;
|
72 |
private TreeMap symbols = new TreeMap( //<Object, ISymbol> |
73 |
new Comparator() { //<Object> |
74 |
public int compare(Object o1, Object o2) { |
75 |
if ((o1 != null) && (o2 != null)) { |
76 |
Object v2 = o2;
|
77 |
Object v1 = o1;
|
78 |
// Boolean boolVal;
|
79 |
|
80 |
// TODO estas dos comprobaciones son por evitar un bug en el gdbms, cuando se solucione se puede eliminar.
|
81 |
if (v1 == null && v2 == null) { |
82 |
return 0; |
83 |
} |
84 |
|
85 |
// if (v1 instanceof NullUniqueValue && v2 instanceof NullUniqueValue) {
|
86 |
// return 0;
|
87 |
// }
|
88 |
//
|
89 |
// if (v1 instanceof NullUniqueValue) {
|
90 |
// return -1;
|
91 |
// }
|
92 |
//
|
93 |
// if (v2 instanceof NullUniqueValue) {
|
94 |
// return 1;
|
95 |
// }
|
96 |
|
97 |
if (v1 instanceof Number && v2 instanceof Number){ |
98 |
return((Number)v1).intValue()-((Number)v2).intValue(); |
99 |
} |
100 |
if (v1 instanceof String && v2 instanceof String){ |
101 |
return ((String)v1).compareTo(((String)v2)); |
102 |
} |
103 |
} |
104 |
|
105 |
return 0; |
106 |
} |
107 |
}); // Para poder ordenar
|
108 |
private ArrayList keys = new ArrayList(); // En lugar de un HashSet, para tener acceso por ?ndice |
109 |
// private String labelFieldName;
|
110 |
// private String labelFieldHeight;
|
111 |
// private String labelFieldRotation;
|
112 |
private ISymbol defaultSymbol;
|
113 |
private int shapeType; |
114 |
// private String valueType = NullValue.class.getName();
|
115 |
private boolean useDefaultSymbol = false; |
116 |
private Color[] selectedColors=null; |
117 |
|
118 |
private ISymbol nullValueSymbol = null; |
119 |
|
120 |
public VectorialUniqueValueLegend() {
|
121 |
// Nothing to do
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Constructor method
|
126 |
*
|
127 |
* @param shapeType Type of the shape.
|
128 |
*/
|
129 |
public VectorialUniqueValueLegend(int shapeType) { |
130 |
setShapeType(shapeType); |
131 |
} |
132 |
|
133 |
public void setShapeType(int shapeType) { |
134 |
if (this.shapeType != shapeType) { |
135 |
ISymbol old = defaultSymbol; |
136 |
defaultSymbol = getManager().createSymbol(shapeType); |
137 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
|
138 |
this.shapeType = shapeType;
|
139 |
} |
140 |
} |
141 |
|
142 |
public void setValueSymbolByID(int id, ISymbol symbol) { |
143 |
ISymbol old = (ISymbol)symbols.put(keys.get(id), symbol); |
144 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
|
145 |
} |
146 |
|
147 |
// /**
|
148 |
// * Used in the table that shows the legend
|
149 |
// *
|
150 |
// * @deprecated use setValueSymbolByID(int id, ISymbol symbol);
|
151 |
// * @param reference
|
152 |
// * @param symbol
|
153 |
// */
|
154 |
// public void setValueSymbol(int id, ISymbol symbol) {
|
155 |
// ISymbol old = symbols.put(keys.get(id), symbol);
|
156 |
// fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
|
157 |
// }
|
158 |
|
159 |
public Object[] getValues() { |
160 |
return symbols.keySet().toArray(new Object[0]); |
161 |
} |
162 |
|
163 |
public void addSymbol(Object key, ISymbol symbol) { |
164 |
ISymbol resul; |
165 |
if (key == null) { |
166 |
resul = nullValueSymbol; |
167 |
nullValueSymbol = symbol; |
168 |
} |
169 |
else {
|
170 |
resul = (ISymbol) symbols.put(key, symbol); |
171 |
|
172 |
if (resul != null) { |
173 |
logger.error("Error: la clave " + key + " ya exist?a. Resul = " |
174 |
+ resul); |
175 |
logger.warn("symbol nuevo:" + symbol.getDescription()
|
176 |
+ " Sviejo= " + resul.getDescription());
|
177 |
} else {
|
178 |
keys.add(key); |
179 |
} |
180 |
} |
181 |
|
182 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(resul, symbol));
|
183 |
} |
184 |
|
185 |
public void clear() { |
186 |
keys.clear(); |
187 |
ISymbol[] olds = (ISymbol[])symbols.values().toArray(new ISymbol[0]); |
188 |
symbols.clear(); |
189 |
removeLegendListener(getZSort()); |
190 |
setZSort(null);
|
191 |
|
192 |
fireLegendClearEvent(new LegendClearEvent(olds));
|
193 |
} |
194 |
|
195 |
public String[] getDescriptions() { |
196 |
String[] descriptions = new String[symbols.size()]; |
197 |
ISymbol[] auxSym = getSymbols();
|
198 |
|
199 |
for (int i = 0; i < descriptions.length; i++) { |
200 |
descriptions[i] = auxSym[i].getDescription(); |
201 |
} |
202 |
|
203 |
return descriptions;
|
204 |
} |
205 |
|
206 |
public ISymbol[] getSymbols() { |
207 |
ISymbol[] symbolList;
|
208 |
if (nullValueSymbol == null) { |
209 |
symbolList = new ISymbol[symbols.size()];
|
210 |
return (ISymbol[]) symbols.values().toArray(symbolList); |
211 |
} |
212 |
else {
|
213 |
symbolList = new ISymbol[symbols.size() + 1]; |
214 |
symbolList[0] = nullValueSymbol;
|
215 |
int i = 1; |
216 |
for (Iterator iterator = symbols.values().iterator(); iterator |
217 |
.hasNext();) { |
218 |
symbolList[i] = (ISymbol) iterator.next(); |
219 |
i++; |
220 |
} |
221 |
return symbolList;
|
222 |
} |
223 |
} |
224 |
|
225 |
public void setClassifyingFieldNames(String[] fNames) { |
226 |
super.setClassifyingFieldNames(fNames);
|
227 |
// try {
|
228 |
// fieldId = ((FeatureType)featureStore.getFeatureTypes().get(0)).getIndex(getClassifyingFieldNames()[0]);
|
229 |
// } catch (NullPointerException e) {
|
230 |
// logger.warn("data source not set");
|
231 |
// } catch (DataException e) {
|
232 |
// logger.warn("data source not set");
|
233 |
// }
|
234 |
} |
235 |
/*
|
236 |
* @see com.iver.cit.gvsig.fmap.rendering.IVectorialLegend#getSymbol(int)
|
237 |
*/
|
238 |
// public ISymbol getSymbol(int recordIndex) throws ReadException {
|
239 |
// Object val = dataSource.getFieldValue(recordIndex, fieldId);
|
240 |
// ISymbol theSymbol = getSymbolByValue(val);
|
241 |
//
|
242 |
// return theSymbol;
|
243 |
// }
|
244 |
|
245 |
/**
|
246 |
* Devuelve un s?mbolo a partir de una IFeature. OJO!! Cuando usamos un
|
247 |
* feature iterator de base de datos el ?nico campo que vendr? rellenado es
|
248 |
* el de fieldID. Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
|
249 |
*
|
250 |
* @param feat
|
251 |
* IFeature
|
252 |
*
|
253 |
* @return S?mbolo.
|
254 |
* @throws MapContextException
|
255 |
*/
|
256 |
public ISymbol getSymbolByFeature(Feature feat) throws MapContextException { |
257 |
|
258 |
Object val = feat.get(getClassifyingFieldNames()[0]); |
259 |
// Object val = feat.get(fieldId);
|
260 |
ISymbol theSymbol = getSymbolByValue(val); |
261 |
|
262 |
if (theSymbol != null) { |
263 |
return theSymbol;
|
264 |
|
265 |
} |
266 |
|
267 |
if (isUseDefaultSymbol()) {
|
268 |
return defaultSymbol;
|
269 |
} |
270 |
|
271 |
return null; |
272 |
} |
273 |
|
274 |
|
275 |
public ISymbol getDefaultSymbol() {
|
276 |
|
277 |
if(defaultSymbol==null) { |
278 |
defaultSymbol = getManager().createSymbol(shapeType); |
279 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol)); |
280 |
} |
281 |
return defaultSymbol;
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* TODO: replace with new Persistence API
|
286 |
*/
|
287 |
public XMLEntity getXMLEntity() throws XMLException { |
288 |
return null; |
289 |
// XMLEntity xml = new XMLEntity();
|
290 |
// xml.putProperty("className", this.getClass().getName());
|
291 |
// xml.putProperty("fieldNames", getClassifyingFieldNames()[0]);
|
292 |
//
|
293 |
// if (getClassifyingFieldTypes()!=null)
|
294 |
// xml.putProperty("fieldTypes", getClassifyingFieldTypes()[0]);
|
295 |
//
|
296 |
// if (selectedColors != null) {
|
297 |
// String[] strColors = new String[selectedColors.length];
|
298 |
// for (int i = 0; i < strColors.length; i++) {
|
299 |
// strColors[i] = StringUtilities.color2String(selectedColors[i]);
|
300 |
// }
|
301 |
// xml.putProperty("colorScheme", strColors);
|
302 |
// }
|
303 |
//
|
304 |
// xml.putProperty("labelfield", labelFieldName);
|
305 |
// xml.putProperty("labelFieldHeight", labelFieldHeight);
|
306 |
// xml.putProperty("labelFieldRotation", labelFieldRotation);
|
307 |
//
|
308 |
// xml.putProperty("useDefaultSymbol", useDefaultSymbol);
|
309 |
// xml.addChild(getDefaultSymbol().getXMLEntity());
|
310 |
// xml.putProperty("numKeys", keys.size());
|
311 |
//
|
312 |
//
|
313 |
// if (keys.size() > 0) {
|
314 |
// xml.putProperty("tipoValueKeys", valueType);
|
315 |
//
|
316 |
// String[] sk = new String[keys.size()];
|
317 |
// int[] stk = new int[keys.size()];
|
318 |
// Object[] values = getValues();
|
319 |
// String[] sv = new String[values.length];
|
320 |
// int[] stv = new int[values.length];
|
321 |
//
|
322 |
// for (int i = 0; i < keys.size(); i++) {
|
323 |
// Object key = keys.get(i);
|
324 |
// sk[i] = key.toString();
|
325 |
// stk[i] = getSQLType(key);
|
326 |
// }
|
327 |
//
|
328 |
// for (int i=0; i < values.length; i++){
|
329 |
// Object value = values[i];
|
330 |
// sv[i] = value.toString();
|
331 |
// stv[i] = getSQLType(value);
|
332 |
// xml.addChild(((ISymbol)symbols.get(value)).getXMLEntity());
|
333 |
// }
|
334 |
//
|
335 |
// xml.putProperty("keys", sk);
|
336 |
// xml.putProperty("values", sv);
|
337 |
// xml.putProperty("typeKeys", stk);
|
338 |
// xml.putProperty("typeValues", stv);
|
339 |
// }
|
340 |
//
|
341 |
//
|
342 |
// if (getZSort()!=null) {
|
343 |
// XMLEntity xmlZSort = getZSort().getXMLEntity();
|
344 |
// xmlZSort.putProperty("id", "zSort");
|
345 |
// xml.addChild(xmlZSort);
|
346 |
// }
|
347 |
// return xml;
|
348 |
} |
349 |
|
350 |
// private int getSQLType(Object object) {
|
351 |
// if (object instanceof Integer){
|
352 |
// return Types.INTEGER;
|
353 |
// }else if (object instanceof Long){
|
354 |
// return Types.BIGINT;
|
355 |
// }else if (object instanceof Float){
|
356 |
// return Types.FLOAT;
|
357 |
// }else if (object instanceof Double){
|
358 |
// return Types.DOUBLE;
|
359 |
// }else if (object instanceof NullUniqueValue){
|
360 |
// return Types.OTHER;
|
361 |
// }
|
362 |
// return Types.LONGVARCHAR;
|
363 |
// }
|
364 |
|
365 |
/**
|
366 |
* TODO: replace with the new Persistence API (libTools)
|
367 |
*/
|
368 |
public void setXMLEntity(XMLEntity xml) { |
369 |
// clear();
|
370 |
// if (xml.contains("fieldName")) {
|
371 |
// setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")});
|
372 |
// } else {
|
373 |
// setClassifyingFieldNames(xml.getStringArrayProperty("fieldNames"));
|
374 |
// }
|
375 |
//
|
376 |
// if (xml.contains("fieldTypes")) {
|
377 |
// setClassifyingFieldTypes(xml.getIntArrayProperty("fieldTypes"));
|
378 |
// }
|
379 |
// if (xml.contains("colorScheme")) {
|
380 |
// String[] strColors = xml.getStringArrayProperty("colorScheme");
|
381 |
//
|
382 |
// Color[] cc = new Color[strColors.length];
|
383 |
// for (int i = 0; i < cc.length; i++) {
|
384 |
// cc[i] = StringUtilities.string2Color(strColors[i]);
|
385 |
// }
|
386 |
// setColorScheme(cc);
|
387 |
// }
|
388 |
// useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol");
|
389 |
// setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
|
390 |
//
|
391 |
// int numKeys = xml.getIntProperty("numKeys");
|
392 |
//
|
393 |
// if (numKeys > 0) {
|
394 |
// String className = xml.getStringProperty("tipoValueKeys");
|
395 |
// String[] sk = xml.getStringArrayProperty("keys");
|
396 |
// if(sk.length == 0){
|
397 |
// sk = new String[]{""};
|
398 |
// }
|
399 |
// String[] sv = xml.getStringArrayProperty("values");
|
400 |
// if(sv.length == 0){
|
401 |
// sv = new String[]{""};
|
402 |
// }
|
403 |
// Object auxValue = null;
|
404 |
// Object auxValue2 = null;
|
405 |
// ISymbol sym;
|
406 |
// int[] stk = null;
|
407 |
// if (xml.contains("typeKeys")) {
|
408 |
// stk = xml.getIntArrayProperty("typeKeys");
|
409 |
// int[] stv = xml.getIntArrayProperty("typeValues");
|
410 |
// for (int i = 0; i < numKeys; i++) {
|
411 |
// auxValue = getValue(sk[i], stk[i]);
|
412 |
// keys.add(auxValue);
|
413 |
// }
|
414 |
//
|
415 |
// boolean foundNullValue = false;
|
416 |
// for (int i = 0; i < sv.length; i++) {
|
417 |
// auxValue2 = getValue(sv[i], stv[i]);
|
418 |
// if ( auxValue2 instanceof NullValue ) {
|
419 |
// foundNullValue = true;
|
420 |
// auxValue2 = new NullUniqueValue();
|
421 |
// sym = getDefaultSymbol();
|
422 |
// } else {
|
423 |
// sym = SymbologyFactory.createSymbolFromXML(xml
|
424 |
// .getChild(i+1), null);
|
425 |
// }
|
426 |
//
|
427 |
// symbols.put(auxValue2, sym);
|
428 |
// }
|
429 |
// if (!foundNullValue && useDefaultSymbol){
|
430 |
// auxValue2 = new NullUniqueValue();
|
431 |
// sym = getDefaultSymbol();
|
432 |
// symbols.put(auxValue2, sym);
|
433 |
// }
|
434 |
// } else {
|
435 |
//
|
436 |
//
|
437 |
// for (int i = 0; i < numKeys; i++) {
|
438 |
// auxValue = getValue(sk[i]);
|
439 |
// if ( auxValue == null ) { //Default
|
440 |
// auxValue = new NullUniqueValue();
|
441 |
// }
|
442 |
// keys.add(auxValue);
|
443 |
// }
|
444 |
//
|
445 |
// boolean foundNullValue = false;
|
446 |
// for (int i = 0; i < sv.length; i++) {
|
447 |
// auxValue2 = getValue(sv[i]);
|
448 |
// if ( auxValue2 == null ) { //Default
|
449 |
// foundNullValue = true;
|
450 |
// auxValue2 = new NullUniqueValue();
|
451 |
// sym = getDefaultSymbol();
|
452 |
// } else {
|
453 |
// sym = SymbologyFactory.createSymbolFromXML(xml
|
454 |
// .getChild(i+1), null);
|
455 |
// }
|
456 |
//
|
457 |
// symbols.put(auxValue2, sym);
|
458 |
// }
|
459 |
// if (!foundNullValue && useDefaultSymbol){
|
460 |
// auxValue2 = new NullUniqueValue();
|
461 |
// sym = getDefaultSymbol();
|
462 |
// symbols.put(auxValue2, sym);
|
463 |
// }
|
464 |
// }
|
465 |
// }
|
466 |
//
|
467 |
//
|
468 |
//
|
469 |
// XMLEntity zSortXML = xml.firstChild("id", "zSort");
|
470 |
// if (zSortXML != null) {
|
471 |
// ZSort zSort = new ZSort(this);
|
472 |
// zSort.setXMLEntity(zSortXML);
|
473 |
// addLegendListener(zSort);
|
474 |
// setZSort(zSort);
|
475 |
// }
|
476 |
} |
477 |
|
478 |
public void setDefaultSymbol(ISymbol s) { |
479 |
ISymbol mySymbol = defaultSymbol; |
480 |
|
481 |
if (s == null) { |
482 |
throw new NullPointerException("Default symbol cannot be null"); |
483 |
} |
484 |
|
485 |
ISymbol old = mySymbol; |
486 |
defaultSymbol = s; |
487 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* Returns the value using the its value in a string.
|
492 |
*
|
493 |
*
|
494 |
* @param s String with the value.
|
495 |
* @deprecated Method used until 1.0 alpha 855 You should use getValue(String s,int type);
|
496 |
* @return Value.
|
497 |
*/
|
498 |
// private Object getValue(String s) {
|
499 |
// Object val = new NullUniqueValue();
|
500 |
// if (s.equals("Resto de Valores")) {
|
501 |
// return val;
|
502 |
// }
|
503 |
//// try {
|
504 |
// try {
|
505 |
// val = new Integer(s);//(s, Types.INTEGER);
|
506 |
//
|
507 |
// return val;
|
508 |
// } catch (NumberFormatException e) {
|
509 |
// }
|
510 |
//
|
511 |
// try {
|
512 |
// val = new Long(s);//ValueFactory.createValueByType(s, Types.BIGINT);
|
513 |
//
|
514 |
// return val;
|
515 |
// } catch (NumberFormatException e) {
|
516 |
// }
|
517 |
//
|
518 |
// try {
|
519 |
// val = new Float(s);//ValueFactory.createValueByType(s, Types.FLOAT);
|
520 |
//
|
521 |
// return val;
|
522 |
// } catch (NumberFormatException e) {
|
523 |
// }
|
524 |
//
|
525 |
// try {
|
526 |
// val = new Double(s);//ValueFactory.createValueByType(s, Types.DOUBLE);
|
527 |
//
|
528 |
// return val;
|
529 |
// } catch (NumberFormatException e) {
|
530 |
// }
|
531 |
//
|
532 |
// val = s;//ValueFactory.createValueByType(s, Types.LONGVARCHAR);
|
533 |
//
|
534 |
//// } catch (ParseException e) {
|
535 |
//// log.warn("parse exception", e);
|
536 |
//// }
|
537 |
//
|
538 |
// return val;
|
539 |
// }
|
540 |
|
541 |
/**
|
542 |
* Devuelve el valor a partir de su valor en un string.
|
543 |
*
|
544 |
* @param s String con el valor.
|
545 |
*
|
546 |
* @return Value.
|
547 |
* @throws MapContextException
|
548 |
*/
|
549 |
// private Object getValue(String s,int type) {
|
550 |
// Object val = new NullUniqueValue();
|
551 |
// if (type==Types.OTHER) {
|
552 |
// return val;
|
553 |
// }
|
554 |
// switch (type) {
|
555 |
// case Types.INTEGER:
|
556 |
// val = new Integer(s);
|
557 |
// break;
|
558 |
// case Types.BIGINT:
|
559 |
// val = new Long(s);
|
560 |
// break;
|
561 |
// case Types.FLOAT:
|
562 |
// val = new Float(s);
|
563 |
// break;
|
564 |
// case Types.DOUBLE:
|
565 |
// val = new Double(s);
|
566 |
// break;
|
567 |
// default:
|
568 |
// val=s;
|
569 |
// break;
|
570 |
// }
|
571 |
// return val;
|
572 |
// }
|
573 |
|
574 |
|
575 |
// /**
|
576 |
// * TODO: replace using the new Persistence API.
|
577 |
// */
|
578 |
// public ILegend cloneLegend() throws XMLException {
|
579 |
// // Example:
|
580 |
//// PersistenceManager manager = ToolsLocator.getPersistenceManager();
|
581 |
//// PersistentState state = manager.getState(this);
|
582 |
//// return manager.create(state);
|
583 |
//
|
584 |
// return null;
|
585 |
// }
|
586 |
|
587 |
|
588 |
/* (non-Javadoc)
|
589 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
590 |
*/
|
591 |
// public void setFeatureStore(FeatureStore fs) throws DataException {
|
592 |
// featureStore = fs;
|
593 |
//// if (getClassifyingFieldNames()!=null) {
|
594 |
//// fieldId = ((FeatureType)fs.getFeatureTypes().get(0)).getIndex(getClassifyingFieldNames()[0]);
|
595 |
//// }
|
596 |
// }
|
597 |
|
598 |
/*
|
599 |
* (non-Javadoc)
|
600 |
*
|
601 |
* @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
|
602 |
*/
|
603 |
public ISymbol getSymbolByValue(Object key) { |
604 |
ISymbol symbol = null;
|
605 |
if (key == null) { |
606 |
symbol = nullValueSymbol; |
607 |
} |
608 |
else {
|
609 |
symbol = (ISymbol)symbols.get(key); |
610 |
} |
611 |
if (symbol == null && useDefaultSymbol) { |
612 |
symbol = getDefaultSymbol(); |
613 |
} |
614 |
return symbol;
|
615 |
|
616 |
} |
617 |
|
618 |
public int getShapeType() { |
619 |
return shapeType;
|
620 |
} |
621 |
|
622 |
public void useDefaultSymbol(boolean b) { |
623 |
useDefaultSymbol = b; |
624 |
} |
625 |
|
626 |
/**
|
627 |
* Devuelve si se utiliza o no el resto de valores para representarse.
|
628 |
* @return True si se utiliza el resto de valores.
|
629 |
*/
|
630 |
public boolean isUseDefaultSymbol() { |
631 |
return useDefaultSymbol;
|
632 |
} |
633 |
|
634 |
public void delSymbol(Object key) { |
635 |
keys.remove(key); |
636 |
|
637 |
ISymbol removedSymbol = (ISymbol) symbols.remove(key); |
638 |
if (removedSymbol != null){ |
639 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(removedSymbol, null)); |
640 |
} |
641 |
} |
642 |
|
643 |
public String getClassName() { |
644 |
return getClass().getName();
|
645 |
} |
646 |
|
647 |
public void replace(ISymbol oldSymbol, ISymbol newSymbol) { |
648 |
if (symbols.containsValue(oldSymbol)) {
|
649 |
Iterator it = symbols.keySet().iterator();
|
650 |
while (it.hasNext()) {
|
651 |
Object key = it.next();
|
652 |
if (symbols.get(key).equals(oldSymbol)) {
|
653 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(
|
654 |
(ISymbol)symbols.put(key, newSymbol), newSymbol)); |
655 |
} |
656 |
|
657 |
} |
658 |
} |
659 |
} |
660 |
public Color[] getColorScheme() { |
661 |
return selectedColors;
|
662 |
} |
663 |
|
664 |
public void setColorScheme(Color[] cc) { |
665 |
this.selectedColors = cc;
|
666 |
} |
667 |
|
668 |
} |