Statistics
| Revision:

root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / FPanelLegendBreaks.java @ 2076

History | View | Annotate | Download (24.4 KB)

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

    
49
import java.awt.BorderLayout;
50
import java.awt.Color;
51
import java.awt.GridBagConstraints;
52
import java.awt.GridBagLayout;
53
import java.awt.Insets;
54
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
56
import java.text.NumberFormat;
57
import java.util.ArrayList;
58
import java.util.Date;
59

    
60
import javax.swing.DefaultComboBoxModel;
61
import javax.swing.JButton;
62
import javax.swing.JComboBox;
63
import javax.swing.JLabel;
64
import javax.swing.JOptionPane;
65
import javax.swing.JPanel;
66
import javax.swing.JTextField;
67

    
68
import org.apache.log4j.Logger;
69

    
70
import com.hardcode.gdbms.engine.data.DataSource;
71
import com.hardcode.gdbms.engine.values.DoubleValue;
72
import com.hardcode.gdbms.engine.values.FloatValue;
73
import com.hardcode.gdbms.engine.values.IntValue;
74
import com.hardcode.gdbms.engine.values.LongValue;
75
import com.hardcode.gdbms.engine.values.NullValue;
76
import com.hardcode.gdbms.engine.values.Value;
77
import com.iver.andami.PluginServices;
78
import com.iver.cit.gvsig.fmap.DriverException;
79
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
80
import com.iver.cit.gvsig.fmap.layers.FLayer;
81
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
82
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
83
import com.iver.cit.gvsig.fmap.rendering.FInterval;
84
import com.iver.cit.gvsig.fmap.rendering.Legend;
85
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
86
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
87
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel;
88

    
89

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

    
101
        // private TOC m_TOC;
102
        private VectorialIntervalLegend m_Renderer;
103
        private ClassifiableVectorial m_lyr;
104
        private FSymbolTable m_symbolTable = new FSymbolTable("intervals");
105
        private JComboBox m_cboFields;
106
        private JComboBox m_cboIntervalType;
107
        private JTextField m_txtNumIntervals;
108
        private ColorChooserPanel m_colorChooser1;
109
        private ColorChooserPanel m_colorChooser2;
110
        private JButton m_btnDeleteAll;
111
        private JButton m_btnDelete;
112
        private FInterval[] intervals;
113
        ///private int tipoClasificacion = VectorialIntervalLegend.NATURAL_INTERVALS;
114
        private int count = 0;
115

    
116
        /**
117
         *
118
         */
119
        public FPanelLegendBreaks() {
120
                super();
121
                initComponents();
122
        }
123

    
124
        /**
125
         * EQUAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
126
         * quieren crear. Los intervalos se crean con un tama?o igual entre ellos.
127
         *
128
         * @param numIntervals n?mero de intervalos
129
         * @param minValue Valor m?nimo.
130
         * @param maxValue Valor m?ximo.
131
         *
132
         * @return Array con los intervalos.
133
         */
134
        FInterval[] calculateEqualIntervals(int numIntervals,
135
                double minValue, double maxValue) {
136
                FInterval[] theIntervalArray = new FInterval[numIntervals];
137
                double step = (maxValue - minValue) / numIntervals;
138

    
139
                for (int i = 0; i < numIntervals; i++) {
140
                        theIntervalArray[i] = new FInterval(minValue + (i * step),
141
                                        minValue + ((i + 1) * step));
142
                }
143

    
144
                return theIntervalArray;
145
        }
146

    
147
        /**
148
         * NATURAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
149
         * quieren crear. Los intervalos se distribuyen de forma natural.
150
         *
151
         * @param numIntervals n?mero de intervalos
152
         * @param minValue Valor m?nimo.
153
         * @param maxValue Valor m?ximo.
154
         *
155
         * @return Array con los intervalos.
156
         */
157
        FInterval[] calculateNaturalIntervals(int numIntervals, double minValue,
158
                double maxValue,String fieldName) {
159
                
160
                NaturalIntervalGenerator intervalGenerator = new NaturalIntervalGenerator(((AlphanumericData) m_lyr),fieldName,numIntervals);
161

    
162
                try {
163
                        intervalGenerator.generarIntervalos();
164
                } catch (DriverException e) {
165
                        e.printStackTrace();
166
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
167
                        e.printStackTrace();
168
                }
169
                int numIntervalsGen=intervalGenerator.getNumIntervals()-1;
170
                if (numIntervalsGen==-1){
171
                        //TODO cuando no puede calcular los intervalos.
172
                        numIntervalsGen=1;
173
                }
174
                FInterval[] theIntervalArray = new FInterval[numIntervalsGen];
175
                if (numIntervalsGen>1){
176
                
177
                theIntervalArray[0] = new FInterval(minValue, intervalGenerator.getValorRuptura(0));
178
                for (int i = 1; i < numIntervalsGen-1; i++) {
179
                        theIntervalArray[i] = new FInterval(intervalGenerator.getValorRuptura(
180
                                                i-1)+0.01, intervalGenerator.getValorRuptura(i));
181
                }
182
                
183
                theIntervalArray[numIntervalsGen-1] = new FInterval(intervalGenerator.getValorRuptura(
184
                                numIntervalsGen-2)+0.01, maxValue);
185
                }else{
186
                        theIntervalArray[numIntervalsGen-1] = new FInterval(minValue, maxValue);
187
                }
188
                return theIntervalArray;
189
        }
190

    
191
        /**
192
         * QUANTILE INTERVAL Devuelve un Array con el n?mero de intervalos que se
193
         * quieren crear. Los intervalos se distribuyen de forma quantile.
194
         *
195
         * @param numIntervals n?mero de intervalos
196
         * @param minValue Valor m?nimo.
197
         * @param maxValue Valor m?ximo.
198
         *
199
         * @return Array con los intervalos.
200
         */
201
        FInterval[] calculateQuantileIntervals(int numIntervals, double minValue,
202
                double maxValue,String fieldName) {
203
                QuantileIntervalGenerator intervalGenerator = new QuantileIntervalGenerator(((AlphanumericData) m_lyr),fieldName,numIntervals);
204

    
205
                try {
206
                        intervalGenerator.generarIntervalos();
207
                } catch (DriverException e) {
208
                        e.printStackTrace();
209
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
210
                        e.printStackTrace();
211
                }
212
                int numIntervalsGen=intervalGenerator.getNumIntervalGen();
213
                FInterval[] theIntervalArray = new FInterval[numIntervalsGen];
214
                if (intervalGenerator.getNumIntervalGen()>1){
215
                theIntervalArray[0] = new FInterval(minValue, intervalGenerator.getNumRuptura(0));
216
                for (int i = 1; i < numIntervalsGen-1; i++) {
217
                        theIntervalArray[i] = new FInterval(intervalGenerator.getNumRuptura(
218
                                                i-1)+0.01, intervalGenerator.getNumRuptura(i));
219
                }
220
                
221
                theIntervalArray[numIntervalsGen-1] = new FInterval(intervalGenerator.getNumRuptura(
222
                                numIntervalsGen-2)+0.01, maxValue);
223
                }else{
224
                        theIntervalArray[numIntervalsGen-1] = new FInterval(minValue, maxValue);
225
                }
226
                return theIntervalArray;
227
                
228
                
229
        /*        double numQ = count / numIntervals;
230

231
                for (int i = 0; i < count; i++) {
232
                }
233

234
                return theIntervalArray;
235
*/
236
        }
237

    
238
        /**
239
         * DOCUMENT ME!
240
         */
241
        protected void initComponents() {
242
                /* JLabel label = new JLabel();
243
                   label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader()
244
                                                                                                                      .getResource("images/ValoresUnicos.png")));
245
                   limagen[1] = new JLabel();
246
                   limagen[1] = label; */
247
                JPanel botonestabla = new JPanel();
248

    
249
                JButton btnAddAll = new JButton(PluginServices.getText(this,
250
                                        "Calcular_intervalos"));
251
                btnAddAll.setActionCommand("ADD_ALL_VALUES");
252
                botonestabla.add(btnAddAll);
253

    
254
                JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir"));
255
                btnAdd.setActionCommand("ADD_VALUE");
256
                btnAdd.addActionListener(listener);
257
                botonestabla.add(btnAdd);
258

    
259
                m_btnDeleteAll = new JButton(PluginServices.getText(this, "Quitar_todos"));
260
                m_btnDeleteAll.setActionCommand("REMOVE_ALL");
261
                m_btnDeleteAll.addActionListener(listener);
262
                botonestabla.add(m_btnDeleteAll);
263

    
264
                m_btnDelete = new JButton(PluginServices.getText(this, "Quitar"));
265
                m_btnDelete.setActionCommand("REMOVE");
266
                m_btnDelete.addActionListener(listener);
267
                botonestabla.add(m_btnDelete);
268

    
269
                m_btnDeleteAll.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
270
                                public void propertyChange(java.beans.PropertyChangeEvent e) {
271
                                        if ((e.getPropertyName().equals("enabled"))) {
272
                                                System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" 
273
                                        }
274
                                }
275
                        });
276
                m_btnDelete.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
277
                                public void propertyChange(java.beans.PropertyChangeEvent e) {
278
                                        if ((e.getPropertyName().equals("enabled"))) {
279
                                                System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" 
280
                                        }
281
                                }
282
                        });
283
                btnAddAll.addActionListener(listener);
284

    
285
                JPanel ptabla = new JPanel();
286
                ptabla.setLayout(new BorderLayout());
287

    
288
                m_cboFields = new JComboBox();
289
                m_cboFields.setActionCommand("FIELD_SELECTED");
290
                m_cboFields.addActionListener(listener);
291
                m_cboFields.setVisible(true);
292

    
293
                JPanel pAux1 = new JPanel();
294

    
295
                /* pAux1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
296
                   "Campo de clasificaci?n",
297
                   javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
298
                   javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); */
299

    
300
                // pAux1.setPreferredSize(new Dimension(300,50));
301
                GridBagLayout gridBag = new GridBagLayout();
302
                pAux1.setLayout(gridBag);
303

    
304
                GridBagConstraints c = new GridBagConstraints();
305

    
306
                c.anchor = GridBagConstraints.WEST;
307

    
308
                JLabel lblFieldClassification = new JLabel(PluginServices.getText(
309
                                        this, "Campo_de_clasificacion"));
310
                c.gridx = 0;
311
                c.gridy = 0;
312
                c.insets = new Insets(5, 5, 2, 2);
313
                c.gridwidth = 1;
314
                gridBag.setConstraints(lblFieldClassification, c);
315
                pAux1.add(lblFieldClassification);
316

    
317
                c.gridx = 1;
318
                c.gridy = 0;
319
                gridBag.setConstraints(m_cboFields, c);
320
                pAux1.add(m_cboFields);
321

    
322
                JLabel lblNumIntervals = new JLabel(PluginServices.getText(this,
323
                                        "No_de_intervalos") + ":");
324
                c.gridx = 3;
325
                c.gridy = 0;
326
                gridBag.setConstraints(lblNumIntervals, c);
327
                pAux1.add(lblNumIntervals);
328

    
329
                m_txtNumIntervals = new JTextField(4);
330
                c.gridx = 4;
331
                c.gridy = 0;
332
                gridBag.setConstraints(m_txtNumIntervals, c);
333
                m_txtNumIntervals.setText("5");
334
                pAux1.add(m_txtNumIntervals);
335

    
336
                JLabel lblIntervalType = new JLabel(PluginServices.getText(this,
337
                                        "tipo_de_intervalo"));
338
                c.gridx = 0;
339
                c.gridy = 1;
340
                c.insets = new Insets(5, 5, 2, 2);
341
                c.gridwidth = 1;
342
                gridBag.setConstraints(lblIntervalType, c);
343
                pAux1.add(lblIntervalType);
344

    
345
                m_cboIntervalType = new JComboBox();
346
                m_cboIntervalType.setActionCommand("INTERVAL_TYPE");
347
                m_cboIntervalType.addActionListener(listener);
348
                m_cboIntervalType.addItem("EQUAL_INTERVALS");
349
                m_cboIntervalType.addItem("NATURAL_INTERVALS");
350
                m_cboIntervalType.addItem("QUANTILE_INTERVALS");
351
                m_cboIntervalType.setVisible(true);
352

    
353
                c.gridx = 1;
354
                c.gridy = 1;
355
                gridBag.setConstraints(m_cboIntervalType, c);
356
                pAux1.add(m_cboIntervalType);
357

    
358
                c.insets = new Insets(2, 2, 2, 2);
359

    
360
                JLabel lblColor1 = new JLabel(PluginServices.getText(this,
361
                                        "Color_inicio") + ":");
362
                c.gridx = 0;
363
                c.gridy = 2;
364
                gridBag.setConstraints(lblColor1, c);
365
                pAux1.add(lblColor1);
366

    
367
                m_colorChooser1 = new ColorChooserPanel();
368
                m_colorChooser1.setColor(Color.red);
369
                m_colorChooser1.setAlpha(255);
370
                c.gridx = 1;
371
                c.gridy = 2;
372
                gridBag.setConstraints(m_colorChooser1, c);
373
                pAux1.add(m_colorChooser1);
374

    
375
                JLabel lblColor2 = new JLabel(PluginServices.getText(this, "Color_final") +
376
                                ":");
377
                c.gridx = 3;
378
                c.gridy = 2;
379
                gridBag.setConstraints(lblColor2, c);
380
                pAux1.add(lblColor2);
381

    
382
                m_colorChooser2 = new ColorChooserPanel();
383
                m_colorChooser2.setColor(Color.blue);
384
                m_colorChooser2.setAlpha(255);
385
                c.gridx = 4;
386
                c.gridy = 2;
387
                gridBag.setConstraints(m_colorChooser2, c);
388
                pAux1.add(m_colorChooser2);
389

    
390
                ptabla.add(m_symbolTable, BorderLayout.CENTER);
391
                this.setLayout(new BorderLayout());
392
                this.add(pAux1, BorderLayout.NORTH);
393
                this.add(ptabla, BorderLayout.CENTER);
394
                this.add(botonestabla, BorderLayout.SOUTH);
395
        }
396

    
397
        /**
398
         * Damos una primera pasada para saber los l?mites inferior y superior y
399
         * rellenar un array con los valores. Luego dividimos ese array en
400
         * intervalos.
401
         */
402
        private void fillTableValues() {
403
                FInterval[] arrayIntervalos = null;
404
                DataSource elRs;
405
                m_symbolTable.removeAllItems();
406

    
407
                try {
408
                        elRs = ((AlphanumericData) m_lyr).getRecordset();
409
                        logger.debug("elRs.start()");
410
                        elRs.start();
411

    
412
                        int idField = -1;
413
                        int numIntervalos=1;
414
                        try{
415
                         numIntervalos= Integer.parseInt(m_txtNumIntervals.getText());
416
                        }catch (NumberFormatException e) {
417
                                System.out.println("Foramto de n?mero erroneo");
418
                        }
419
                        String fieldName = (String) m_cboFields.getSelectedItem();
420
                        System.out.println("Nombre del campo de clasificaci?n: " +
421
                                fieldName);
422
                        m_Renderer.setFieldName(fieldName);
423

    
424
                        String nomField = m_Renderer.getFieldName();
425

    
426
                        // Cogemos el tipo de gradaci?n de colores que quiere el usuario y 
427
                        // Creamos el primer y ?ltimo color.
428
                        Color startColor = m_colorChooser1.getColor();
429
                        m_Renderer.setStartColor(startColor);
430

    
431
                        Color endColor = m_colorChooser2.getColor();
432
                        m_Renderer.setEndColor(endColor);
433

    
434
                        
435

    
436
                        for (int i = 0; i < elRs.getFieldCount(); i++) {
437
                                String nomAux = elRs.getFieldName(i).trim();
438

    
439
                                if (nomField.compareToIgnoreCase(nomAux) == 0) {
440
                                        idField = i;
441

    
442
                                        break;
443
                                }
444
                        }
445

    
446
                        if (idField == -1) {
447
                                System.err.println("Campo no reconocido " + nomField);
448

    
449
                                return;
450
                        }
451

    
452
                        ///m_symbolTable.removeAllItems();
453
                        ///m_valuesCache = new Object[m_lyr.getSource().getShapeCount()];
454
                        int numSymbols = 0;
455
                        FSymbol theSymbol;
456
                        Date valorDate;
457
                        double minValue = Double.MAX_VALUE;
458
                        double maxValue = Double.MIN_VALUE;
459
                        Date minValueDate = null;
460
                        Date maxValueDate = null;
461

    
462
                        VectorialIntervalLegend auxLegend;
463
                        auxLegend = LegendFactory.createVectorialIntervalLegend(m_lyr.getShapeType());
464

    
465
                        Value clave;
466
                        Object resul;
467
                        int symbolType = 0;
468
                        count = 0;
469

    
470
                        for (int j = 0; j < elRs.getRowCount(); j++) {
471
                                clave = elRs.getFieldValue(j, idField);
472

    
473
                                FInterval interval = auxLegend.getInterval(clave);
474

    
475
                                ////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
476
                                if (auxLegend.getSymbolByInterval(interval) == null) {
477
                                        //si no esta creado el simbolo se crea
478
                                        double valor = 0;
479
                                        symbolType = m_lyr.getShapeType();
480

    
481
                                        if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.IntValue") {
482
                                                valor = ((IntValue) clave).getValue();
483
                                        } else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.DoubleValue") {
484
                                                valor = ((DoubleValue) clave).getValue();
485
                                        } else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.FloatValue") {
486
                                                valor = ((FloatValue) clave).getValue();
487
                                        } else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.LongValue") {
488
                                                valor = ((LongValue) clave).getValue();
489
                                        } else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.DateValue") {
490
                                                //TODO POR IMPLEMENTAR
491
                                                ///valorDate = elRs.getFieldValueAsDate(idField);
492
                                                ///if (valorDate.before(minValueDate)) minValueDate = valorDate;
493
                                                ///if (valorDate.after(maxValueDate)) maxValueDate = valorDate;
494
                                        }
495

    
496
                                        if (valor < minValue) {
497
                                                minValue = (double) valor;
498
                                        }
499

    
500
                                        if (valor > maxValue) {
501
                                                maxValue = (double) valor;
502
                                        }
503
                                }
504

    
505
                                count++;
506
                        }
507

    
508
                        switch (m_Renderer.getIntervalType()) {
509
                                case VectorialIntervalLegend.EQUAL_INTERVALS:
510
                                        arrayIntervalos = calculateEqualIntervals(numIntervalos,
511
                                                        minValue, maxValue);
512

    
513
                                        break;
514

    
515
                                case VectorialIntervalLegend.NATURAL_INTERVALS:
516
                                        arrayIntervalos = calculateNaturalIntervals(numIntervalos,
517
                                                        minValue, maxValue,fieldName);
518

    
519
                                        break;
520

    
521
                                case VectorialIntervalLegend.QUANTILE_INTERVALS:
522
                                        arrayIntervalos = calculateQuantileIntervals(numIntervalos,
523
                                                        minValue, maxValue,fieldName);
524

    
525
                                        break;
526
                        }
527

    
528
                        intervals = arrayIntervalos;
529

    
530
                        FInterval elIntervalo;
531
                        NumberFormat.getInstance().setMaximumFractionDigits(2);
532
                        m_Renderer.clear();
533

    
534
                        int r;
535
                        int g;
536
                        int b;
537
                        int stepR;
538
                        int stepG;
539
                        int stepB;
540
                        r = startColor.getRed();
541
                        g = startColor.getGreen();
542
                        b = startColor.getBlue();
543
                        stepR = (endColor.getRed() - r) / arrayIntervalos.length;
544
                        stepG = (endColor.getGreen() - g) / arrayIntervalos.length;
545
                        stepB = (endColor.getBlue() - b) / arrayIntervalos.length;
546
                        for (int k = 0; k < arrayIntervalos.length; k++) {
547
                                elIntervalo = arrayIntervalos[k];
548

    
549
                                // clave = elIntervalo; // elIntervalo.getMin() + " - " + elIntervalo.getMax();
550
                                // System.out.println("k = " + k + " clave = " + clave);
551
                                ////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
552
                                // if (!m_Renderer.m_symbolList.containsKey(elIntervalo)) {
553
                                //si no esta creado el simbolo se crea
554
                                theSymbol = new FSymbol(symbolType, new Color(r, g, b));
555
                                theSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) +
556
                                        " - " +
557
                                        NumberFormat.getInstance().format(elIntervalo.getMax()));
558

    
559
                                //////////////////////////////////////
560
                                // CALCULAMOS UN COLOR APROPIADO
561
                                r = r + stepR;
562
                                g = g + stepG;
563
                                b = b + stepB;
564

    
565
                                /////////////////////////////////
566
                                m_Renderer.addSymbol(elIntervalo, theSymbol);
567
                                System.out.println("addSymbol = " + elIntervalo +
568
                                        " theSymbol = " + theSymbol.getDescription());
569
                                numSymbols++;
570

    
571
                                if (numSymbols > 100) {
572
                                        JOptionPane.showMessageDialog(this,
573
                                                "M?s 100 de s?mbolos no aportan informaci?n en un plano. Por favor, revise el campo seleccionado.");
574

    
575
                                        break;
576
                                }
577

    
578
                                // }
579
                        } // for
580

    
581
                        System.out.println("Num. Simbolos = " +
582
                                m_Renderer.getValues().length);
583
                        m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(),
584
                                m_Renderer.getValues(), m_Renderer.getDescriptions());
585
                        elRs.stop();
586
                } catch (DriverException e) {
587
                        // TODO Auto-generated catch block
588
                        e.printStackTrace();
589
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
590
                        e.printStackTrace();
591
                }
592

    
593
                m_btnDeleteAll.setEnabled(true);
594
                m_btnDelete.setEnabled(true);
595
        }
596

    
597
        /**
598
         * A partir de los registros de la tabla, regenera el FRenderer. (No solo
599
         * el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
600
         */
601
        private void fillSymbolListFromTable() {
602
                String clave;
603
                FSymbol theSymbol;
604
                FInterval theInterval = null;
605

    
606
                // Borramos las anteriores listas:
607
                m_Renderer.clear();
608

    
609
                boolean bRestoValores = false; // PONERLO EN UN CHECKBOX
610
                double from = 0;
611
                double to = 0;
612
                String[] arraySplit = new String[2];
613
                int hasta;
614
                String fieldName = (String) m_cboFields.getSelectedItem();
615
                m_Renderer.setFieldName(fieldName);
616

    
617
                if (bRestoValores) {
618
                        hasta = m_symbolTable.getRowCount() - 1;
619
                } else {
620
                        hasta = m_symbolTable.getRowCount();
621
                }
622

    
623
                for (int row = 0; row < m_symbolTable.getRowCount(); row++) {
624
                        // clave = m_symbolTable.getFieldValue(row,1);
625
                        theInterval = (FInterval) m_symbolTable.getFieldValue(row, 1);
626
                        theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
627
                        theSymbol.setDescription((String) m_symbolTable.getFieldValue(row, 2));
628
                        m_Renderer.addSymbol(theInterval, theSymbol);
629

    
630
                        ///m_Renderer.m_legendIntervals.add(theInterval);
631
                }
632

    
633
                if (bRestoValores) {
634
                        //m_Renderer.m_bUseDefaultSymbol = true;
635
                        theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta, 0);
636
                        m_Renderer.setDefaultSymbol(theSymbol);
637
                }
638
        }
639

    
640
        /**
641
         * DOCUMENT ME!
642
         */
643
        private void fillFieldNames() {
644
                DataSource rs = null;
645
                ArrayList nomFields = null;
646

    
647
                try {
648
                        rs = ((AlphanumericData) m_lyr).getRecordset();
649
                        logger.debug("rs.start()");
650
                        rs.start();
651

    
652
                        nomFields = new ArrayList();
653

    
654
                        Value val;
655

    
656
                        for (int i = 0; i < rs.getFieldCount(); i++) {
657
                                //TODO deber?a de existir un getFieldType
658
                                val = rs.getFieldValue(0, i);
659

    
660
                                if (val.getClass() == NullValue.class) {
661
                                        continue;
662
                                }
663

    
664
                                if ((val.getClass() == IntValue.class) ||
665
                                                (val.getClass() == DoubleValue.class) ||
666
                                                (val.getClass() == FloatValue.class) ||
667
                                                (val.getClass() == LongValue.class)) {
668
                                        nomFields.add(rs.getFieldName(i).trim());
669
                                }
670
                        }
671

    
672
                        rs.stop();
673
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
674
                        e1.printStackTrace();
675
                } catch (DriverException e) {
676
                        e.printStackTrace();
677
                }
678

    
679
                /*        ArrayList nomFields = new ArrayList();
680
                   for (int i = 0; i < rs.getFieldsCount(); i++) {
681
                           if ((rs.getFieldType(i) == FRecordset.INTEGER) ||
682
                                   (rs.getFieldType(i) == FRecordset.DECIMAL) ||
683
                                   (rs.getFieldType(i) == FRecordset.DATE))
684
                           {
685
                                   nomFields.add(rs.getFieldName(i).trim());
686
                           }
687
                
688
                   }
689
                 */
690
                DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray());
691
                m_cboFields.setModel(cM);
692

    
693
                // fieldsListValor.setSelectedIndex(0);
694
                m_symbolTable.removeAllItems();
695
        }
696

    
697
        /**
698
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer,
699
         *                 com.iver.cit.gvsig.fmap.rendering.Legend)
700
         */
701
        public void setLayer(FLayer lyr, Legend r) {
702
                //                 m_TOC = t;
703
                // OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL
704
                // m_lyr = (FLyrVect) t.getFirstLyrVectSelected();
705
                m_lyr = (ClassifiableVectorial) lyr;
706
                fillFieldNames();
707

    
708
                if (r instanceof VectorialIntervalLegend) {
709
                        m_Renderer = (VectorialIntervalLegend) r;
710
                        m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName());
711
                        m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(),
712
                                m_Renderer.getValues(), m_Renderer.getDescriptions());
713
                        m_colorChooser1.setColor(m_Renderer.getStartColor());
714
                        m_colorChooser2.setColor(m_Renderer.getEndColor());
715
                        m_colorChooser1.repaint();
716
                        m_colorChooser2.repaint();
717
                } else {
718
                        try {
719
                                // Si la capa viene con otro tipo de leyenda, creamos
720
                                // una nueva del tipo que maneja este panel
721
                                m_Renderer = new VectorialIntervalLegend(m_lyr.getShapeType());
722
                        } catch (DriverException e) {
723
                                // TODO Auto-generated catch block
724
                                e.printStackTrace();
725
                        }
726
                }
727
                m_cboIntervalType.setSelectedIndex(m_Renderer.getIntervalType());
728
        }
729

    
730
        /**
731
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
732
         */
733
        public Legend getLegend() {
734
                fillSymbolListFromTable();
735

    
736
                return m_Renderer;
737
        }
738

    
739
        /**
740
         * DOCUMENT ME!
741
         *
742
         * @author Vicente Caballero Navarro
743
         */
744
        class MyListener implements ActionListener {
745
                //private FLyrShp m_layer;
746
                // private FPanelLegendValues m_Parent;
747
                public MyListener() { // FPanelLegendValues p) {
748

    
749
                        // m_Parent = p;
750
                }
751

    
752
                /**
753
                 * DOCUMENT ME!
754
                 *
755
                 * @param e DOCUMENT ME!
756
                 */
757
                public void actionPerformed(ActionEvent e) {
758
                        // rellenarValue();
759
                        System.out.println("ActionEvent con " + e.getActionCommand());
760

    
761
                        //modificar el combobox de valor
762
                        if (e.getActionCommand() == "FIELD_SELECTED") {
763
                                JComboBox cb = (JComboBox) e.getSource();
764
                                String fieldName = (String) cb.getSelectedItem();
765
                                System.out.println("Nombre del campo: " + fieldName);
766
                                m_symbolTable.removeAllItems();
767

    
768
                                m_Renderer.setFieldName(fieldName);
769
                        } else if (e.getActionCommand() == "INTERVAL_TYPE") {
770
                                JComboBox cb = (JComboBox) e.getSource();
771
                                
772
                                if (m_Renderer!=null && cb.getSelectedIndex() != m_Renderer.getIntervalType()) {
773
                                        m_Renderer.setIntervalType(cb.getSelectedIndex());
774
                                        m_symbolTable.removeAllItems();
775
                                }
776
                                
777
                        }
778

    
779
                        //A?adir todos los elementos por valor
780
                        if (e.getActionCommand() == "ADD_ALL_VALUES") {
781
                                fillTableValues();
782
                        }
783

    
784
                        //A?adir un ?nico elemento
785
                        if (e.getActionCommand() == "ADD_VALUE") {
786
                                /*        a?adir("Nuevo_Valor");
787
                                   aceptar.setEnabled(true);
788
                                   quitartodo.setEnabled(true);
789
                                   quitar.setEnabled(true); */
790
                        }
791

    
792
                        //Vacia la tabla
793
                        if (e.getActionCommand() == "REMOVE_ALL") {
794
                                m_symbolTable.removeAllItems();
795

    
796
                                // aceptar.setEnabled(false);
797
                        }
798

    
799
                        //Quitar solo el elemento seleccionado
800
                        if (e.getActionCommand() == "REMOVE") {
801
                                m_symbolTable.removeSelectedRows();
802
                        }
803
                }
804
        }
805
}