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