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