Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / VectorialUniqueValue.java @ 38639

History | View | Annotate | Download (24.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 org.gvsig.app.project.documents.view.legend.gui;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.Color;
45
import java.awt.Component;
46
import java.awt.Dimension;
47
import java.awt.GridLayout;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50
import java.util.ArrayList;
51
import java.util.Iterator;
52
import java.util.Random;
53

    
54
import javax.swing.DefaultComboBoxModel;
55
import javax.swing.ImageIcon;
56
import javax.swing.JCheckBox;
57
import javax.swing.JComboBox;
58
import javax.swing.JLabel;
59
import javax.swing.JOptionPane;
60
import javax.swing.JPanel;
61

    
62
import org.gvsig.andami.IconThemeHelper;
63
import org.gvsig.andami.PluginServices;
64
import org.gvsig.andami.messages.NotificationManager;
65
import org.gvsig.app.gui.styling.JComboBoxColorScheme;
66
import org.gvsig.app.gui.styling.SymbolLevelsWindow;
67
import org.gvsig.fmap.dal.exception.DataException;
68
import org.gvsig.fmap.dal.exception.ReadException;
69
import org.gvsig.fmap.dal.feature.Feature;
70
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
71
import org.gvsig.fmap.dal.feature.FeatureSet;
72
import org.gvsig.fmap.dal.feature.FeatureStore;
73
import org.gvsig.fmap.mapcontext.MapContextLocator;
74
import org.gvsig.fmap.mapcontext.MapContextManager;
75
import org.gvsig.fmap.mapcontext.layers.FLayer;
76
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
77
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
78
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
79
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
80
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
81
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
82
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
83
import org.gvsig.gui.beans.swing.JBlank;
84
import org.gvsig.gui.beans.swing.JButton;
85
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
86
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
87
import org.gvsig.tools.dispose.DisposableIterator;
88
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
90

    
91

    
92

    
93
/**
94
 * DOCUMENT ME!
95
 *
96
 * @author fjp To change the template for this generated type comment go to
97
 *         Window>Preferences>Java>Code Generation>Code and
98
 *         Comments
99
 */
100
public class VectorialUniqueValue extends JPanel implements ILegendPanel, ActionListener{
101
    private static final Logger logger = LoggerFactory
102
    .getLogger(VectorialUniqueValue.class);
103

    
104
    protected VectorialUniqueValueLegend theLegend;
105
    private ClassifiableVectorial layer;
106
    private SymbolTable symbolTable;
107
    protected JComboBox cmbFields;
108
    private JButton btnRemoveAll;
109
    private JButton btnRemove;
110
    private JCheckBox chbUseDefault = null;
111
    private JSymbolPreviewButton defaultSymbolPrev;
112
    private VectorialUniqueValueLegend auxLegend;
113
        private JPanel pnlCenter;
114
        private JButton btnOpenSymbolLevelsEditor;
115

    
116
        private JComboBoxColorScheme cmbColorScheme;
117
        private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
118
                
119
        private MapContextManager mapContextManager = MapContextLocator
120
                        .getMapContextManager();
121

    
122
    /**
123
     *
124
     */
125
    public VectorialUniqueValue() {
126
        super();
127
        initComponents();
128
    }
129

    
130
    /**
131
     * DOCUMENT ME!
132
     */
133
    protected void initComponents() {
134
        JPanel pnlButtons = new JPanel();
135

    
136
        JButton btnAddAll = new JButton(PluginServices.getText(this,
137
                    "Anadir_todos"));
138
        btnAddAll.setActionCommand("ADD_ALL_VALUES");
139
        btnAddAll.addActionListener(this);
140
        pnlButtons.add(btnAddAll);
141

    
142
        JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir"));
143
        btnAdd.setActionCommand("ADD_VALUE");
144
        btnAdd.addActionListener(this);
145
        pnlButtons.add(btnAdd);
146

    
147
        btnRemoveAll = new JButton(PluginServices.getText(this, "Quitar_todos"));
148
        btnRemoveAll.setActionCommand("REMOVE_ALL");
149
        btnRemoveAll.addActionListener(this);
150
        pnlButtons.add(btnRemoveAll);
151

    
152
        btnRemove = new JButton(PluginServices.getText(this, "Quitar"));
153
        btnRemove.setActionCommand("REMOVE");
154
        btnRemove.addActionListener(this);
155
        pnlButtons.add(btnRemove);
156

    
157
        btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels"));
158
        btnOpenSymbolLevelsEditor.addActionListener(this);
159
        btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR");
160
        pnlButtons.add(btnOpenSymbolLevelsEditor);
161
                btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
162

    
163
                pnlCenter = new JPanel();
164
        pnlCenter.setLayout(new BorderLayout());
165

    
166
        cmbFields = new JComboBox();
167
        cmbFields.setActionCommand("FIELD_SELECTED");
168
        cmbFields.addActionListener(this);
169
        cmbFields.setVisible(true);
170

    
171
                JPanel pnlNorth = new JPanel();
172
                pnlNorth.setLayout(new GridLayout(0,2));
173

    
174
                GridBagLayoutPanel auxPanel = new GridBagLayoutPanel();
175
                JLabel lblFieldClassification = new JLabel(PluginServices.getText(
176
                                this, "Campo_de_clasificacion")+": ");
177
                auxPanel.add(lblFieldClassification);
178
                auxPanel.add(cmbFields);
179
                pnlNorth.add(auxPanel);
180

    
181
                auxPanel = new GridBagLayoutPanel();
182
                auxPanel.add(new JLabel(PluginServices.getText(this, "color_scheme")+": "));
183
                cmbColorScheme = new JComboBoxColorScheme(false);
184
                cmbColorScheme.addActionListener(this);
185
                auxPanel.add(cmbColorScheme);
186
                pnlNorth.add(auxPanel);
187

    
188

    
189
                defaultSymbolPanel.add(getChbUseDefault(), null);
190
                pnlNorth.add(defaultSymbolPanel);
191
                pnlNorth.add(new JBlank(0,30));
192

    
193
                this.setLayout(new BorderLayout());
194
                this.add(pnlNorth, BorderLayout.NORTH);
195
                this.add(pnlCenter, BorderLayout.CENTER);
196
                this.add(pnlButtons, BorderLayout.SOUTH);
197

    
198

    
199
    }
200

    
201
    /**
202
     * DOCUMENT ME!
203
     */
204
    private void fillTableValues() {
205
        FeatureStore elRs;
206

    
207
        try {
208
            elRs = ((FLyrVect) layer).getFeatureStore();
209
//            logger.debug("elRs.start()");
210
//            elRs.start();
211

    
212
//            int idField = -1;
213
            String fieldName = (String) cmbFields.getSelectedItem();
214
            if (fieldName==null) {
215
                    JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_hay_campo_seleccionado"));
216
                    return;
217
            }
218

    
219
//            idField = elRs.getFieldIndexByName(fieldName);
220
            auxLegend.setClassifyingFieldNames(new String[] {fieldName});
221

    
222
            //long numReg = elRs.getRowCount();
223
//            if (idField == -1) {
224
//                NotificationManager.addWarning(
225
//                                PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
226
//
227
//                return;
228
//            }
229

    
230
            symbolTable.removeAllItems();
231

    
232
            int numSymbols = 0;
233
            ISymbol theSymbol = null;
234

    
235
            //auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend();
236

    
237
            //            auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
238
            auxLegend = (VectorialUniqueValueLegend) MapContextLocator
239
                                        .getMapContextManager().createLegend(
240
                                                        IVectorialUniqueValueLegend.LEGEND_NAME);
241
            auxLegend.setShapeType(layer.getShapeType());
242

    
243
            Object clave=null;
244

    
245
            //Object resul;
246
            if (chbUseDefault.isSelected()) {
247
                auxLegend.getDefaultSymbol().setDescription("Default");
248
                auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
249
            }
250

    
251
            Color[] colorScheme = cmbColorScheme.getSelectedColors();
252

    
253
            Color[] colors = new Color[colorScheme.length];
254
                        for (int i = 0; i < colorScheme.length; i++) {
255
                                colors[i] = colorScheme[i];
256
                        }
257
                        auxLegend.setColorScheme(colors);
258

    
259
            Random rand = new Random(System.currentTimeMillis());
260

    
261
            FeatureSet set = null;
262
                        DisposableIterator iterator = null;
263

    
264
                        try {
265
                                set = elRs.getFeatureSet();
266

    
267
                                int count = 0;
268

    
269
                                iterator = set.iterator();
270
                                while (iterator.hasNext()) {
271
                                        Feature feature = (Feature) iterator.next();
272
                                        clave = feature.get(fieldName);
273
                                        // }
274
                                        // for (int j = 0; j < elRs.getRowCount(); j++) {
275
                                        // clave = elRs.getFieldValue(j, idField);
276

    
277
//                                        if (clave instanceof NullValue) {
278
//                                                continue;
279
//                                        }
280
                                        if (clave == null) {
281
                                                continue;
282
                                        }
283

    
284
                                        // //Comprobar que no esta repetido y no hace falta
285
                                        // introducir en el hashtable el campo junto con el simbolo.
286
                                        if (auxLegend.getSymbolByValue(clave) == null) {
287

    
288
                                                if (count == 100) {
289
                                                        int resp = JOptionPane.showConfirmDialog(this,
290
                                                                        PluginServices.getText(this,
291
                                                                                        "mas_de_100_simbolos"),
292
                                                                        PluginServices.getText(this,
293
                                                                                        "quiere_continuar"),
294
                                                                        JOptionPane.YES_NO_OPTION,
295
                                                                        JOptionPane.WARNING_MESSAGE);
296

    
297
                                                        if ((resp == JOptionPane.NO_OPTION)
298
                                                                        || (resp == JOptionPane.DEFAULT_OPTION)) {
299
                                                                break;
300
                                                        }
301
                                                }
302

    
303

    
304
                                                // si no esta creado el simbolo se crea
305
                                                // jaume (moved to ISymbol); theSymbol = new
306
                                                // FSymbol(layer.getShapeType());
307
                                                theSymbol =
308
                                                                mapContextManager.getSymbolManager()
309
                                                                                .createSymbol(
310
                                                                                                layer
311
                                                                                .getShapeType(), colorScheme[rand
312
                                                                                .nextInt(colorScheme.length)]);
313
                                                theSymbol.setDescription(clave.toString());
314
                                                auxLegend.addSymbol(clave, theSymbol);
315
                                                count++;
316
                                        }
317

    
318
                                } // for
319
                        }finally{
320
                                if (iterator != null){
321
                                        iterator.dispose();
322
                                }
323
                                if (set != null) {
324
                                        set.dispose();
325
                                }
326
                        }
327

    
328
                        Object[] values = auxLegend.getValues();
329
                        String[] descriptions = new String[values.length];
330
                        ISymbol[] symbols = new ISymbol[values.length];
331
                        
332
                        for (int i = 0; i < values.length; i++) {
333
                                Object value = values[i];
334
                                symbols[i] = auxLegend.getSymbolByValue(value);
335
                                descriptions[i] = symbols[i].getDescription();
336
                        }
337
                        
338
            symbolTable.fillTableFromSymbolList(symbols,
339
                values, descriptions);
340
//            elRs.stop();
341
//            set.dispose();
342
        } catch (DataException e) {
343
                NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
344
        }
345

    
346
        btnRemoveAll.setEnabled(true);
347
        btnRemove.setEnabled(true);
348

    
349
        //m_bCacheDirty = false;
350
    }
351

    
352
        private boolean compareClassifyingFieldNames(String[] a, String[] b){
353
                if (a==b) {
354
                        return true;
355
                }
356
                if (a == null || b == null) {
357
                        return false;
358
                }
359
                if (a.length != b.length) {
360
                        return false;
361
                }
362
                for (int i=0; i<a.length; i++){
363
                        if (!a[i].equals(b[i])) {
364
                                return false;
365
                        }
366
                }
367
                return true;
368
        }
369

    
370
        private boolean compareClassifyingFieldTypes(int[] a, int[] b){
371
                if (a==b) {
372
                        return true;
373
                }
374
                if (a == null || b == null) {
375
                        return false;
376
                }
377
                if (a.length != b.length) {
378
                        return false;
379
                }
380
                for (int i=0; i<a.length; i++){
381
                        if (a[i]!=b[i]) {
382
                                return false;
383
                        }
384
                }
385
                return true;
386
        }
387

    
388
    /**
389
     * A partir de los registros de la tabla, regenera el FRenderer. (No solo
390
     * el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
391
     */
392
    private void fillSymbolListFromTable() {
393
        Object clave=null;
394
        ISymbol theSymbol;
395
                ArrayList visitedKeys = new ArrayList();
396
                boolean changedLegend = false;
397

    
398
            String fieldName = (String) cmbFields.getSelectedItem();
399
                String[] classifyingFieldNames = new String[] {fieldName};
400
                if(auxLegend!=null){
401
                        if(!compareClassifyingFieldNames(classifyingFieldNames,auxLegend.getClassifyingFieldNames())){
402
                                auxLegend.setClassifyingFieldNames(classifyingFieldNames);
403
                                changedLegend = true;
404
                        }
405
                } else {
406
                        auxLegend.setClassifyingFieldNames(classifyingFieldNames);
407
                        changedLegend = true;
408
                }
409

    
410
                FLyrVect m = (FLyrVect) layer;
411

    
412
        try {
413
                int fieldType = m.getFeatureStore().getDefaultFeatureType()
414
                                        .getAttributeDescriptor(cmbFields.getSelectedIndex())
415
                                        .getType();
416
//                int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
417
                        int[] classifyingFieldTypes = new int[] {fieldType};
418
                        if(auxLegend!=null){
419
                                if(!compareClassifyingFieldTypes(classifyingFieldTypes,auxLegend.getClassifyingFieldTypes())){
420
                                        auxLegend.setClassifyingFieldTypes(classifyingFieldTypes);
421
                                        changedLegend = true;
422
                                }
423
                        } else {
424
                                auxLegend.setClassifyingFieldTypes(classifyingFieldTypes);
425
                                changedLegend = true;
426
                        }
427
        } catch (DataException e) {
428
                NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e);
429
        } catch (Exception e) {
430
                        NotificationManager.showMessageWarning(PluginServices.getText(this, "could_not_setup_legend"), e);
431
                }
432

    
433
                if(changedLegend){
434
                        auxLegend.clear();
435
                }
436

    
437
        for (int row = 0; row < symbolTable.getRowCount(); row++) {
438
            clave = symbolTable.getFieldValue(row, 1);
439
            theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
440
                        String description = (String) symbolTable.getFieldValue(row, 2);
441
                        theSymbol.setDescription(description);
442
                        ISymbol legendSymbol = null;
443
                        if (auxLegend != null){
444
                                legendSymbol = auxLegend.getSymbolByValue(clave);
445
                        }
446
                        if( legendSymbol == null || ( auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())){
447
                                if (auxLegend != null){
448
                                        auxLegend.addSymbol(clave, theSymbol);
449
                                }
450
                        } else {
451
                            
452
                            // avoid same instance
453
                            if (legendSymbol != theSymbol) {
454

    
455
                                /*
456
                                 * Perhaps use this "if" when implementations of ISymbol
457
                                 * properly implement the equals method. 
458
                                 */
459
                                // if (!legendSymbol.equals(theSymbol)) {
460
                                    auxLegend.replace(legendSymbol, theSymbol);
461
                                // }
462
                            }
463
                        }
464
                        visitedKeys.add(clave);
465
                }
466
                if(auxLegend != null){
467
                        Object[] keys = auxLegend.getValues();
468
                        for(int i=0; i<keys.length; i++){
469
                                Object key = keys[i];
470
                                if(!visitedKeys.contains(key)){
471
                                        auxLegend.delSymbol(key);
472
                                }
473
                        }
474
                }
475
                clave = null;
476
                if(chbUseDefault.isSelected()){
477
                        theSymbol = defaultSymbolPrev.getSymbol();
478
                        if(theSymbol != null){
479
                                String description = PluginServices.getText(this,"default");
480
                                theSymbol.setDescription(description);
481
                                ISymbol legendSymbol = null;
482
                                if (auxLegend != null){
483
                                        legendSymbol = auxLegend.getSymbolByValue(clave);
484
                                }
485
                                if( legendSymbol == null){
486
                                        auxLegend.addSymbol(clave, theSymbol);
487
                                } else {
488
//                                        if(!legendSymbol.equals(theSymbol)){
489
                                        if(legendSymbol!=theSymbol){
490
                                                auxLegend.replace(legendSymbol, theSymbol);
491
                                        }
492
                                }
493
                        }
494
                } else {
495
                        if (auxLegend != null){
496
                                ISymbol legendSymbol = auxLegend.getSymbolByValue(clave);
497
                                if( legendSymbol != null){
498
                                        auxLegend.replace(legendSymbol, null);
499
                                }
500
                        }
501
                }
502
        }
503

    
504
    /**
505
     * DOCUMENT ME!
506
     */
507
    private void fillFieldNames() {
508
        FeatureStore rs;
509

    
510
        try {
511
            rs = ((FLyrVect) layer).getFeatureStore();
512
//            logger.debug("rs.start()");
513
//            rs.start();
514

    
515
            ArrayList names=new ArrayList();
516
            Iterator iterator=rs.getDefaultFeatureType().iterator();
517
            while (iterator.hasNext()) {
518
                                FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
519
                                names.add(descriptor.getName());
520
                        }
521
//            String[] nomFields = new String[rs.getFieldCount()];
522
//
523
//            for (int i = 0; i < rs.getFieldCount(); i++) {
524
//                nomFields[i] = rs.getFieldName(i).trim();
525
//            }
526
//
527
//            rs.stop();
528

    
529
            DefaultComboBoxModel cM = new DefaultComboBoxModel(names.toArray(new String[0]));
530
            cmbFields.setModel(cM);
531

    
532
            // fieldsListValor.setSelectedIndex(0);
533
        } catch (DataException e) {
534
                NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
535
        }
536
    }
537

    
538
    public void setData(FLayer layer, ILegend legend) {
539
            this.layer = (ClassifiableVectorial) layer;
540
              int shapeType = 0;
541
              try {
542
                      shapeType = this.layer.getShapeType();
543
              } catch (ReadException e) {
544
                    NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e);
545
                }
546

    
547
              getDefaultSymbolPrev(shapeType);
548

    
549
              if (symbolTable != null) {
550
                        pnlCenter.remove(symbolTable);
551
                }
552
              symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType);
553
              pnlCenter.add(symbolTable, BorderLayout.CENTER);
554

    
555
        fillFieldNames();
556

    
557
        symbolTable.removeAllItems();
558

    
559
            if (VectorialUniqueValueLegend.class.equals(legend.getClass())) {
560
                        auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend();
561
                        getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol());
562
                        cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
563
                        setColorScheme();
564
                        
565
                        Object[] values = auxLegend.getValues();
566
                        String[] descriptions = new String[values.length];
567
                        ISymbol[] symbols = new ISymbol[values.length];
568
                        
569
                        for (int i = 0; i < values.length; i++) {
570
                                Object value = values[i];
571
                                symbols[i] = auxLegend.getSymbolByValue(value);
572
                                descriptions[i] = symbols[i].getDescription();
573
                        }
574

    
575
                        symbolTable.fillTableFromSymbolList(symbols,
576
                                        values,descriptions);
577
                        chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol());
578
                } else {
579
                        auxLegend = new VectorialUniqueValueLegend(shapeType);
580
                }
581
                defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
582
                btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
583
    }
584

    
585

    
586
    private void setColorScheme(){
587

    
588
                if(auxLegend.getColorScheme() != null) {
589
                        Color[] colorScheme = auxLegend.getColorScheme();
590
//                        ColorItem[] colors = new ColorItem[auxLegend.getColorScheme().length];
591
//                        for (int i = 0; i < auxLegend.getColorScheme().length; i++) {
592
//                                colors[i] = new ColorItem();
593
//                                colors[i].setColor(auxLegend.getColorScheme()[i]);
594
//                        }
595
                        cmbColorScheme.setSelectedColors(colorScheme);
596
                }
597
        }
598

    
599
    private void getDefaultSymbolPrev(int shapeType) {
600
                if(defaultSymbolPrev == null){
601
                        defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
602
                        defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
603
                        defaultSymbolPrev.addActionListener(this);
604
                        defaultSymbolPanel.add(defaultSymbolPrev,null);
605
                }
606
        }
607

    
608
    /* (non-Javadoc)
609
     * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
610
     */
611
    public ILegend getLegend() {
612
            fillSymbolListFromTable();
613

    
614
            if (auxLegend != null) {
615
                    // your settings that are not the set of symbols must be located here
616
//                  auxLegend.setClassifyingFieldNames(
617
//                  new String[] {(String) cmbFields.getSelectedItem()});
618

    
619
                    ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol();
620
                    ISymbol symbol = defaultSymbolPrev.getSymbol();
621
                    if(symbol != null){
622
                            if(symbol!=defaultSymbolLegend){
623
                                    auxLegend.setDefaultSymbol(symbol);
624
                            }
625
                    }
626

    
627
                    auxLegend.useDefaultSymbol(chbUseDefault.isSelected());
628

    
629
                    theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend();
630
                    theLegend.setZSort(auxLegend.getZSort());
631
            }
632

    
633
            return theLegend;
634
    }
635

    
636
    private JCheckBox getChbUseDefault() {
637
            if (chbUseDefault == null) {
638
                        chbUseDefault = new JCheckBox();
639
                        chbUseDefault.setSelected(false);
640
                        chbUseDefault.addActionListener(new java.awt.event.ActionListener() {
641
                                public void actionPerformed(java.awt.event.ActionEvent e) {
642
                                        if (chbUseDefault.isSelected()) {
643
                                                auxLegend.useDefaultSymbol(true);
644
                                        } else {
645
                                                auxLegend.useDefaultSymbol(false);
646
                                        }
647
                                }
648
                        });
649
                        chbUseDefault.setText(PluginServices.getText(this, "resto_valores")+ ": ");
650
                }
651

    
652
                return chbUseDefault;
653
    }
654

    
655
    /**
656
     * A�ade el resto de valores.
657
     */
658
    private void addDefault() {
659
        auxLegend.getDefaultSymbol().setDescription("Default");
660
        auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
661
        symbolTable.addTableRecord(auxLegend.getDefaultSymbol(),
662
            null, auxLegend.getDefaultSymbol().getDescription());
663
        symbolTable.repaint();
664
    }
665

    
666
    /**
667
     * Elimina el resto de valores que no estan representados por ning�n otro s�mbolo..
668
     */
669
    private void delDefault() {
670
        auxLegend.delSymbol(null);
671
        symbolTable.removeRow(null);
672
        symbolTable.repaint();
673
    }
674

    
675

    
676
    public void actionPerformed(ActionEvent e) {
677

    
678
            //modificar el combobox de valor
679
            if (e.getActionCommand() == "FIELD_SELECTED") {
680
                    JComboBox cb = (JComboBox) e.getSource();
681
                    String fieldName = (String) cb.getSelectedItem();
682
                    symbolTable.removeAllItems();
683
                        btnOpenSymbolLevelsEditor.setEnabled(false);
684

    
685

    
686
//                    if (theLegend.getClassifyingFieldNames()!=null && fieldName != theLegend.getClassifyingFieldNames()[0]) {
687
//                            //m_bCacheDirty = true;
688
//                            theLegend.setClassifyingFieldNames(new String[] {fieldName});
689
//                    }
690
//
691
//                    //////////////////////////////////////////PEPE
692
//                    FLyrVect m = (FLyrVect) layer;
693
//                    try {
694
//                            int fieldType = m.getSource().getRecordset().getFieldType((int)cb.getSelectedIndex());
695
//                            if (theLegend.getClassifyingFieldTypes()!=null && fieldType != theLegend.getClassifyingFieldTypes()[0]) {
696
//                                    //m_bCacheDirty = true;
697
//                                    theLegend.setClassifyingFieldTypes(new int[] {fieldType});
698
//                            }
699
//                    } catch (ReadDriverException e1) {
700
//                            NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e1);
701
//                    }
702
//                    /////////////////////////////////////////PEPE
703
            }
704

    
705
            // add all elements by value
706
            if (e.getActionCommand() == "ADD_ALL_VALUES") {
707
                    fillTableValues();
708
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
709
            }
710

    
711
            // add only one value
712
            if (e.getActionCommand() == "ADD_VALUE") {
713
                    try {
714
                                ISymbol symbol =
715
                                                mapContextManager.getSymbolManager().createSymbol(
716
                                                                layer.getShapeType());
717
                                Double clave = new Double(0.0);
718
                                symbolTable.addTableRecord(symbol,
719
                                                clave,"0 - 0");
720
                                btnOpenSymbolLevelsEditor.setEnabled(true);
721
                    } catch (ReadException ex) {
722
                            NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex);
723
                    }
724
            }
725

    
726
            //Vacia la tabla
727
            if (e.getActionCommand() == "REMOVE_ALL") {
728
                    symbolTable.removeAllItems();
729
                    auxLegend.setZSort(null);
730
                        btnOpenSymbolLevelsEditor.setEnabled(false);
731

    
732
            }
733

    
734
            //Quitar solo el elemento seleccionado
735
            if (e.getActionCommand() == "REMOVE") {
736
                    symbolTable.removeSelectedRows();
737
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount()>0);
738
            }
739

    
740
            if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") {
741
                        ZSort myZSort = null;
742
                        if (auxLegend != null) {
743
                                myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort();
744
                                if(myZSort == null){
745
                                        myZSort = new ZSort(auxLegend);
746
                                }
747
                        }
748
                        if (myZSort == null && theLegend != null) {
749
                                myZSort = new ZSort(theLegend);
750
                        }
751
                        SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
752
                        PluginServices.getMDIManager().addWindow(sl);
753
                        auxLegend.setZSort(sl.getZSort());
754
                }
755
    }
756

    
757
        public String getDescription() {
758
                return PluginServices.getText(this,"Dado_un_campo_de_atributos") + "," + PluginServices.getText(this,"muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico") + ".";
759
        }
760

    
761
        public ImageIcon getIcon() {
762
            return IconThemeHelper.getImageIcon(
763
                "legend-overview-vectorial-unique-value");
764
        }
765

    
766
        public Class getParentClass() {
767
                return Categories.class;
768
        }
769

    
770
        public String getTitle() {
771
                return PluginServices.getText(this,"Valores_unicos");
772
        }
773

    
774
        public JPanel getPanel() {
775
                return this;
776
        }
777

    
778
        public Class getLegendClass() {
779
                return VectorialUniqueValueLegend.class;
780
        }
781

    
782

    
783
        public boolean isSuitableFor(FLayer layer) {
784
                return (layer instanceof FLyrVect);
785
        }
786
}