Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / VectorialUniqueValueLegend.java @ 18621

History | View | Annotate | Download (20.4 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.sql.Types;
44
import java.text.ParseException;
45
import java.util.ArrayList;
46
import java.util.Comparator;
47
import java.util.Iterator;
48
import java.util.TreeMap;
49

    
50
import org.apache.log4j.Logger;
51

    
52
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
53
import com.hardcode.gdbms.engine.data.DataSource;
54
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
55
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException;
56
import com.hardcode.gdbms.engine.instruction.SemanticException;
57
import com.hardcode.gdbms.engine.values.BooleanValue;
58
import com.hardcode.gdbms.engine.values.NullValue;
59
import com.hardcode.gdbms.engine.values.StringValue;
60
import com.hardcode.gdbms.engine.values.Value;
61
import com.hardcode.gdbms.engine.values.ValueFactory;
62
import com.iver.cit.gvsig.fmap.core.IFeature;
63
import com.iver.cit.gvsig.fmap.core.ISLDCompatible;
64
import com.iver.cit.gvsig.fmap.core.SLDTags;
65
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
66
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
67
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
68
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
69
import com.iver.cit.gvsig.fmap.layers.XMLException;
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
        /**
151
     * Constructor method
152
     */
153
    public VectorialUniqueValueLegend() {
154
    }
155

    
156
    /**
157
     * Constructor method 
158
     *
159
     * @param shapeType Type of the shape.
160
     */
161
    public VectorialUniqueValueLegend(int shapeType) {
162
        setShapeType(shapeType);
163
    }
164

    
165
     public void setShapeType(int shapeType) {
166
            if (this.shapeType != shapeType) {
167
                    ISymbol old = defaultSymbol;
168
                    defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType);
169
                    fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
170
                    this.shapeType = shapeType;
171
            }
172
    }
173

    
174
    public void setValueSymbolByID(int id, ISymbol symbol) {
175
        ISymbol old = symbols.put(keys.get(id), symbol);
176
        fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
177
    }
178

    
179
    /**
180
     * Used in the table that shows the legend
181
     * 
182
     * @deprecated use setValueSymbolByID(int id, ISymbol symbol);
183
     * @param id
184
     * @param symbol
185
     */
186
    public void setValueSymbol(int id, ISymbol symbol) {
187
            ISymbol old = symbols.put(keys.get(id), symbol);
188
        fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(old, symbol));
189
    }
190

    
191
    public Object[] getValues() {
192
        return symbols.keySet().toArray(new Object[0]);
193
    }
194

    
195
    public void addSymbol(Object key, ISymbol symbol) {
196
        ISymbol resul;
197
        resul = symbols.put((Value) key, symbol);
198

    
199
        if (resul != null) {
200
                log.error("Error: la clave " + key +
201
                " ya exist?a. Resul = " + resul);
202
            log.warn("symbol nuevo:" + symbol.getDescription() +
203
                " Sviejo= " + resul.getDescription());
204
        } else { 
205
            keys.add((Value) key);
206

    
207
            if (!key.getClass().equals(NullValue.class)) {
208
                valueType = key.getClass().getName();
209
            }
210
        }
211
        
212
        fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(resul, symbol));
213
       
214
    }
215

    
216
    public void clear() {
217
        keys.clear();
218
        ISymbol[] olds = symbols.values().toArray(new ISymbol[0]);
219
        symbols.clear();
220
        removeLegendListener(getZSort());
221
        setZSort(null);
222
        
223
        fireLegendClearEvent(new LegendClearEvent(olds));
224
    }
225

    
226
    public String[] getDescriptions() {
227
        String[] descriptions = new String[symbols.size()];
228
        ISymbol[] auxSym = getSymbols();
229

    
230
        for (int i = 0; i < descriptions.length; i++)
231
            descriptions[i] = auxSym[i].getDescription();
232

    
233
        return descriptions;
234
    }
235

    
236
     public ISymbol[] getSymbols() {
237
        return symbols.values().toArray(new ISymbol[0]);
238
    }
239

    
240
     @Override
241
     public void setClassifyingFieldNames(String[] fNames) {
242
             super.setClassifyingFieldNames(fNames);
243
             try {
244
                     fieldId = dataSource.getFieldIndexByName(getClassifyingFieldNames()[0]);
245
             } catch (NullPointerException e) {
246
                     log.warn("data source not set");
247
             } catch (ReadDriverException e) {
248
                     log.warn("failed setting field id");
249
             }
250
     }
251
    /*
252
     * @see com.iver.cit.gvsig.fmap.rendering.IVectorialLegend#getSymbol(int)
253
     */
254
    public ISymbol getSymbol(int recordIndex) throws ReadDriverException {
255
                Value val = dataSource.getFieldValue(recordIndex, fieldId);
256
                ISymbol theSymbol = getSymbolByValue(val);
257

    
258
                return theSymbol;
259
        }
260

    
261
    /**
262
         * Devuelve un s?mbolo a partir de una IFeature. OJO!! Cuando usamos un
263
         * feature iterator de base de datos el ?nico campo que vendr? rellenado es
264
         * el de fieldID. Los dem?s vendr?n a nulos para ahorra tiempo de creaci?n.
265
         *
266
         * @param feat
267
         *            IFeature
268
         *
269
         * @return S?mbolo.
270
         */
271
    public ISymbol getSymbolByFeature(IFeature feat) {
272
        Value val = feat.getAttribute(FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD
273
                        ? 0 :fieldId);
274
        ISymbol theSymbol = getSymbolByValue(val);
275

    
276
        if (theSymbol != null) {
277
                return theSymbol;
278

    
279
        } 
280

    
281
               return getDefaultSymbol();
282
    }
283

    
284
    public ISymbol getDefaultSymbol() {
285

    
286
            NullUniqueValue nuv=new NullUniqueValue();
287
            if (symbols.containsKey(nuv))
288
                    return symbols.get(nuv);
289

    
290
            if(defaultSymbol==null) {
291
                    defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType);
292
                    fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol));
293
            }
294
        return defaultSymbol;
295
    }
296

    
297
    
298
        public String getSLDString(String name)        {
299
            try {
300

    
301
                        XmlBuilder xmlBuilder = new XmlBuilder();
302
                        xmlBuilder.writeHeader();
303
                        xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0);
304
                        xmlBuilder.openTag(SLDTags.NAMEDLAYER);
305
                        xmlBuilder.writeTag(SLDTags.NAME,name);
306
                        xmlBuilder.openTag(SLDTags.USERSTYLE);
307
                        xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE);
308
                        //xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"fieldName");
309

    
310
                        ISymbol[] mySymbols = this.getSymbols();
311
                        Object[] values = this.getValues();
312
                        String valueStr = null;
313

    
314
                        for(int i = 0; i < mySymbols.length; i++ ){
315
                                valueStr = values[i].toString();
316
                                xmlBuilder.openTag(SLDTags.RULE);
317
                                xmlBuilder.writeTag(SLDTags.NAME, valueStr);
318
                                xmlBuilder.openTag(SLDTags.FILTER);
319
                                xmlBuilder.openTag(SLDTags.PROPERTYISEQUALTO);
320
                                xmlBuilder.writeTag(SLDTags.PROPERTYNAME, getClassifyingFieldNames()[0]);
321
                                xmlBuilder.writeTag(SLDTags.LITERAL, valueStr);
322
                                xmlBuilder.closeTag();
323
                                xmlBuilder.closeTag();
324
                                if (mySymbols[i] instanceof ISLDCompatible) {
325
                                        ISLDCompatible symSLD = (ISLDCompatible) mySymbols[i];
326
                                        xmlBuilder.writeRaw(symSLD.toSLD());
327
                                } else
328
                                        throw new RuntimeException("Cannot convert Symbol " + i + " " + mySymbols[i].getDescription() + " to SLD");
329

    
330
                                xmlBuilder.closeTag();
331
                        }
332

    
333
                        xmlBuilder.closeTag();
334
                        xmlBuilder.closeTag();
335
                        xmlBuilder.closeTag();
336
                        xmlBuilder.closeTag();
337
                        return xmlBuilder.getXML();
338

    
339
            } catch (Exception e) {
340
                    e.printStackTrace();
341
                    return null;
342
            }
343
        }
344

    
345
    public XMLEntity getXMLEntity() {
346
        XMLEntity xml = new XMLEntity();
347
        xml.putProperty("className", this.getClass().getName());
348
        xml.putProperty("fieldNames", getClassifyingFieldNames()[0]);
349
        
350
        ///////////////////////////////////////PEPE
351
        xml.putProperty("fieldTypes", getClassifyingFieldTypes()[0]);
352
        ///////////////////////////////////////PEPE
353
        
354
        xml.putProperty("labelfield", labelFieldName);
355
        xml.putProperty("labelFieldHeight", labelFieldHeight);
356
        xml.putProperty("labelFieldRotation", labelFieldRotation);
357

    
358
        xml.putProperty("useDefaultSymbol", useDefaultSymbol);
359
        xml.addChild(getDefaultSymbol().getXMLEntity());
360
        xml.putProperty("numKeys", keys.size());
361

    
362
        if (keys.size() > 0) {
363
            xml.putProperty("tipoValueKeys", valueType);
364

    
365
            String[] sk = new String[keys.size()];
366
            String[] sv = new String[keys.size()];
367
            int[] stk = new int[keys.size()];
368
            int[] stv = new int[keys.size()];
369
            ISymbol[] fsymbols = getSymbols();
370
            Object[] values = getValues();
371

    
372
            for (int i = 0; i < keys.size(); i++) {
373
                    if (keys.get(i).toString().equals("")) {
374
                            sk[i] =" ";
375
                    }else {
376
                            sk[i] = keys.get(i).toString();
377
                    }
378
                    if (((Value) values[i]).toString().equals("")) {
379
                            sv[i] =" ";
380
                    }else {
381
                            sv[i] = ((Value) values[i]).toString();
382
                    }
383
                    stk[i]= keys.get(i).getSQLType();
384
                    stv[i]= ((Value)values[i]).getSQLType();
385
                xml.addChild(fsymbols[i].getXMLEntity());
386

    
387
                ///System.out.println("get-----------"+sk[i]+"--"+fsymbols[i].getDescription()+"---"+fsymbols[i].getColor());
388
            }
389

    
390
            xml.putProperty("keys", sk);
391
            xml.putProperty("values", sv);
392
            xml.putProperty("typeKeys",stk);
393
            xml.putProperty("typeValues",stv);
394
        }
395
        
396
        if (getZSort()!=null) {
397
                XMLEntity xmlZSort = getZSort().getXMLEntity();
398
                xmlZSort.putProperty("id", "zSort");
399
                xml.addChild(xmlZSort);
400
        }
401
        return xml;
402
    }
403

    
404
    public void setXMLEntity03(XMLEntity xml) {
405
        clear();
406
        setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")});
407

    
408
        int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol");
409

    
410
        if (useDefaultSymbol == 1) {
411
            setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
412
        } else {
413
            setDefaultSymbol(null);
414
        }
415

    
416
        int numKeys = xml.getIntProperty("numKeys");
417

    
418
        if (numKeys > 0) {
419
            String className = xml.getStringProperty("tipoValueKeys");
420
            String[] sk = xml.getStringArrayProperty("keys");
421
            String[] sv = xml.getStringArrayProperty("values");
422
            Value auxValue;
423
            Value auxValue2;
424

    
425
            for (int i = 0; i < numKeys; i++) {
426
                try {
427
                    auxValue = ValueFactory.createValue(sk[i], className);
428
                    auxValue2 = ValueFactory.createValue(sv[i], className);
429

    
430
                    ISymbol sym = FSymbol.createFromXML03(xml.getChild(i +
431
                                useDefaultSymbol));
432

    
433
                    symbols.put(auxValue2, sym);
434
                    keys.add(auxValue);
435

    
436
                } catch (SemanticException e) {
437
                        log.error("Exception", e);
438
                    e.printStackTrace();
439
                }
440
            }
441
        }
442
    }
443

    
444
    public void setXMLEntity(XMLEntity xml) {
445
        clear();
446
        if (xml.contains("fieldName"))
447
                setClassifyingFieldNames(new String[] {xml.getStringProperty("fieldName")});
448
        else
449
                setClassifyingFieldNames(xml.getStringArrayProperty("fieldNames"));
450

    
451
        if (xml.contains("fieldTypes"))
452
                setClassifyingFieldTypes(new int[] {xml.getIntProperty("fieldTypes")});
453

    
454
        useDefaultSymbol = xml.getBooleanProperty("useDefaultSymbol");
455
        setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
456

    
457
        int numKeys = xml.getIntProperty("numKeys");
458

    
459
        if (numKeys > 0) {
460
            String className = xml.getStringProperty("tipoValueKeys");
461
            String[] sk = xml.getStringArrayProperty("keys");
462
            String[] sv = xml.getStringArrayProperty("values");
463
            Value auxValue = null;
464
            Value auxValue2 = null;
465
            int[] stk=null;
466
            if (xml.contains("typeKeys")) {
467
                                stk = xml.getIntArrayProperty("typeKeys");
468
                                int[] stv = xml.getIntArrayProperty("typeValues");
469
                                for (int i = 0; i < numKeys; i++) {
470
                                        boolean isDefault = false;
471
                                        if (getValue(sk[i], stk[i]) == null) {
472
                                                isDefault = true;
473
                                        }
474

    
475
                                        if (className
476
                                                        .equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
477
                                                        || isDefault) {
478
                                                auxValue = new NullUniqueValue();
479
                                                auxValue2 = ValueFactory.createNullValue();
480
                                        } else {
481
                                                auxValue = getValue(sk[i], stk[i]); // ValueFactory.createValue(sk[i],
482
                                                                                                                        // className);
483
                                                auxValue2 = getValue(sv[i], stv[i]); // ValueFactory.createValue(sv[i],
484
                                                                                                                                // className);
485
                                        }
486

    
487
                                        // (substituir la de baix per esta) ISymbol sym = SymbolFactory.createFromXML(xml.getChild(i + 1), null);
488
                                        ISymbol sym = SymbologyFactory.createSymbolFromXML(xml.getChild(i + 1), null);
489
                                        symbols.put(auxValue2, sym);
490
                                        keys.add(auxValue);
491
                                }
492
                        } else {
493
                                for (int i = 0; i < numKeys; i++) {
494
                                        boolean isDefault = false;
495
                                        if (getValue(sk[i]) == null) {
496
                                                isDefault = true;
497
                                        }
498
                                        if (className
499
                                                        .equals("com.hardcode.gdbms.engine.values.NullUniqueValue")
500
                                                        || isDefault) {
501
                                                auxValue = new NullUniqueValue();
502
                                                auxValue2 = ValueFactory.createNullValue();
503
                                        } else {
504
                                                auxValue = getValue(sk[i]); // ValueFactory.createValue(sk[i],
505
                                                                                                        // className);
506
                                                auxValue2 = getValue(sv[i]); // ValueFactory.createValue(sv[i],
507
                                                                                                                // className);
508
                                        }
509
                                        ISymbol sym = FSymbol.createFromXML(xml.getChild(i + 1));
510
                                        symbols.put(auxValue2, sym);
511
                                        keys.add(auxValue);
512
                                }
513
                        }
514
        }
515
        
516
        XMLEntity zSortXML = xml.firstChild("id", "zSort");
517
                if (zSortXML != null) {
518
                        ZSort zSort = new ZSort(this);
519
                        zSort.setXMLEntity(zSortXML);
520
                        addLegendListener(zSort);
521
                        setZSort(zSort);
522
                }
523
    }
524

    
525
    public void setDefaultSymbol(ISymbol s) {
526
            if (s == null) throw new NullPointerException("Default symbol cannot be null");
527
            ISymbol old = defaultSymbol;
528
        defaultSymbol = s;
529
                fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
530
                
531

    
532
    }
533
    /**
534
     * Returns the value using the its value in a string.
535
         * 
536
         *
537
         * @param s String with the value.
538
         * @deprecated Method used until 1.0 alpha 855 You should use getValue(String s,int type);
539
         * @return Value.
540
         */
541
    private Value getValue(String s) {
542
        Value val = new NullUniqueValue();
543
        if (s.equals("Resto de Valores"))return val;
544
        try {
545
            try {
546
                val = ValueFactory.createValueByType(s, Types.INTEGER);
547

    
548
                return val;
549
            } catch (NumberFormatException e) {
550
            }
551

    
552
            try {
553
                val = ValueFactory.createValueByType(s, Types.BIGINT);
554

    
555
                return val;
556
            } catch (NumberFormatException e) {
557
            }
558

    
559
            try {
560
                val = ValueFactory.createValueByType(s, Types.FLOAT);
561

    
562
                return val;
563
            } catch (NumberFormatException e) {
564
            }
565

    
566
            try {
567
                val = ValueFactory.createValueByType(s, Types.DOUBLE);
568

    
569
                return val;
570
            } catch (NumberFormatException e) {
571
            }
572

    
573
            val = ValueFactory.createValueByType(s, Types.LONGVARCHAR);
574

    
575
        } catch (ParseException e) {
576
           log.warn("parse exception", e);
577
        }
578

    
579
        return val;
580
    }
581

    
582
    /**
583
     * Devuelve el valor a partir de su valor en un string.
584
     *
585
     * @param s String con el valor.
586
     *
587
     * @return Value.
588
     */
589
    private Value getValue(String s,int type) {
590
        Value val = new NullUniqueValue();
591
        if (type==Types.OTHER)
592
                return val;
593
        try {
594
                val = ValueFactory.createValueByType(s, type);
595
        } catch (ParseException e) {
596
            e.printStackTrace();
597
        }
598
        return val;
599
    }
600

    
601
    public ILegend cloneLegend() throws XMLException {
602
        return LegendFactory.createFromXML(getXMLEntity());
603
    }
604

    
605

    
606
    /* (non-Javadoc)
607
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
608
     */
609
    public void setDataSource(DataSource ds) throws FieldNotFoundException,
610
                        ReadDriverException {
611
                dataSource = ds;
612
                ds.start();
613
                fieldId = ds.getFieldIndexByName(getClassifyingFieldNames()[0]);
614
                ds.stop();
615
        }
616

    
617
    /*
618
     * (non-Javadoc)
619
     *
620
     * @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#getSymbolByValue(com.hardcode.gdbms.engine.values.Value)
621
     */
622
    public ISymbol getSymbolByValue(Value key) {
623
            ISymbol symbol = symbols.get(key);
624
            if (symbol!=null) {
625
                    return symbol;
626
            } else if (useDefaultSymbol) {
627
                    return getDefaultSymbol();
628
            }
629
            return null;
630

    
631
    }
632

    
633
    public int getShapeType() {
634
        return shapeType;
635
    }
636

    
637
    public void useDefaultSymbol(boolean b) {
638
        useDefaultSymbol = b;
639
    }
640

    
641
    /**
642
         * Devuelve si se utiliza o no el resto de valores para representarse.
643
         * @return  True si se utiliza el resto de valores.
644
         */
645
    public boolean isUseDefaultSymbol() {
646
        return useDefaultSymbol;
647
    }
648

    
649
    public void delSymbol(Object key) {
650
        keys.remove(key);
651
        
652
        fireClassifiedSymbolChangeEvent(
653
                        new SymbolLegendEvent(
654
                                        symbols.remove(key),
655
                                        null));
656
    }
657

    
658
        public String getClassName() {
659
                return getClass().getName();
660
        }
661
        
662
        public void replace(ISymbol oldSymbol, ISymbol newSymbol) {
663
                if (symbols.containsValue(oldSymbol)) {
664
                        Iterator<Value> it = symbols.keySet().iterator();
665
                        while (it.hasNext()) {
666
                                Value key = it.next();
667
                                if (symbols.get(key).equals(oldSymbol)) {
668
                                        fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(
669
                                                        symbols.put(key, newSymbol), newSymbol));
670
                                }
671

    
672
                        }
673
                }
674
        }
675
}