Statistics
| Revision:

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

History | View | Annotate | Download (24.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.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
                                /* FIXME: Se optimizar?a descomentarizando el if, pero el metodo equals del AbstractSymbol
452
                                 * no tiene en cuenta determinadas propiedades del simbolo, como, por ejemplo, el tama?o.
453
                                 * Descomentarizar al arreglar el metodo equals del AbstractSymbol.
454
                                 */
455
//                                if(!legendSymbol.equals(theSymbol)){
456
                                        auxLegend.replace(legendSymbol, theSymbol);
457
//                                }
458
                        }
459
                        visitedKeys.add(clave);
460
                }
461
                if(auxLegend != null){
462
                        Object[] keys = auxLegend.getValues();
463
                        for(int i=0; i<keys.length; i++){
464
                                Object key = keys[i];
465
                                if(!visitedKeys.contains(key)){
466
                                        auxLegend.delSymbol(key);
467
                                }
468
                        }
469
                }
470
                clave = null;
471
                if(chbUseDefault.isSelected()){
472
                        theSymbol = defaultSymbolPrev.getSymbol();
473
                        if(theSymbol != null){
474
                                String description = PluginServices.getText(this,"default");
475
                                theSymbol.setDescription(description);
476
                                ISymbol legendSymbol = null;
477
                                if (auxLegend != null){
478
                                        legendSymbol = auxLegend.getSymbolByValue(clave);
479
                                }
480
                                if( legendSymbol == null){
481
                                        auxLegend.addSymbol(clave, theSymbol);
482
                                } else {
483
//                                        if(!legendSymbol.equals(theSymbol)){
484
                                        if(legendSymbol!=theSymbol){
485
                                                auxLegend.replace(legendSymbol, theSymbol);
486
                                        }
487
                                }
488
                        }
489
                } else {
490
                        if (auxLegend != null){
491
                                ISymbol legendSymbol = auxLegend.getSymbolByValue(clave);
492
                                if( legendSymbol != null){
493
                                        auxLegend.replace(legendSymbol, null);
494
                                }
495
                        }
496
                }
497
        }
498

    
499
    /**
500
     * DOCUMENT ME!
501
     */
502
    private void fillFieldNames() {
503
        FeatureStore rs;
504

    
505
        try {
506
            rs = ((FLyrVect) layer).getFeatureStore();
507
//            logger.debug("rs.start()");
508
//            rs.start();
509

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

    
524
            DefaultComboBoxModel cM = new DefaultComboBoxModel(names.toArray(new String[0]));
525
            cmbFields.setModel(cM);
526

    
527
            // fieldsListValor.setSelectedIndex(0);
528
        } catch (DataException e) {
529
                NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
530
        }
531
    }
532

    
533
    public void setData(FLayer layer, ILegend legend) {
534
            this.layer = (ClassifiableVectorial) layer;
535
              int shapeType = 0;
536
              try {
537
                      shapeType = this.layer.getShapeType();
538
              } catch (ReadException e) {
539
                    NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e);
540
                }
541

    
542
              getDefaultSymbolPrev(shapeType);
543

    
544
              if (symbolTable != null) {
545
                        pnlCenter.remove(symbolTable);
546
                }
547
              symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType);
548
              pnlCenter.add(symbolTable, BorderLayout.CENTER);
549

    
550
        fillFieldNames();
551

    
552
        symbolTable.removeAllItems();
553

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

    
570
                        symbolTable.fillTableFromSymbolList(symbols,
571
                                        values,descriptions);
572
                        chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol());
573
                } else {
574
                        auxLegend = new VectorialUniqueValueLegend(shapeType);
575
                }
576
                defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
577
                btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
578
    }
579

    
580

    
581
    private void setColorScheme(){
582

    
583
                if(auxLegend.getColorScheme() != null) {
584
                        Color[] colorScheme = auxLegend.getColorScheme();
585
//                        ColorItem[] colors = new ColorItem[auxLegend.getColorScheme().length];
586
//                        for (int i = 0; i < auxLegend.getColorScheme().length; i++) {
587
//                                colors[i] = new ColorItem();
588
//                                colors[i].setColor(auxLegend.getColorScheme()[i]);
589
//                        }
590
                        cmbColorScheme.setSelectedColors(colorScheme);
591
                }
592
        }
593

    
594
    private void getDefaultSymbolPrev(int shapeType) {
595
                if(defaultSymbolPrev == null){
596
                        defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
597
                        defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
598
                        defaultSymbolPrev.addActionListener(this);
599
                        defaultSymbolPanel.add(defaultSymbolPrev,null);
600
                }
601
        }
602

    
603
    /* (non-Javadoc)
604
     * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
605
     */
606
    public ILegend getLegend() {
607
            fillSymbolListFromTable();
608

    
609
            if (auxLegend != null) {
610
                    // your settings that are not the set of symbols must be located here
611
//                  auxLegend.setClassifyingFieldNames(
612
//                  new String[] {(String) cmbFields.getSelectedItem()});
613

    
614
                    ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol();
615
                    ISymbol symbol = defaultSymbolPrev.getSymbol();
616
                    if(symbol != null){
617
                            if(symbol!=defaultSymbolLegend){
618
                                    auxLegend.setDefaultSymbol(symbol);
619
                            }
620
                    }
621

    
622
                    auxLegend.useDefaultSymbol(chbUseDefault.isSelected());
623

    
624
                    theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend();
625
                    theLegend.setZSort(auxLegend.getZSort());
626
            }
627

    
628
            return theLegend;
629
    }
630

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

    
647
                return chbUseDefault;
648
    }
649

    
650
    /**
651
     * A?ade el resto de valores.
652
     */
653
    private void addDefault() {
654
        auxLegend.getDefaultSymbol().setDescription("Default");
655
        auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
656
        symbolTable.addTableRecord(auxLegend.getDefaultSymbol(),
657
            null, auxLegend.getDefaultSymbol().getDescription());
658
        symbolTable.repaint();
659
    }
660

    
661
    /**
662
     * Elimina el resto de valores que no estan representados por ning?n otro s?mbolo..
663
     */
664
    private void delDefault() {
665
        auxLegend.delSymbol(null);
666
        symbolTable.removeRow(null);
667
        symbolTable.repaint();
668
    }
669

    
670

    
671
    public void actionPerformed(ActionEvent e) {
672

    
673
            //modificar el combobox de valor
674
            if (e.getActionCommand() == "FIELD_SELECTED") {
675
                    JComboBox cb = (JComboBox) e.getSource();
676
                    String fieldName = (String) cb.getSelectedItem();
677
                    symbolTable.removeAllItems();
678
                        btnOpenSymbolLevelsEditor.setEnabled(false);
679

    
680

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

    
700
            // add all elements by value
701
            if (e.getActionCommand() == "ADD_ALL_VALUES") {
702
                    fillTableValues();
703
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
704
            }
705

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

    
721
            //Vacia la tabla
722
            if (e.getActionCommand() == "REMOVE_ALL") {
723
                    symbolTable.removeAllItems();
724
                    auxLegend.setZSort(null);
725
                        btnOpenSymbolLevelsEditor.setEnabled(false);
726

    
727
            }
728

    
729
            //Quitar solo el elemento seleccionado
730
            if (e.getActionCommand() == "REMOVE") {
731
                    symbolTable.removeSelectedRows();
732
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount()>0);
733
            }
734

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

    
752
        public String getDescription() {
753
                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") + ".";
754
        }
755

    
756
        public ImageIcon getIcon() {
757
            return IconThemeHelper.getImageIcon(
758
                "legend-overview-vectorial-unique-value");
759
        }
760

    
761
        public Class getParentClass() {
762
                return Categories.class;
763
        }
764

    
765
        public String getTitle() {
766
                return PluginServices.getText(this,"Valores_unicos");
767
        }
768

    
769
        public JPanel getPanel() {
770
                return this;
771
        }
772

    
773
        public Class getLegendClass() {
774
                return VectorialUniqueValueLegend.class;
775
        }
776

    
777

    
778
        public boolean isSuitableFor(FLayer layer) {
779
                return (layer instanceof FLyrVect);
780
        }
781
}