Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / VectorialUniqueValue.java @ 28460

History | View | Annotate | Download (21.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 com.iver.cit.gvsig.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.Random;
52

    
53
import javax.swing.BoxLayout;
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.apache.log4j.Logger;
63
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
64
import org.gvsig.gui.beans.swing.JBlank;
65
import org.gvsig.gui.beans.swing.JButton;
66
import org.gvsig.raster.datastruct.ColorItem;
67

    
68
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
69
import com.hardcode.gdbms.engine.data.DataSource;
70
import com.hardcode.gdbms.engine.values.NullValue;
71
import com.hardcode.gdbms.engine.values.Value;
72
import com.hardcode.gdbms.engine.values.ValueFactory;
73
import com.iver.andami.PluginServices;
74
import com.iver.andami.messages.NotificationManager;
75
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
76
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
77
import com.iver.cit.gvsig.fmap.layers.FLayer;
78
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
79
import com.iver.cit.gvsig.fmap.layers.XMLException;
80
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
81
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
82
import com.iver.cit.gvsig.fmap.rendering.AbstractClassifiedVectorLegend;
83
import com.iver.cit.gvsig.fmap.rendering.ILegend;
84
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
85
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue;
86
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
87
import com.iver.cit.gvsig.fmap.rendering.ZSort;
88
import com.iver.cit.gvsig.gui.styling.JComboBoxColorScheme;
89
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow;
90

    
91

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

    
102
        protected VectorialUniqueValueLegend theLegend;
103
        private ClassifiableVectorial layer;
104
        private SymbolTable symbolTable;
105
        protected JComboBox cmbFields;
106
        private JButton btnRemoveAll;
107
        private JButton btnRemove;
108
        private JButton moveUp;
109
        private JButton moveDown;
110
        private JCheckBox chbUseDefault = null;
111
        private JSymbolPreviewButton defaultSymbolPrev;
112
        private VectorialUniqueValueLegend auxLegend;
113
        private JPanel pnlCenter;
114
        private JPanel pnlMovBut;
115
        private JButton btnOpenSymbolLevelsEditor;
116
        private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
117

    
118
        private JComboBoxColorScheme cmbColorScheme;
119

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

    
128
        /**
129
         * DOCUMENT ME!
130
         */
131
        protected void initComponents() {
132

    
133
                JPanel pnlButtons = new JPanel();
134

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

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

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

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

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

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

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

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

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

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

    
187

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

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

    
197
        }
198

    
199
        /**
200
         * DOCUMENT ME!
201
         */
202
        private void fillTableValues() {
203
                DataSource elRs;
204

    
205
                try {
206
                        elRs = ((FLyrVect) layer).getRecordset();
207
                        logger.debug("elRs.start()");
208
                        elRs.start();
209

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

    
217
                        idField = elRs.getFieldIndexByName(fieldName);
218
                        auxLegend.setClassifyingFieldNames(new String[] {fieldName});
219

    
220
                        //long numReg = elRs.getRowCount();
221
                        if (idField == -1) {
222
                                NotificationManager.addWarning(
223
                                                PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
224

    
225
                                return;
226
                        }
227

    
228
                        symbolTable.removeAllItems();
229

    
230
                        int numSymbols = 0;
231
                        ISymbol theSymbol = null;
232

    
233
                        //auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend();
234
                        auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
235

    
236
                        Value clave;
237

    
238
                        ColorItem[] colorScheme = cmbColorScheme.getSelectedColors();
239

    
240
                        Color[] colors = new Color[colorScheme.length];
241
                        for (int i = 0; i < colorScheme.length; i++) {
242
                                colors[i] = colorScheme[i].getColor();
243
                        }
244
                        auxLegend.setColorScheme(colors);
245

    
246

    
247
                        Random rand = new Random(System.currentTimeMillis());
248

    
249
                        for (int j = 0; j < elRs.getRowCount(); j++) {
250
                                clave = elRs.getFieldValue(j, idField);
251

    
252
                                if (clave instanceof NullValue) {
253
                                        continue;
254
                                }
255

    
256
                                ////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
257
                                if (auxLegend.getSymbolByValue(clave) == null) {
258
                                        //si no esta creado el simbolo se crea
259
                                        // jaume (moved to ISymbol); theSymbol = new FSymbol(layer.getShapeType());
260
                                        theSymbol = SymbologyFactory.
261
                                        createDefaultSymbolByShapeType(layer.getShapeType(),
262
                                                        colorScheme[rand.nextInt(colorScheme.length)].getColor());
263
                                        theSymbol.setDescription(clave.toString());
264
                                        auxLegend.addSymbol(clave, theSymbol);
265

    
266
                                        numSymbols++;
267

    
268
                                        if (numSymbols == 100) {
269
                                                int resp = JOptionPane.showConfirmDialog(this,
270
                                                                PluginServices.getText(this,
271
                                                                "mas_de_100_simbolos"),
272
                                                                PluginServices.getText(this, "quiere_continuar"),
273
                                                                JOptionPane.YES_NO_OPTION,
274
                                                                JOptionPane.WARNING_MESSAGE);
275

    
276
                                                if ((resp == JOptionPane.NO_OPTION) ||
277
                                                                (resp == JOptionPane.DEFAULT_OPTION)) {
278
                                                        return;
279
                                                }
280
                                        }
281
                                }
282
                        } // for
283

    
284
                        symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
285
                                        auxLegend.getValues(),auxLegend.getDescriptions());
286
                        elRs.stop();
287
                } catch (ReadDriverException e) {
288
                        NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
289
                }
290

    
291
                btnRemoveAll.setEnabled(true);
292
                btnRemove.setEnabled(true);
293

    
294
                //m_bCacheDirty = false;
295
        }
296

    
297
        private boolean compareClassifyingFieldNames(String[] a, String[] b){
298
                if (a==b) return true;
299
                if (a == null || b == null) return false;
300
                if (a.length != b.length) return false;
301
                for (int i=0; i<a.length; i++){
302
                        if (!a[i].equals(b[i])) return false;
303
                }
304
                return true;
305
        }
306

    
307
        private boolean compareClassifyingFieldTypes(int[] a, int[] b){
308
                if (a==b) return true;
309
                if (a == null || b == null) return false;
310
                if (a.length != b.length) return false;
311
                for (int i=0; i<a.length; i++){
312
                        if (a[i]!=b[i]) return false;
313
                }
314
                return true;
315
        }
316
        /**
317
         * A partir de los registros de la tabla, regenera el FRenderer. (No solo
318
         * el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
319
         */
320
        private void fillSymbolListFromTable() {
321
                Value clave;
322
                ISymbol theSymbol;
323
                ArrayList<Value> visitedKeys = new ArrayList();
324
                boolean changedLegend = false;
325

    
326
                String fieldName = (String) cmbFields.getSelectedItem();
327
                String[] classifyingFieldNames = new String[] {fieldName};
328
                if(auxLegend!=null){
329
                        if(!compareClassifyingFieldNames(classifyingFieldNames,auxLegend.getClassifyingFieldNames())){
330
                                auxLegend.setClassifyingFieldNames(classifyingFieldNames);
331
                                changedLegend = true;
332
                        }
333
                } else {
334
                        auxLegend.setClassifyingFieldNames(classifyingFieldNames);
335
                        changedLegend = true;
336
                }
337

    
338
                FLyrVect m = (FLyrVect) layer;
339
                try {
340
                        int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
341
                        int[] classifyingFieldTypes = new int[] {fieldType};
342
                        if(auxLegend!=null){
343
                                if(!compareClassifyingFieldTypes(classifyingFieldTypes,auxLegend.getClassifyingFieldTypes())){
344
                                        auxLegend.setClassifyingFieldTypes(classifyingFieldTypes);
345
                                        changedLegend = true;
346
                                }
347
                        } else {
348
                                auxLegend.setClassifyingFieldTypes(classifyingFieldTypes);
349
                                changedLegend = true;
350
                        }
351
                } catch (ReadDriverException e) {
352
                        NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e);
353
                }
354

    
355
                if(changedLegend){
356
                        auxLegend.clear();
357
                }
358

    
359
                for (int row = 0; row < symbolTable.getRowCount(); row++) {
360
                        clave = (Value) symbolTable.getFieldValue(row, 1);
361
                        theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
362
                        String description = (String) symbolTable.getFieldValue(row, 2);
363
                        theSymbol.setDescription(description);
364
                        ISymbol legendSymbol = null;
365
                        if (auxLegend != null){
366
                                legendSymbol = auxLegend.getSymbolByValue(clave);
367
                        }
368
                        if( legendSymbol == null || ( auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())){
369
                                if (auxLegend != null){
370
                                        auxLegend.addSymbol(clave, theSymbol);
371
                                }
372
                        } else {
373
                                /* FIXME: Se optimizar?a descomentarizando el if, pero el metodo equals del AbstractSymbol
374
                                 * no tiene en cuenta determinadas propiedades del simbolo, como, por ejemplo, el tama?o.
375
                                 * Descomentarizar al arreglar el metodo equals del AbstractSymbol.
376
                                 */
377
//                                if(!legendSymbol.equals(theSymbol)){
378
                                        auxLegend.replace(legendSymbol, theSymbol);
379
//                                }
380
                        }
381
                        visitedKeys.add(clave);
382
                }
383
                if(auxLegend != null){
384
                        Object[] keys = auxLegend.getValues();
385
                        for(int i=0; i<keys.length; i++){
386
                                Object key = keys[i];
387
                                if(!visitedKeys.contains(key)){
388
                                        auxLegend.delSymbol(key);
389
                                }
390
                        }
391
                }
392

    
393
                clave = new NullUniqueValue();
394
                if(chbUseDefault.isSelected()){
395
                        if(defaultSymbolPrev.getSymbol() != null){
396
                                String description = PluginServices.getText(this,"default");
397
                                defaultSymbolPrev.getSymbol().setDescription(description);
398
                                ISymbol legendSymbol = null;
399
                                if (auxLegend != null){
400
                                        legendSymbol = auxLegend.getSymbolByValue(clave);
401
                                }
402
                                theSymbol = defaultSymbolPrev.getSymbol();
403
                                if( legendSymbol == null){
404
                                        auxLegend.addSymbol(clave, theSymbol);
405
                                } else {
406
                                        if(!legendSymbol.equals(theSymbol)){
407
                                                auxLegend.replace(legendSymbol, theSymbol);
408
                                        }
409
                                }
410
                        }
411
                } else {
412
                        if (auxLegend != null){
413
                                ISymbol legendSymbol = auxLegend.getSymbolByValue(clave);
414
                                if( legendSymbol != null){
415
                                        auxLegend.replace(legendSymbol, null);
416
                                }
417
                        }
418
                }
419
        }
420

    
421
        /**
422
         * DOCUMENT ME!
423
         */
424
        private void fillFieldNames() {
425
                DataSource rs;
426

    
427
                try {
428
                        rs = ((FLyrVect) layer).getSource().getRecordset();
429
                        logger.debug("rs.start()");
430
                        rs.start();
431

    
432
                        String[] nomFields = new String[rs.getFieldCount()];
433

    
434
                        for (int i = 0; i < rs.getFieldCount(); i++) {
435
                                nomFields[i] = rs.getFieldName(i).trim();
436
                        }
437

    
438
                        rs.stop();
439

    
440
                        DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields);
441
                        cmbFields.setModel(cM);
442

    
443
                        // fieldsListValor.setSelectedIndex(0);
444
                } catch (ReadDriverException e) {
445
                        NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
446
                }
447
        }
448

    
449
        public void setData(FLayer layer, ILegend legend) {
450
                this.layer = (ClassifiableVectorial) layer;
451
                int shapeType = 0;
452
                try {
453
                        shapeType = this.layer.getShapeType();
454
                } catch (ReadDriverException e) {
455
                        NotificationManager.addError(PluginServices.getText(this, "accessing_to_the_layer"), e);
456
                }
457

    
458
                getDefaultSymbolPrev(shapeType);
459

    
460

    
461
                if (symbolTable != null)
462
                        pnlCenter.remove(symbolTable);
463
                if(pnlMovBut != null)
464
                        pnlCenter.remove(pnlMovBut);
465

    
466
                symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType);
467
                pnlCenter.add(symbolTable, BorderLayout.CENTER);
468
                pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
469

    
470
                fillFieldNames();
471

    
472
                symbolTable.removeAllItems();
473

    
474
                if (VectorialUniqueValueLegend.class.equals(legend.getClass())) {
475
                        try {
476
                                auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend();
477
                        } catch (XMLException e) {
478
                                // TODO Auto-generated catch block
479
                                e.printStackTrace();
480
                        }
481
                        getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol());
482
                        cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
483
                        setColorScheme();
484
                        symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
485
                                        auxLegend.getValues(),auxLegend.getDescriptions());
486
                        chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol());
487
                } else {
488
                        auxLegend = new VectorialUniqueValueLegend(shapeType);
489
                }
490
                defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
491
                btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
492
        }
493

    
494

    
495
        private JPanel getPnlMovBut() {
496
                if(pnlMovBut == null){
497
                        pnlMovBut = new JPanel();
498
                        pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS));
499
                        pnlMovBut.add(new JBlank(1, 70));
500
                        pnlMovBut.add(moveUp = new JButton(PluginServices.getIconTheme().get("up-arrow")));
501
                        moveUp.setSize(new Dimension(15,15));
502
                        pnlMovBut.add(new JBlank(1,10));
503
                        pnlMovBut.add(moveDown = new JButton(PluginServices.getIconTheme().get("down-arrow")));
504
                        pnlMovBut.add(new JBlank(1, 70));
505
                        moveDown.setActionCommand("MOVE-DOWN");
506
                        moveUp.setActionCommand("MOVE-UP");
507
                        moveDown.addActionListener(this);
508
                        moveUp.addActionListener(this);
509
                }
510
                return pnlMovBut;
511
        }
512

    
513
        private void setColorScheme(){
514

    
515
                if(auxLegend.getColorScheme() != null) {
516
                        ColorItem[] colors = new ColorItem[auxLegend.getColorScheme().length];
517
                        for (int i = 0; i < auxLegend.getColorScheme().length; i++) {
518
                                colors[i] = new ColorItem();
519
                                colors[i].setColor(auxLegend.getColorScheme()[i]);
520
                        }
521
                        cmbColorScheme.setSelectedColors(colors);
522
                }
523
        }
524

    
525

    
526

    
527
        private void getDefaultSymbolPrev(int shapeType) {
528
                if(defaultSymbolPrev == null){
529
                        defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
530
                        defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
531
                        defaultSymbolPrev.addActionListener(this);
532
                        defaultSymbolPanel.add(defaultSymbolPrev,null);
533
                }
534
        }
535

    
536
        /* (non-Javadoc)
537
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
538
         */
539
        public ILegend getLegend() {
540
                fillSymbolListFromTable();
541

    
542
                if (auxLegend != null) {
543
                        // your settings that are not the set of symbols must be located here
544
//                        auxLegend.setClassifyingFieldNames(
545
//                                        new String[] {(String) cmbFields.getSelectedItem()});
546

    
547
                        ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol();
548
                        ISymbol symbol = defaultSymbolPrev.getSymbol();
549
                        if(symbol != null){
550
                                if(!symbol.equals(defaultSymbolLegend)){
551
                                        auxLegend.setDefaultSymbol(symbol);
552
                                }
553
                        }
554
                        auxLegend.useDefaultSymbol(chbUseDefault.isSelected());
555

    
556
                        try {
557
                                theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend();
558
                        } catch (XMLException e) {
559
                                // TODO Auto-generated catch block
560
                                e.printStackTrace();
561
                        }
562
                        theLegend.setZSort(auxLegend.getZSort());
563
                }
564

    
565
                return theLegend;
566
        }
567

    
568
        private JCheckBox getChbUseDefault() {
569
                if (chbUseDefault == null) {
570
                        chbUseDefault = new JCheckBox();
571
                        chbUseDefault.setSelected(false);
572
                        chbUseDefault.addActionListener(new java.awt.event.ActionListener() {
573
                                public void actionPerformed(java.awt.event.ActionEvent e) {
574
                                        if (chbUseDefault.isSelected()) {
575
                                                auxLegend.useDefaultSymbol(true);
576
                                        } else {
577
                                                auxLegend.useDefaultSymbol(false);
578
                                        }
579
                                }
580
                        });
581
                        chbUseDefault.setText(PluginServices.getText(this, "resto_valores")+ ": ");
582
                }
583

    
584
                return chbUseDefault;
585
        }
586

    
587
        public void actionPerformed(ActionEvent e) {
588
                int[] indices = null;
589

    
590
                if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
591
                        if(!auxLegend.isOwnOrder()){
592
                                auxLegend.setOwnOrder(true);
593
                        }
594
                        indices = symbolTable.getSelectedRows();
595
                }
596

    
597
                if(e.getActionCommand() == "MOVE-UP"){
598
                        if (indices.length>0) {
599
                                int classIndex = indices[0];
600
                                int targetPos = Math.max(0, classIndex-1);
601
                                symbolTable.moveUpRows(classIndex, targetPos,indices.length);
602
                        }
603
                }
604

    
605
                if(e.getActionCommand() == "MOVE-DOWN"){
606
                        if (indices.length>0) {
607
                                int classIndex = indices[indices.length-1];
608
                                int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1);
609
                                symbolTable.moveDownRows(classIndex, targetPos,indices.length);
610
                        }
611
                }
612

    
613
                if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
614
                        ArrayList orders = new ArrayList();
615

    
616
                        for (int i = 0; i < symbolTable.getRowCount(); i++) {
617
                                orders.add(symbolTable.getFieldValue(i,1).toString());
618
                        }
619
                        auxLegend.setOrders(orders);
620
                }
621

    
622
                //modificar el combobox de valor
623
                if (e.getActionCommand() == "FIELD_SELECTED") {
624
                        JComboBox cb = (JComboBox) e.getSource();
625
                        String fieldName = (String) cb.getSelectedItem();
626
                        symbolTable.removeAllItems();
627
                        btnOpenSymbolLevelsEditor.setEnabled(false);
628
                }
629

    
630
                // add all elements by value
631
                if (e.getActionCommand() == "ADD_ALL_VALUES") {
632
                        fillTableValues();
633
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
634
                }
635

    
636
                // add only one value
637
                if (e.getActionCommand() == "ADD_VALUE") {
638
                        try {
639
                                ISymbol symbol = SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType());
640
                                Value clave = ValueFactory.createValue(0.0);
641
                                symbolTable.addTableRecord(symbol,
642
                                                clave,"0 - 0");
643
                                btnOpenSymbolLevelsEditor.setEnabled(true);
644
                        } catch (ReadDriverException ex) {
645
                                NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex);
646
                        }
647
                }
648

    
649
                //Vacia la tabla
650
                if (e.getActionCommand() == "REMOVE_ALL") {
651
                        symbolTable.removeAllItems();
652
                        auxLegend.setZSort(null);
653
                        btnOpenSymbolLevelsEditor.setEnabled(false);
654
                }
655

    
656
                //Quitar solo el elemento seleccionado
657
                if (e.getActionCommand() == "REMOVE") {
658
                        symbolTable.removeSelectedRows();
659
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount()>0);
660
                }
661

    
662
                if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") {
663
                        ZSort myZSort = null;
664
                        if (auxLegend != null) {
665
                                myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort();
666
                                if(myZSort == null){
667
                                        myZSort = new ZSort(auxLegend);
668
                                }
669
                        }
670
                        if (myZSort == null && theLegend != null) {
671
                                myZSort = new ZSort(theLegend);
672
                        }
673
                        SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
674
                        PluginServices.getMDIManager().addWindow(sl);
675
                        auxLegend.setZSort(sl.getZSort());
676
                }
677
        }
678

    
679

    
680
        public String getDescription() {
681
                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").toLowerCase() + ".";
682
        }
683

    
684
        public ImageIcon getIcon() {
685
                return new ImageIcon(this.getClass().getClassLoader().
686
                                getResource("images/ValoresUnicos.png"));
687
        }
688

    
689
        public Class getParentClass() {
690
                return Categories.class;
691
        }
692

    
693
        public String getTitle() {
694
                return PluginServices.getText(this,"Valores_unicos");
695
        }
696

    
697
        public JPanel getPanel() {
698
                return this;
699
        }
700

    
701
        public Class getLegendClass() {
702
                return VectorialUniqueValueLegend.class;
703
        }
704

    
705

    
706
        public boolean isSuitableFor(FLayer layer) {
707
                return (layer instanceof FLyrVect);
708
        }
709

    
710
}