Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / VectorialInterval.java @ 29812

History | View | Annotate | Download (27.1 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.app.project.documents.view.legend.gui;
42

    
43
import java.awt.*;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.text.NumberFormat;
47
import java.util.ArrayList;
48
import java.util.Iterator;
49

    
50
import javax.swing.*;
51

    
52
import org.gvsig.andami.PluginServices;
53
import org.gvsig.andami.messages.NotificationManager;
54
import org.gvsig.app.gui.panels.ColorChooserPanel;
55
import org.gvsig.fmap.dal.DataTypes;
56
import org.gvsig.fmap.dal.exception.DataException;
57
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
58
import org.gvsig.fmap.dal.feature.FeatureStore;
59
import org.gvsig.fmap.dal.feature.FeatureType;
60
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
61
import org.gvsig.fmap.mapcontext.layers.FLayer;
62
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
63
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
64
import org.gvsig.fmap.mapcontext.rendering.legend.*;
65
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
66
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
67
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
68
import org.gvsig.gui.beans.swing.JButton;
69
import org.gvsig.utils.XMLException;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

    
73

    
74

    
75
/**
76
 * DOCUMENT ME!
77
 *
78
 * @author Vicente Caballero Navarro
79
 */
80
public class VectorialInterval extends JPanel implements ILegendPanel{
81
    private static final Logger logger = LoggerFactory
82
            .getLogger(VectorialInterval.class);
83
    private GridBagLayoutPanel pnlGeneral = null;
84
    protected JComboBox cmbField = null;
85
    protected JTextField txtNumIntervals = null;
86
    private ColorChooserPanel colorChooserPanel = null;
87
    private ColorChooserPanel colorChooserPanel1 = null;
88
    protected JCheckBox chkdefaultvalues = null;
89
    protected JComboBox cmbFieldType = null;
90
    private JPanel panelS = null;
91
    private JButton bintervals = null;
92
    private JButton bInsert = null;
93
    protected JButton bDelAll = null;
94
    protected JButton bDel = null;
95
    private int count = 0;
96
    protected ClassifiableVectorial layer;
97
    protected VectorialIntervalLegend theLegend;
98
    protected VectorialIntervalLegend auxLegend = null;
99
    protected SymbolTable symbolTable;
100
    private MyListener listener = new MyListener();
101
    protected JPanel pnlCenter = null;
102
    protected JPanel optionPanel;
103
    private JPanel pnlNorth;
104
        protected JSymbolPreviewButton defaultSymbolPrev;
105
        private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
106

    
107
    /**
108
     * This is the default constructor
109
     */
110
    public VectorialInterval() {
111
        super();
112
        initialize();
113
    }
114

    
115
    /**
116
     * This method initializes this
117
     */
118
    private void initialize() {
119
        this.setLayout(new BorderLayout());
120
        this.setSize(700, 350);
121
        this.add(getPnlNorth(), BorderLayout.NORTH);
122

    
123
        this.add(getPnlButtons(), BorderLayout.SOUTH);
124
        this.add(getPnlCenter(), BorderLayout.CENTER);
125
        setOptionPanel(getOptionPanel());
126
    }
127

    
128
    private JPanel getPnlNorth() {
129
        if (pnlNorth == null) {
130
            pnlNorth = new JPanel(new GridLayout(1, 2));
131
            pnlNorth.add(getGeneralPanel());
132
        }
133
        return pnlNorth;
134
    }
135

    
136
    /**
137
     * This method initializes panelN
138
     *
139
     * @return javax.swing.JPanel
140
     */
141
    private JPanel getGeneralPanel() {
142
        if (pnlGeneral == null) {
143
            pnlGeneral = new GridBagLayoutPanel();
144
            pnlGeneral.setBorder(BorderFactory.
145
                    createTitledBorder(null,
146
                            PluginServices.getText(this, "fields")));
147
            pnlGeneral.addComponent(PluginServices.getText(this, "Campo_de_clasificacion"),
148
                    getCmbFields());
149
            pnlGeneral.addComponent(PluginServices.getText(this, "tipo_de_intervalo"),
150
                    getCmbIntervalTypes());
151

    
152
            JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
153
            aux.add(getTxtNumIntervals());
154
            pnlGeneral.addComponent(PluginServices.getText(this, "No_de_intervalos"),
155
                    aux);
156
            defaultSymbolPanel.add(getChkDefaultvalues(), null);
157
                        pnlGeneral.addComponent(defaultSymbolPanel);
158
        }
159
        return pnlGeneral;
160
    }
161

    
162
    public JPanel getOptionPanel() {
163
        if (optionPanel == null) {
164
            optionPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
165
            optionPanel.setBorder(BorderFactory.
166
                    createTitledBorder(null,
167
                            PluginServices.getText(this, "color_ramp")));
168

    
169
            GridBagLayoutPanel aux = new GridBagLayoutPanel();
170
            aux.addComponent(PluginServices.getText(this, "Color_final"),
171
                    getColorChooserPanel());
172
            aux.addComponent(PluginServices.getText(this, "Color_inicio"),
173
                    getColorChooserPanel1());
174
            optionPanel.add(aux);
175
        }
176
        return optionPanel;
177
    }
178

    
179
    private void setOptionPanel(JPanel p) {
180
        getPnlNorth().remove(getOptionPanel());
181
        getPnlNorth().add(p, BorderLayout.NORTH);
182
    }
183
    /**
184
     * This method initializes jComboBox
185
     *
186
     * @return javax.swing.JComboBox
187
     */
188
    private JComboBox getCmbFields() {
189
        if (cmbField == null) {
190
            cmbField = new JComboBox();
191
            cmbField.setActionCommand("FIELD_SELECTED");
192
            cmbField.addActionListener(listener);
193
            cmbField.setVisible(true);
194
        }
195

    
196
        return cmbField;
197
    }
198

    
199
    /**
200
     * This method initializes txtNumIntervals
201
     *
202
     * @return javax.swing.JTextField
203
     */
204
    private JTextField getTxtNumIntervals() {
205
        if (txtNumIntervals == null) {
206
            txtNumIntervals = new JTextField(5);
207
            txtNumIntervals.setText("5");
208
        }
209

    
210
        return txtNumIntervals;
211
    }
212

    
213
    /**
214
     * This method initializes colorChooserPanel
215
     *
216
     * @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel
217
     */
218
    private ColorChooserPanel getColorChooserPanel() {
219
        if (colorChooserPanel == null) {
220
            colorChooserPanel = new ColorChooserPanel();
221
            colorChooserPanel.setBounds(new java.awt.Rectangle(108, 49, 54, 20));
222
            colorChooserPanel.setAlpha(255);
223
            colorChooserPanel.setColor(Color.red);
224
        }
225

    
226
        return colorChooserPanel;
227
    }
228

    
229
    /**
230
     * This method initializes colorChooserPanel1
231
     *
232
     * @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel
233
     */
234
    private ColorChooserPanel getColorChooserPanel1() {
235
        if (colorChooserPanel1 == null) {
236
            colorChooserPanel1 = new ColorChooserPanel();
237
            colorChooserPanel1.setBounds(new java.awt.Rectangle(251, 49, 54, 20));
238
            colorChooserPanel1.setAlpha(255);
239
            colorChooserPanel1.setColor(Color.blue);
240
        }
241

    
242
        return colorChooserPanel1;
243
    }
244

    
245
    /**
246
     * This method initializes chkdefaultvalues
247
     *
248
     * @return javax.swing.JCheckBox
249
     */
250
    protected JCheckBox getChkDefaultvalues() {
251
                if (chkdefaultvalues == null) {
252
                        chkdefaultvalues = new JCheckBox();
253
                        chkdefaultvalues.setText(PluginServices.getText(this,
254
                        "resto_valores")+": ");
255
                        chkdefaultvalues.setBounds(new java.awt.Rectangle(342, 26, 141, 20));
256
                        chkdefaultvalues.setSelected(false);
257
                        chkdefaultvalues.addActionListener(new java.awt.event.ActionListener() {
258
                                public void actionPerformed(java.awt.event.ActionEvent e) {
259
                                        if (chkdefaultvalues.isSelected()) {
260
                                                auxLegend.useDefaultSymbol(true);
261
                                        } else {
262
                                                auxLegend.useDefaultSymbol(false);
263
                                        }
264
                                }
265
                        });
266
                }
267

    
268
                return chkdefaultvalues;
269
        }
270

    
271
    /**
272
     * This method initializes jComboBox1
273
     *
274
     * @return javax.swing.JComboBox
275
     */
276
    private JComboBox getCmbIntervalTypes() {
277
        if (cmbFieldType == null) {
278
            cmbFieldType = new JComboBox();
279
            cmbFieldType.setActionCommand("INTERVAL_TYPE");
280
            cmbFieldType.addActionListener(listener);
281
            cmbFieldType.addItem(PluginServices.getText(this, "equal_intervals"));
282
            cmbFieldType.addItem(PluginServices.getText(this,
283
                    "natural_intervals"));
284
            cmbFieldType.addItem(PluginServices.getText(this,
285
                    "quantile_intervals"));
286
            cmbFieldType.setVisible(true);
287
        }
288

    
289
        return cmbFieldType;
290
    }
291

    
292
    /**
293
     * This method initializes panelS
294
     *
295
     * @return javax.swing.JPanel
296
     */
297
    protected JPanel getPnlButtons() {
298
        if (panelS == null) {
299
            panelS = new JPanel();
300
            panelS.setPreferredSize(new java.awt.Dimension(417, 32));
301
            panelS.add(getBintervals(), null);
302
            panelS.add(getBInsert(), null);
303
            panelS.add(getBDelAll(), null);
304
            panelS.add(getBDel(), null);
305
        }
306

    
307
        return panelS;
308
    }
309

    
310
    /**
311
     * This method initializes bintervals
312
     *
313
     * @return javax.swing.JButton
314
     */
315
    private JButton getBintervals() {
316
        if (bintervals == null) {
317
            bintervals = new JButton();
318
            bintervals.setActionCommand("ADD_ALL_VALUES");
319
            bintervals.addActionListener(listener);
320
            bintervals.setText(PluginServices.getText(this,
321
                    "Calcular_intervalos"));
322
        }
323

    
324
        return bintervals;
325
    }
326

    
327
    /**
328
     * This method initializes bInsert
329
     *
330
     * @return javax.swing.JButton
331
     */
332
    private JButton getBInsert() {
333
        if (bInsert == null) {
334
            bInsert = new JButton();
335
            bInsert.setActionCommand("ADD_VALUE");
336
            bInsert.addActionListener(listener);
337
            bInsert.setText(PluginServices.getText(this, "Anadir"));
338
        }
339

    
340
        return bInsert;
341
    }
342

    
343
    /**
344
     * This method initializes bDelAll
345
     *
346
     * @return javax.swing.JButton
347
     */
348
    private JButton getBDelAll() {
349
        if (bDelAll == null) {
350
            bDelAll = new JButton();
351
            bDelAll.setActionCommand("REMOVE_ALL");
352
            bDelAll.addActionListener(listener);
353
            bDelAll.setText(PluginServices.getText(this, "Quitar_todos"));
354
        }
355

    
356
        return bDelAll;
357
    }
358

    
359
    /**
360
     * This method initializes bDel
361
     *
362
     * @return javax.swing.JButton
363
     */
364
    private JButton getBDel() {
365
        if (bDel == null) {
366
            bDel = new JButton();
367
            bDel.setText(PluginServices.getText(this, "Quitar"));
368
            bDel.setActionCommand("REMOVE");
369
            bDel.addActionListener(listener);
370
        }
371

    
372
        return bDel;
373
    }
374

    
375

    
376
    /**
377
     * Damos una primera pasada para saber los l�mites inferior y superior y
378
     * rellenar un array con los valores. Luego dividimos ese array en
379
     * intervalos.
380
     */
381
    protected void fillTableValues() {
382

    
383
        symbolTable.removeAllItems();
384

    
385
        try {
386
            FInterval[] arrayIntervalos = calculateIntervals();
387
            if (arrayIntervalos == null) {
388
                                return;
389
                        }
390

    
391
            FInterval interval;
392
            NumberFormat.getInstance().setMaximumFractionDigits(2);
393
            //theLegend.clear();
394
            auxLegend.clear();
395

    
396
            int r;
397
            int g;
398
            int b;
399
            int stepR;
400
            int stepG;
401
            int stepB;
402

    
403
            // Cogemos el tipo de gradaci�n de colores que quiere el usuario y
404
            // Creamos el primer y �ltimo color.
405
            Color startColor = colorChooserPanel.getColor();
406

    
407
            Color endColor = colorChooserPanel1.getColor();
408

    
409
            r = startColor.getRed();
410
            g = startColor.getGreen();
411
            b = startColor.getBlue();
412
            stepR = (endColor.getRed() - r) / arrayIntervalos.length;
413
            stepG = (endColor.getGreen() - g) / arrayIntervalos.length;
414
            stepB = (endColor.getBlue() - b) / arrayIntervalos.length;
415

    
416
            auxLegend = LegendFactory.createVectorialIntervalLegend(layer.getShapeType());
417
            auxLegend.useDefaultSymbol(false);
418
            auxLegend.setStartColor(startColor);
419
            auxLegend.setEndColor(endColor);
420

    
421
            int symbolType = layer.getShapeType();
422
            int numSymbols = 0;
423

    
424
            for (int k = 0; k < arrayIntervalos.length; k++) {
425
                interval = arrayIntervalos[k];
426

    
427
                ISymbol theSymbol = SymbologyFactory.createDefaultSymbolByShapeType(
428
                                symbolType,
429
                                new Color(r, g, b));
430
                theSymbol.setDescription(NumberFormat.getInstance().format(interval.getMin()) +
431
                    " - " +
432
                    NumberFormat.getInstance().format(interval.getMax()));
433

    
434
                //////////////////////////////////////
435
                // CALCULAMOS UN COLOR APROPIADO
436
                r = r + stepR;
437
                g = g + stepG;
438
                b = b + stepB;
439

    
440
                /////////////////////////////////
441
                auxLegend.addSymbol(interval, theSymbol);
442
                System.out.println("addSymbol = " + interval +
443
                    " theSymbol = " + theSymbol.getDescription());
444
                numSymbols++;
445

    
446
                if (numSymbols > 100) {
447
                    int resp = JOptionPane.showConfirmDialog(this,
448
                            PluginServices.getText(this, "mas_de_100_simbolos"),
449
                            PluginServices.getText(this, "quiere_continuar"),
450
                            JOptionPane.YES_NO_OPTION,
451
                            JOptionPane.WARNING_MESSAGE);
452

    
453
                    if ((resp == JOptionPane.NO_OPTION) ||
454
                            (resp == JOptionPane.DEFAULT_OPTION)) {
455
                        return;
456
                    }
457
                }
458

    
459
                // }
460
            } // for
461

    
462
            System.out.println("Num. Simbolos = " +
463
                auxLegend.getValues().length);
464
            symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
465
                auxLegend.getValues(), auxLegend.getDescriptions());
466

    
467
        } catch (DataException e) {
468
                NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e);
469
        } catch (LegendLayerException e) {
470
                NotificationManager.addError(PluginServices.getText(this, "failed_computing_intervals"), e);
471
                }
472

    
473
        bDelAll.setEnabled(true);
474
        bDel.setEnabled(true);
475
    }
476

    
477
    protected FInterval[] calculateIntervals() throws LegendLayerException {
478
            int intervalCount = 1;
479
            // ensure the interval value is an integer greather than 0
480
            try {
481
                    intervalCount = (int) Double.
482
                                    parseDouble(txtNumIntervals.getText());
483
                    if (intervalCount<1) {
484
                            throw new Exception();
485
                    }
486
            } catch (Exception e) {
487
                    JOptionPane.showMessageDialog(this,
488
                                    PluginServices.getText(this, "invalid_interval_count_value"));
489
                    return null;
490
            }
491

    
492
            try {
493

    
494
                    return auxLegend.calculateIntervals(
495
                    //return theLegend.calculateIntervals(
496
                                    ((FLyrVect) layer).getFeatureStore(),
497
                                    (String) cmbField.getSelectedItem(),
498
                                    intervalCount,
499
                                    layer.getShapeType()
500
                                    );
501
            } catch (DataException e) {
502
                    return null;
503
            }
504
    }
505

    
506
    public void setData(FLayer layer, ILegend legend) {
507
        this.layer = (ClassifiableVectorial) layer;
508
            int shapeType = 0;
509
            try {
510
                    shapeType = this.layer.getShapeType();
511
            } catch (DataException e) {
512
                    NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e);
513
            }
514

    
515
            if (symbolTable != null) {
516
                        pnlCenter.remove(symbolTable);
517
                }
518

    
519
            getDefaultSymbolPrev(shapeType);
520

    
521
            symbolTable = new SymbolTable(this, SymbolTable.INTERVALS_TYPE, shapeType);
522
            pnlCenter.add(symbolTable);
523
        fillFieldNames();
524

    
525
/*        if (legend instanceof VectorialIntervalLegend) {
526
            theLegend = (VectorialIntervalLegend) legend;
527
            getChkDefaultvalues().setSelected(theLegend.isUseDefaultSymbol());
528
            cmbField.getModel().setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
529
            symbolTable.fillTableFromSymbolList(theLegend.getSymbols(),
530
                theLegend.getValues(), theLegend.getDescriptions());
531
            colorChooserPanel.setColor(theLegend.getStartColor());
532
            colorChooserPanel1.setColor(theLegend.getEndColor());
533
            colorChooserPanel.repaint();
534
            colorChooserPanel1.repaint();
535
        } else {
536
                        // Si la capa viene con otro tipo de leyenda, creamos
537
                        // una nueva del tipo que maneja este panel
538
                        theLegend = new VectorialIntervalLegend();
539
                        theLegend.setShapeType(shapeType);
540
        }
541

542

543
        cmbFieldType.setSelectedIndex(theLegend.getIntervalType());
544
*/
545
                if (VectorialIntervalLegend.class.equals(legend.getClass())) {
546
                        try {
547
                                auxLegend = (VectorialIntervalLegend) legend.cloneLegend();
548
                        } catch (XMLException e) {
549
                                NotificationManager.addError(e);
550
                        }
551
                        chkdefaultvalues.setSelected(auxLegend.isUseDefaultSymbol());
552
                        cmbField.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
553
                        symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(),
554
                                        auxLegend.getValues(), auxLegend.getDescriptions());
555
                        colorChooserPanel.setColor(auxLegend.getStartColor());
556
                        colorChooserPanel1.setColor(auxLegend.getEndColor());
557
                        colorChooserPanel.repaint();
558
                        colorChooserPanel1.repaint();
559
                        if(auxLegend.isUseDefaultSymbol()) {
560
                                txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length - 1));
561
                        } else {
562
                                txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length));
563
                        }
564
                } else {
565
                        // Si la capa viene con otro tipo de leyenda, creamos
566
                        // una nueva del tipo que maneja este panel
567
                        auxLegend = new VectorialIntervalLegend();
568
                        auxLegend.setShapeType(shapeType);
569
                        auxLegend.useDefaultSymbol(false);
570
                }
571
                defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
572
                cmbFieldType.setSelectedIndex(auxLegend.getIntervalType());
573
    }
574

    
575

    
576
        public void getDefaultSymbolPrev(int shapeType) {
577
                if(defaultSymbolPrev == null){
578
                defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
579
                defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
580
                defaultSymbolPanel.add(defaultSymbolPrev,null);
581
                }
582
        }
583

    
584
    protected void fillFieldNames() {
585
        FeatureStore rs = null;
586
        ArrayList<String> nomFields = null;
587

    
588
        try {
589
            rs = ((FLyrVect) layer).getFeatureStore();
590
//            logger.debug("rs.start()");
591
//            rs.start();
592

    
593
            nomFields = new ArrayList<String>();
594

    
595
            int type;
596
            Iterator<FeatureAttributeDescriptor> iterator=rs.getDefaultFeatureType().iterator();
597
            while (iterator.hasNext()) {
598
                                FeatureAttributeDescriptor descriptor = iterator.next();
599

    
600
//                        }
601
//            for (int i = 0; i < rs.getFieldCount(); i++) {
602
                type = descriptor.getDataType();//rs.getFieldType(i);
603

    
604
//                if (type.equals(FeatureAttributeDescriptor.) == Types.NULL) {
605
//                    continue;
606
//                }
607

    
608
                if (type == DataTypes.INT ||
609
                                type == DataTypes.DOUBLE ||
610
                                type == DataTypes.FLOAT ||
611
                                type  == DataTypes.LONG)
612
                {
613
                        nomFields.add(descriptor.getName());
614
                }
615
            }
616

    
617
//            rs.stop();
618
        } catch (DataException e) {
619
                NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
620
        }
621

    
622
        DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray());
623
        cmbField.setModel(cM);
624

    
625
        symbolTable.removeAllItems();
626
    }
627

    
628
    /**
629
     * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
630
     */
631
     public ILegend getLegend() {
632
                fillSymbolListFromTable();
633
                if(defaultSymbolPrev.getSymbol() != null) {
634
                        auxLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol());
635
                }
636

    
637
                auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
638

    
639
                try {
640
                        theLegend = (VectorialIntervalLegend) auxLegend.cloneLegend();
641
                } catch (XMLException e) {
642
                        // TODO Auto-generated catch block
643
                        e.printStackTrace();
644
                }
645
                return theLegend;
646
        }
647

    
648
    /**
649
     * A partir de los registros de la tabla, regenera el FRenderer. (No solo
650
     * el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
651
     */
652

    
653
    private void fillSymbolListFromTable() {
654
                ISymbol theSymbol;
655
                IInterval theInterval = null;
656

    
657
                // Borramos las anteriores listas:
658
                auxLegend.clear();
659

    
660
                String fieldName = (String) cmbField.getSelectedItem();
661
                auxLegend.setClassifyingFieldNames(new String[] {fieldName});
662

    
663
                auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
664

    
665
                FeatureStore rs;
666
                try {
667

    
668
                        rs = ((FLyrVect) layer).getFeatureStore();
669
//                        rs.start();
670
                        FeatureType featureType=rs.getDefaultFeatureType();
671
                        auxLegend
672
                                        .setClassifyingFieldTypes(new int[] { new Integer(
673
                                                        featureType.getAttributeDescriptor(fieldName)
674
                                                                        .getDataType()) });
675
                        logger.debug("rs.start()");
676
//                        rs.stop();
677

    
678
                } catch (DataException e) {
679
                        NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
680
                }
681

    
682

    
683

    
684
                for (int row = 0; row < symbolTable.getRowCount(); row++) {
685
                        if (!(symbolTable.getFieldValue(row, 1) instanceof FInterval)) {
686
                                theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
687
                                theSymbol.setDescription((String) symbolTable.getFieldValue(
688
                                                row, 2));
689
                                auxLegend.addSymbol(new NullIntervalValue(), theSymbol);
690
                        } else {
691
                                theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
692
                                theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
693
                                theSymbol.setDescription((String) symbolTable.getFieldValue(
694
                                                row, 2));
695
                                auxLegend.addSymbol(theInterval, theSymbol);
696
                        }
697
                }
698
                if(chkdefaultvalues.isSelected()){
699
                        if(defaultSymbolPrev.getSymbol() != null){
700
                                String description = PluginServices.getText(this,"default");
701
                                defaultSymbolPrev.getSymbol().setDescription(description);
702
                                auxLegend.addSymbol(new NullIntervalValue(), defaultSymbolPrev.getSymbol());
703
                        }
704
                }
705
        }
706

    
707
    /**
708
     * This method initializes panelC
709
     *
710
     * @return javax.swing.JPanel
711
     */
712
    private JPanel getPnlCenter() {
713
        if (pnlCenter == null) {
714
            pnlCenter = new JPanel();
715
        }
716

    
717
        return pnlCenter;
718
    }
719

    
720
    /**
721
     * Listener.
722
     *
723
     * @author Vicente Caballero Navarro
724
     */
725
    class MyListener implements ActionListener {
726

    
727
       public void actionPerformed(ActionEvent e) {
728
            System.out.println("ActionEvent con " + e.getActionCommand());
729

    
730
            //modificar el combobox de valor
731
            if (e.getActionCommand() == "FIELD_SELECTED") {
732
                JComboBox cb = (JComboBox) e.getSource();
733
                String fieldName = (String) cb.getSelectedItem();
734
                System.out.println("Nombre del campo: " + fieldName);
735
                symbolTable.removeAllItems();
736

    
737
                //theLegend.setClassifyingFieldNames(new String[] {fieldName});
738
                auxLegend.setClassifyingFieldNames(new String[] {fieldName});
739
            } else if (e.getActionCommand() == "INTERVAL_TYPE") {
740
                JComboBox cb = (JComboBox) e.getSource();
741

    
742
                //if ((theLegend != null) &&
743
                if ((auxLegend != null) &&
744
                    //    (cb.getSelectedIndex() != theLegend.getIntervalType())) {
745
                        (cb.getSelectedIndex() != auxLegend.getIntervalType())) {
746
                    //theLegend.setIntervalType(cb.getSelectedIndex());
747
                    auxLegend.setIntervalType(cb.getSelectedIndex());
748
                    symbolTable.removeAllItems();
749
                }
750
            }
751

    
752
            //A�adir todos los elementos por valor
753
            if (e.getActionCommand() == "ADD_ALL_VALUES") {
754
                fillTableValues();
755
            }
756

    
757
            //A�adir un �nico elemento
758
            if (e.getActionCommand() == "ADD_VALUE") {
759
                try {
760
                    symbolTable.addTableRecord(
761
                                    SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType()),
762
                                    new FInterval(0, 0),
763
                                    "0 - 0");
764
                } catch (DataException e1) {
765
                        NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e1);
766
                }
767

    
768
            }
769

    
770
            //Vacia la tabla
771
            if (e.getActionCommand() == "REMOVE_ALL") {
772
                symbolTable.removeAllItems();
773

    
774
            }
775

    
776
            //Quitar solo el elemento seleccionado
777
            if (e.getActionCommand() == "REMOVE") {
778
                symbolTable.removeSelectedRows();
779
            }
780
        }
781
    }
782

    
783
    public String getDescription() {
784
        return PluginServices.getText(this,"Muestra_los_elementos_de_la_capa_usando_una_gama_de_colores_en_funcion_del_valor_de_un_determinado_campo_de_atributos") + ".";
785
    }
786

    
787
    public ImageIcon getIcon() {
788
        return new ImageIcon(this.getClass().getClassLoader().
789
                                getResource("images/Intervalos.png"));
790
    }
791

    
792
    public Class getParentClass() {
793
        return Quantities.class;
794
    }
795

    
796
    public String getTitle() {
797
        return PluginServices.getText(this,"Intervalos");
798
    }
799

    
800
    public JPanel getPanel() {
801
        return this;
802
    }
803

    
804
    public Class getLegendClass() {
805
        return VectorialIntervalLegend.class;
806
    }
807

    
808
    private boolean isNumericField(int fieldType) {
809
                if (fieldType == DataTypes.DOUBLE || fieldType == DataTypes.FLOAT
810
                                || fieldType == DataTypes.LONG || fieldType == DataTypes.INT) {
811
                        return true;
812
                }else{
813
                        return false;
814
                }
815
//            switch (fieldType) {
816
//                case Types.BIGINT:
817
//                case Types.DECIMAL:
818
//                case Types.DOUBLE:
819
//                case Types.FLOAT:
820
//                case Types.INTEGER:
821
//                case Types.NUMERIC:
822
//                case Types.REAL:
823
//                case Types.SMALLINT:
824
//                case Types.TINYINT:
825
//                        return true;
826
//                default:
827
//                        return false;
828
//                }
829

    
830
        }
831
        public boolean isSuitableFor(FLayer layer) {
832
                if (layer instanceof FLyrVect) {
833
                        FeatureStore sds;
834
                        try {
835
                                sds = ((FLyrVect) layer).getFeatureStore();
836
                                FeatureType featureType=sds.getDefaultFeatureType();
837
                                Iterator iterator=featureType.iterator();
838
                                while (iterator.hasNext()) {
839
                                        FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
840

    
841
//                                }
842
//                                String[] fNames = sds.getFieldNames();
843
//                                for (int i = 0; i < fNames.length; i++) {
844
                                        if (isNumericField(descriptor.getDataType())) {
845
                                                return true;
846
                                        }
847
                                }
848
                        } catch (DataException e) {
849
                                return false;
850
                        }
851
                }
852
                return false;
853
        }
854
}