Statistics
| Revision:

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

History | View | Annotate | Download (21.8 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 = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
219
                        auxLegend.setClassifyingFieldNames(new String[] {fieldName});
220

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

    
226
                                return;
227
                        }
228

    
229
                        symbolTable.removeAllItems();
230

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

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

    
237
                        Value clave;
238

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

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

    
247

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

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

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

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

    
267
                                        numSymbols++;
268

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

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

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

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

    
295
                //m_bCacheDirty = false;
296
        }
297

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

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

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

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

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

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

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

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

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

    
434
                        String[] nomFields = new String[rs.getFieldCount()];
435

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

    
440
                        rs.stop();
441

    
442
                        DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields);
443
                        cmbFields.setModel(cM);
444

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

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

    
460
                getDefaultSymbolPrev(shapeType);
461

    
462

    
463
                if (symbolTable != null)
464
                        pnlCenter.remove(symbolTable);
465
                if(pnlMovBut != null)
466
                        pnlCenter.remove(pnlMovBut);
467

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

    
472
                fillFieldNames();
473

    
474
                symbolTable.removeAllItems();
475

    
476
                if (VectorialUniqueValueLegend.class.equals(legend.getClass())) {
477
                        try {
478
                                auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend();
479
                                //FIXME: Esto es un parche porque la clase ZSort no est? bien hecha
480
                                auxLegend.setZSort(((VectorialUniqueValueLegend) legend).getZSort());
481
                        } catch (XMLException e) {
482
                                // TODO Auto-generated catch block
483
                                e.printStackTrace();
484
                        }
485
                        getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol());
486
                        cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
487
                        setColorScheme();
488
                        symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
489
                                        auxLegend.getValues(),auxLegend.getDescriptions());
490
                        chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol());
491
                } else {
492
                        auxLegend = new VectorialUniqueValueLegend(shapeType);
493
                }
494
                defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
495
                btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
496
        }
497

    
498

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

    
517
        private void setColorScheme(){
518

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

    
529

    
530

    
531
        private void getDefaultSymbolPrev(int shapeType) {
532
                if(defaultSymbolPrev == null){
533
                        defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
534
                        defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
535
                        defaultSymbolPrev.addActionListener(this);
536
                        defaultSymbolPanel.add(defaultSymbolPrev,null);
537
                }
538
        }
539

    
540
        /* (non-Javadoc)
541
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
542
         */
543
        public ILegend getLegend() {
544
                fillSymbolListFromTable();
545

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

    
551
                        ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol();
552
                        ISymbol symbol = defaultSymbolPrev.getSymbol();
553
                        if(symbol != null){
554
                                if(symbol!=defaultSymbolLegend){
555
                                        auxLegend.setDefaultSymbol(symbol);
556
                                }
557
                        }
558
                        auxLegend.useDefaultSymbol(chbUseDefault.isSelected());
559

    
560
                        try {
561
                                theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend();
562
                        } catch (XMLException e) {
563
                                // TODO Auto-generated catch block
564
                                e.printStackTrace();
565
                        }
566
                        //FIXME: Esto es un parche porque la clase ZSort no est? bien hecha
567
                        theLegend.setZSort(auxLegend.getZSort());
568
                }
569

    
570
                return theLegend;
571
        }
572

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

    
589
                return chbUseDefault;
590
        }
591

    
592
        public void actionPerformed(ActionEvent e) {
593
                int[] indices = null;
594

    
595
                if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
596
                        if(!auxLegend.isOwnOrder()){
597
                                auxLegend.setOwnOrder(true);
598
                        }
599
                        indices = symbolTable.getSelectedRows();
600
                }
601

    
602
                if(e.getActionCommand() == "MOVE-UP"){
603
                        if (indices.length>0) {
604
                                int classIndex = indices[0];
605
                                int targetPos = Math.max(0, classIndex-1);
606
                                symbolTable.moveUpRows(classIndex, targetPos,indices.length);
607
                        }
608
                }
609

    
610
                if(e.getActionCommand() == "MOVE-DOWN"){
611
                        if (indices.length>0) {
612
                                int classIndex = indices[indices.length-1];
613
                                int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1);
614
                                symbolTable.moveDownRows(classIndex, targetPos,indices.length);
615
                        }
616
                }
617

    
618
                if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
619
                        ArrayList orders = new ArrayList();
620

    
621
                        for (int i = 0; i < symbolTable.getRowCount(); i++) {
622
                                orders.add(symbolTable.getFieldValue(i,1).toString());
623
                        }
624
                        auxLegend.setOrders(orders);
625

    
626
                        
627
                        
628
                }
629

    
630
                //modificar el combobox de valor
631
                if (e.getActionCommand() == "FIELD_SELECTED") {
632
                        JComboBox cb = (JComboBox) e.getSource();
633
                        String fieldName = (String) cb.getSelectedItem();
634
                        symbolTable.removeAllItems();
635
                        btnOpenSymbolLevelsEditor.setEnabled(false);
636
                }
637

    
638
                // add all elements by value
639
                if (e.getActionCommand() == "ADD_ALL_VALUES") {
640
                        fillTableValues();
641
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0);
642
                }
643

    
644
                // add only one value
645
                if (e.getActionCommand() == "ADD_VALUE") {
646
                        try {
647
                                ISymbol symbol = SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType());
648
                                Value clave = ValueFactory.createValue(0.0);
649
                                symbolTable.addTableRecord(symbol,
650
                                                clave,"0 - 0");
651
                                btnOpenSymbolLevelsEditor.setEnabled(true);
652
                        } catch (ReadDriverException ex) {
653
                                NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex);
654
                        }
655
                }
656

    
657
                //Vacia la tabla
658
                if (e.getActionCommand() == "REMOVE_ALL") {
659
                        symbolTable.removeAllItems();
660
                        auxLegend.setZSort(null);
661
                        btnOpenSymbolLevelsEditor.setEnabled(false);
662
                }
663

    
664
                //Quitar solo el elemento seleccionado
665
                if (e.getActionCommand() == "REMOVE") {
666
                        symbolTable.removeSelectedRows();
667
                        btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount()>0);
668
                }
669

    
670
                if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") {
671
                        ZSort myZSort = null;
672
                        if (auxLegend != null) {
673
                                myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort();
674
                                if(myZSort == null){
675
                                        myZSort = new ZSort(auxLegend);
676
                                }
677
                        }
678
                        if (myZSort == null && theLegend != null) {
679
                                myZSort = new ZSort(theLegend);
680
                        }
681
                        SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
682
                        PluginServices.getMDIManager().addWindow(sl);
683
                        auxLegend.setZSort(sl.getZSort());
684
                }
685
        }
686

    
687

    
688
        public String getDescription() {
689
                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() + ".";
690
        }
691

    
692
        public ImageIcon getIcon() {
693
                return new ImageIcon(this.getClass().getClassLoader().
694
                                getResource("images/ValoresUnicos.png"));
695
        }
696

    
697
        public Class getParentClass() {
698
                return Categories.class;
699
        }
700

    
701
        public String getTitle() {
702
                return PluginServices.getText(this,"Valores_unicos");
703
        }
704

    
705
        public JPanel getPanel() {
706
                return this;
707
        }
708

    
709
        public Class getLegendClass() {
710
                return VectorialUniqueValueLegend.class;
711
        }
712

    
713

    
714
        public boolean isSuitableFor(FLayer layer) {
715
                return (layer instanceof FLyrVect);
716
        }
717

    
718
}