Statistics
| Revision:

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

History | View | Annotate | Download (21.9 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
                        auxLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol());
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
//                        auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
237

    
238
                        Value clave;
239

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

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

    
248

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

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

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

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

    
268
                                        numSymbols++;
269

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

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

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

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

    
296
                //m_bCacheDirty = false;
297
        }
298

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

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

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

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

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

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

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

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

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

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

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

    
441
                        rs.stop();
442

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

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

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

    
461
                getDefaultSymbolPrev(shapeType);
462

    
463

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

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

    
473
                fillFieldNames();
474

    
475
                symbolTable.removeAllItems();
476

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

    
499

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

    
518
        private void setColorScheme(){
519

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

    
530

    
531

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

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

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

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

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

    
571
                return theLegend;
572
        }
573

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

    
590
                return chbUseDefault;
591
        }
592

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

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

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

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

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

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

    
627
                        
628
                        
629
                }
630

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

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

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

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

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

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

    
688

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

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

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

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

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

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

    
714

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

    
719
}