Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / PalettePanel.java @ 8026

History | View | Annotate | Download (19.5 KB)

1
/*
2
 * Created on 23-ago-2006
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 */
23
package org.cresques.ui.raster;
24

    
25
import java.awt.Color;
26
import java.awt.FlowLayout;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.io.File;
30
import java.io.FileInputStream;
31
import java.io.FileNotFoundException;
32
import java.io.IOException;
33
import java.util.ArrayList;
34
import java.util.Arrays;
35
import java.util.Hashtable;
36

    
37
import javax.swing.JButton;
38
import javax.swing.JCheckBox;
39
import javax.swing.JComboBox;
40
import javax.swing.JFrame;
41
import javax.swing.JLabel;
42
import javax.swing.JPanel;
43

    
44
import org.cresques.io.data.RasterBuf;
45
import org.cresques.io.datastruct.Palette;
46
import org.cresques.ui.raster.listener.PalettePanelListener;
47
import org.cresques.util.Utilities;
48
import org.gvsig.gui.beans.table.TableContainer;
49
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
50
import org.gvsig.gui.beans.table.models.TableButtonModel;
51
import org.gvsig.i18n.Messages;
52
import org.kxml2.io.KXmlParser;
53
import org.xmlpull.v1.XmlPullParserException;
54

    
55
/**
56
 * Interfaz de usuario para la selecci?n de paletas de color
57
 * 
58
 * @author Nacho Brodin (brodin_ign@gva.es)
59
 *
60
 */
61

    
62
public class PalettePanel extends BaseComponent {
63

    
64
        private int                                         HSELECT = 52;
65
        private int                                         HOPTIONS = 25;
66
        private int                                         HBUTTONS = 30;
67
        private int                                         MARGIN = 12;
68
        
69
        private JPanel                                         pMain = null;
70
        private JPanel                                         pNorth = null;
71
        private JPanel                                         pButtons = null;
72
        private TableContainer                         pTable = null;
73
        private JPanel                                         pSelect = null;
74
        private JPanel                                         pOptions = null;
75
        private JButton                                 bAccept = null;
76
        private JButton                                 bApply = null;
77
        private JButton                                 bCancel = null;
78
        private JButton                                 bSave = null;
79
        
80
        private int                                         width = 500;
81
        private int                                         height = 600;
82
        private String[]                                 columnNames = {Messages.getText("selec"), Messages.getText("clase"), "RGB", Messages.getText("valor"), Messages.getText("alpha")};
83
        private int[]                                         columnWidths = {50, 90, 94, 95, 65};
84
        private JCheckBox                                 cActive = null;
85
        private JComboBox                                 cbList = null;
86
        private JCheckBox                                 cbInterpolar = null;
87
        private PalettePanelListener        listener  = null;
88
        private String                                         palettesPath = "";
89
        private JLabel                                         lPredefinidas = null;
90

    
91
        
92
        /**
93
         * This method initializes 
94
         * 
95
         */
96
        public PalettePanel(int w, int h, JFrame mainFrame) {
97
                super();
98
                this.width = w;
99
                this.height = h;
100
                listener = new PalettePanelListener(this);
101
                initialize();
102
        }
103
        
104
        /**
105
         * This method initializes 
106
         * 
107
         */
108
        public PalettePanel(int w, int h, String palettesPath) {
109
                //super();
110
                this.width = w;
111
                this.height = h;
112
                this.palettesPath = palettesPath;
113
                listener = new PalettePanelListener(this);
114
                initialize();
115
        }
116

    
117
        /**
118
         * This method initializes this
119
         * 
120
         */
121
        private void initialize() {
122
        this.add(getPMain(), null);
123
                listener.setControlListeners();
124
                loadPaletteList(palettesPath);
125
        }
126

    
127
        /**
128
         * This method initializes jPanel        
129
         *         
130
         * @return javax.swing.JPanel        
131
         */
132
        public JPanel getPMain() {
133
                if (pMain == null) {
134
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
135
                        gridBagConstraints4.insets = new java.awt.Insets(0,0,0,0);
136
                        gridBagConstraints4.gridy = 1;
137
                        gridBagConstraints4.gridx = 0;
138
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
139
                        gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0);
140
                        gridBagConstraints3.gridy = 0;
141
                        gridBagConstraints3.gridx = 0;
142
                        pMain = new JPanel();
143
                        pMain.setLayout(new GridBagLayout());
144
                        pMain.setPreferredSize(new java.awt.Dimension(width, height));
145
                        pMain.add(getPNorth(), gridBagConstraints3);
146
                        pMain.add(getPButtons(), gridBagConstraints4);
147
                }
148
                return pMain;
149
        }
150

    
151
        /**
152
         * This method initializes jPanel1        
153
         *         
154
         * @return javax.swing.JPanel        
155
         */
156
        public JPanel getPNorth() {
157
                if (pNorth == null) {
158
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
159
                        gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0);
160
                        gridBagConstraints2.gridy = 2;
161
                        gridBagConstraints2.gridx = 0;
162
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
163
                        gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0);
164
                        gridBagConstraints1.gridy = 1;
165
                        gridBagConstraints1.gridx = 0;
166
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
167
                        gridBagConstraints.insets = new java.awt.Insets(0,0,0,0);
168
                        gridBagConstraints.gridy = 0;
169
                        gridBagConstraints.gridx = 0;
170
                        pNorth = new JPanel();
171
                        pNorth.setLayout(new GridBagLayout());
172
                        pNorth.setPreferredSize(new java.awt.Dimension(width, height - HBUTTONS));
173
                        pNorth.add(getPSelect(), gridBagConstraints);
174
                        pNorth.add(getPTable(), gridBagConstraints1);
175
                        pNorth.add(getPOptions(), gridBagConstraints2);
176
                }
177
                return pNorth;
178
        }
179

    
180
        /**
181
         * This method initializes jPanel2        
182
         *         
183
         * @return javax.swing.JPanel        
184
         */
185
        private JPanel getPButtons() {
186
                if (pButtons == null) {
187
                        FlowLayout flowLayout = new FlowLayout();
188
                        flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
189
                        flowLayout.setVgap(0);
190
                        flowLayout.setHgap(3);
191
                        pButtons = new JPanel();
192
                        pButtons.setPreferredSize(new java.awt.Dimension(width, HBUTTONS));
193
                        pButtons.setLayout(flowLayout);
194
                        pButtons.add(getBSave(), null);
195
                        pButtons.add(getBAccept(), null);
196
                        pButtons.add(getBApply(), null);
197
                        pButtons.add(getBCancel(), null);
198
                }
199
                return pButtons;
200
        }
201

    
202
        /**
203
         * This method initializes jPanel3        
204
         *         
205
         * @return javax.swing.JPanel        
206
         */
207
        public TableContainer getPTable() {
208
                if (pTable == null) {
209
                        pTable = new TableContainer(width -MARGIN, height - HSELECT - HOPTIONS - HBUTTONS - MARGIN, columnNames, columnWidths);
210
                        pTable.setModel("TableButtonModel");
211
                        pTable.initialize();
212
                }
213
                return pTable;
214
        }
215

    
216
        /**
217
         * This method initializes jPanel4        
218
         *         
219
         * @return javax.swing.JPanel        
220
         */
221
        private JPanel getPSelect() {
222
                if (pSelect == null) {
223
                        lPredefinidas = new JLabel();
224
                        lPredefinidas.setText(Messages.getText("predefinidas")+":");
225
                        
226
                        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
227
                        gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL;
228
                        gridBagConstraints6.gridx = 1;
229
                        gridBagConstraints6.gridy = 1;
230
                        gridBagConstraints6.weightx = 1.0;
231
                        gridBagConstraints6.insets = new java.awt.Insets(0,0,0,8);
232
                        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
233
                        gridBagConstraints5.insets = new java.awt.Insets(0,5,0,0);
234
                        gridBagConstraints5.gridy = 0;
235
                        gridBagConstraints5.gridx = 0;
236
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
237
                        gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
238
                        gridBagConstraints4.gridx = 1;
239
                        gridBagConstraints4.gridy = 0;
240
                        gridBagConstraints4.insets = new java.awt.Insets(0,0,0,0);
241
                        pSelect = new JPanel();
242
                        pSelect.setLayout(new GridBagLayout());
243
                        pSelect.setPreferredSize(new java.awt.Dimension(width, HSELECT));
244
                        pSelect.add(getCActive(), gridBagConstraints5);
245
                        pSelect.add(getCbList(), gridBagConstraints6);
246
                        pSelect.add(lPredefinidas, gridBagConstraints4);
247
                }
248
                return pSelect;
249
        }
250

    
251
        /**
252
         * This method initializes jPanel5        
253
         *         
254
         * @return javax.swing.JPanel        
255
         */
256
        private JPanel getPOptions() {
257
                if (pOptions == null) {
258
                        FlowLayout flowLayout1 = new FlowLayout();
259
                        flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
260
                        flowLayout1.setVgap(0);
261
                        flowLayout1.setHgap(3);
262
                        pOptions = new JPanel();
263
                        pOptions.setLayout(flowLayout1);
264
                        pOptions.setPreferredSize(new java.awt.Dimension(width, HOPTIONS));
265
                        pOptions.add(getCbInterpolar(), null);
266
                }
267
                return pOptions;
268
        }
269

    
270
        /**
271
         * This method initializes bApply        
272
         *         
273
         * @return javax.swing.JButton        
274
         */
275
        public JButton getBAccept() {
276
                if (bAccept == null) {
277
                        bAccept = new JButton(Messages.getText("aceptar"));
278
                }
279
                return bAccept;
280
        }
281

    
282
        /**
283
         * This method initializes bApply        
284
         *         
285
         * @return javax.swing.JButton        
286
         */
287
        public JButton getBApply() {
288
                if (bApply == null) {
289
                        bApply = new JButton(Messages.getText("aplicar"));
290
                }
291
                return bApply;
292
        }
293

    
294
        /**
295
         * This method initializes bCancel        
296
         *         
297
         * @return javax.swing.JButton        
298
         */
299
        public JButton getBCancel() {
300
                if (bCancel == null) {
301
                        bCancel = new JButton(Messages.getText("cancelar"));
302
                }
303
                return bCancel;
304
        }
305
        
306
        /**
307
         * This method initializes bSave        
308
         *         
309
         * @return javax.swing.JButton        
310
         */
311
        public JButton getBSave() {
312
                if (bSave == null) {
313
                        bSave = new JButton(Messages.getText("salvar"));
314
                }
315
                return bSave;
316
        }
317

    
318
        /**
319
         * Asigna el tama?o del componente
320
         * @param w Nuevo ancho del componente padre
321
         * @param h Nuevo alto del componente padre
322
         */
323
        public void setComponentSize(int w, int h){
324
                this.width = w;
325
                this.height = h;
326
                this.setSize(w, h);
327
                this.setPreferredSize(new java.awt.Dimension(w, h));
328
                this.getPMain().setPreferredSize(new java.awt.Dimension(w, h));
329
                this.getPNorth().setPreferredSize(new java.awt.Dimension(w, h - HBUTTONS));
330
                this.getPSelect().setPreferredSize(new java.awt.Dimension(width, HSELECT));
331
                this.getPTable().setComponentSize(width -MARGIN, height - HSELECT - HOPTIONS - HBUTTONS - MARGIN);
332
                this.getPOptions().setPreferredSize(new java.awt.Dimension(width, HOPTIONS));
333
                this.getPButtons().setPreferredSize(new java.awt.Dimension(width, HBUTTONS));
334
        }
335

    
336
        /**
337
         * This method initializes jCheckBox        
338
         *         
339
         * @return javax.swing.JCheckBox        
340
         */
341
        public JCheckBox getCActive() {
342
                if (cActive == null) {
343
                        cActive = new JCheckBox();
344
                        cActive.setText(Messages.getText("activar"));
345
                        cActive.setPreferredSize(new java.awt.Dimension(180,23));
346
                        cActive.addActionListener(listener);
347
                        cActive.setSelected(true);
348
                }
349
                return cActive;
350
        }
351

    
352
        /**
353
         * This method initializes jComboBox        
354
         *         
355
         * @return javax.swing.JComboBox        
356
         */
357
        public JComboBox getCbList() {
358
                if (cbList == null) {
359
                        cbList = new JComboBox();
360
                }
361
                return cbList;
362
        }
363

    
364
        /**
365
         * This method initializes jCheckBox        
366
         *         
367
         * @return javax.swing.JCheckBox        
368
         */
369
        public JCheckBox getCbInterpolar() {
370
                if (cbInterpolar == null) {
371
                        cbInterpolar = new JCheckBox();
372
                        cbInterpolar.setText(Messages.getText("interpolar"));
373
                }
374
                return cbInterpolar;
375
        }
376
        
377
        //----------------------------------------------------------------
378
        //M?TODOS DEL CONTROL
379
        
380
        /**
381
         * Convierte la tabla en un array de objetos para poder crear con el el objeto Palette
382
         * @return 
383
         * @throws NotInitializeException
384
         */
385
        public Object[][] getTablePalette() throws NotInitializeException{
386
                int cols = 6;
387
                if(getPTable().getRowCount() <= 0)
388
                        return null;
389
                Object[][] pal = new Object[getPTable().getRowCount()][cols];
390
                TableButtonModel model = (TableButtonModel)getPTable().getModel();
391
                for(int iRow = 0; iRow < getPTable().getRowCount(); iRow ++){
392
                        pal[iRow][0] = model.getValueAt(iRow, 1);
393
                        String[] rgb = ((String)model.getValueAt(iRow, 2)).split(",");
394
                        pal[iRow][1] = Integer.valueOf(rgb[0]);
395
                        pal[iRow][2] = Integer.valueOf(rgb[1]);
396
                        pal[iRow][3] = Integer.valueOf(rgb[2]);
397
                        pal[iRow][4] = Double.valueOf((String)model.getValueAt(iRow, 3));
398
                        pal[iRow][5] = Integer.valueOf((String)model.getValueAt(iRow, 4));
399
                }
400
                return pal;
401
        }
402
        
403
        /**
404
         * Carga la tabla de datos desde un objeto Palette. 
405
         * @param pal
406
         */
407
        public void loadPanelFromPalette(Palette pal){
408
                deleteAllRows();
409
                int[] paleta = pal.getPalette();
410
                String[] names = pal.getNameClass();
411
                
412
                //Obtenemos los datos de la clase paleta para construir cada fila de la tabla        
413
                for(int iEntry = 0; iEntry < paleta.length; iEntry ++){
414
                        int[] argb = Utilities.getARGBFromIntToIntArray(paleta[iEntry]);
415
                        Color color = new Color(argb[0], argb[1], argb[2]);
416
                                                
417
                        if(        pal.getType() == RasterBuf.TYPE_BYTE | 
418
                                pal.getType() == RasterBuf.TYPE_SHORT | 
419
                                pal.getType() == RasterBuf.TYPE_INT){
420
                                int[] range = pal.getIntRange();
421
                                addRowToTable(color, names[iEntry], range[iEntry]+"", String.valueOf(argb[3]));
422
                        }else if(        pal.getType() == RasterBuf.TYPE_FLOAT | 
423
                                                pal.getType() == RasterBuf.TYPE_DOUBLE ){
424
                                double[] range = pal.getDoubleRange();
425
                                addRowToTable(color, names[iEntry], range[iEntry]+"", String.valueOf(argb[3]));
426
                        }        
427
                }
428
        }
429
        
430
        /**
431
         * A?ade una fila a la tabla asignando el color por par?metro. Este
432
         * color asignado ser? el que aparezca en el bot?n y en el texto RGB
433
         * @param color 
434
         */
435
        public void addRowToTable(Color color, String name, String range, String alpha){
436
                getBSave().setEnabled(true);
437
        
438
                try {
439
                        getPTable().addRow(new Object[]{color, name, color.getRed()+","+color.getGreen()+","+color.getBlue(), range, alpha});
440
                } catch (NotInitializeException e1) {
441
                        return;
442
                }
443
        
444
        }
445
        
446
        /**
447
         * Asigna valores a una fila de la tabla
448
         * @param row fila de la tabla a asignar valores
449
         * @param color Color del bot?n y RGB
450
         * @param name Nombre de la clase
451
         * @param range Valor de la entrada
452
         * @param alpha Valor de la transparencia
453
         */
454
        public void setValues(int row, Color color, String name, String range, String alpha){
455
                TableButtonModel model = (TableButtonModel)getPTable().getModel();
456

    
457
                model.setValueAt(color, row, 0);
458
                model.setValueAt(name, row, 1);
459
                model.setValueAt(color.getRed()+","+color.getGreen()+","+color.getBlue(), row, 2);
460
                model.setValueAt(range, row, 3);
461
                model.setValueAt(alpha, row, 4);
462
        }
463
        
464
        /**
465
         * Elimina la fila seleccionada de la tabla
466
         */
467
        public void deleteSelectedRow(){
468
                int index = 0;
469
                try {
470
                        index = getPTable().getSelectedIndex();
471
                        getPTable().delRow(index);
472
                        if(getPTable().getRowCount() == 0)
473
                                getBSave().setEnabled(false);
474
                } catch (NotInitializeException e1) {
475
                        return;
476
                }
477
        }
478
        
479
        /**
480
         * Elimina todas las filas de la tabla
481
         */
482
        public void deleteAllRows(){
483
                try {
484
                        getPTable().removeAllRows();
485
                } catch (NotInitializeException e1) {
486
                        return;
487
                }
488
                getBSave().setEnabled(false);
489
        }
490
        
491
        /**
492
         * Obtiene el indice de la fila seleccionada
493
         * @return Indice de la fila
494
         */
495
        public int getSelectedIndex(){
496
                 try {
497
                        return getPTable().getSelectedIndex();
498
                } catch (NotInitializeException e) {
499
                        return -1;
500
                }
501
        }
502
        
503
        /**
504
         * Obtiene el valor del alpha de la fila seleccionada en la tabla
505
         * @return Entero que representa el alpha 
506
         */
507
        public int getAlpha(){
508
                TableButtonModel model = (TableButtonModel)getPTable().getModel();
509
                String value;
510
                try {
511
                        value = ((JButton)model.getValueAt(getPTable().getSelectedIndex(), 4)).getText();
512
                        return Integer.valueOf(value).intValue();
513
                } catch (NotInitializeException e) {
514
                        return -1;
515
                } catch (NumberFormatException e) {
516
                        return -1;
517
                }
518
        }
519
        
520
        /**
521
         * Ordena las filas de la paleta de color con valores decrecientes de rango. En las primeras
522
         * filas coloca los valores mayores y en la ?ltima los menores. Esta funci?n es utilizada
523
         * cada vez que se da aplicar o aceptar ya que es necesario cuando se pasa el filtro que los
524
         * valores esten ordenados.
525
         */
526
        public void orderRows(){
527
                class Row{
528
                        public String name = null;
529
                        public Color rgb = null;
530
                        public String value = null;
531
                        public String alpha = null;
532
                }
533
                
534
                try {
535
                        Row row = null;
536
                        Hashtable map = new Hashtable(); 
537
                        TableButtonModel model = (TableButtonModel)getPTable().getModel();
538
                        
539
                        //Comprobamos que el tipo de datos sea igual para todas las filas.
540
                        boolean intType = true;
541
                        for(int iRow = 0; iRow < getPTable().getRowCount(); iRow ++){
542
                                try{
543
                                        Integer.valueOf((String)model.getValueAt(iRow, 3));
544
                                }catch(NumberFormatException exc){
545
                                        //Si alguno de los datos da un formatException es que no es entero por lo
546
                                        //que suponemos que es decimal. Ojo!, ya se ha validado que sea numerico
547
                                        intType = false;
548
                                }
549
                        }
550
                                
551
                        double[] doubleRange = null;
552
                        int[] intRange = null;
553
                        if(intType)
554
                                intRange = new int[getPTable().getRowCount()];
555
                        else
556
                                doubleRange = new double[getPTable().getRowCount()];
557
                        
558
                        int lenght = getPTable().getRowCount();
559
                        
560
                        //Cargamos las filas en un treemap cuya clave es el rango
561
                        for(int iRow = 0; iRow < lenght; iRow ++){
562
                                row = new Row();
563
                                row.name = (String)model.getValueAt(iRow, 1);
564
                                row.rgb = (Color)model.getValueAt(iRow, 0);
565
                                row.value = (String)model.getValueAt(iRow, 3);
566
                                row.alpha = (String)model.getValueAt(iRow, 4);
567
                                if(intType){                
568
                                        intRange[iRow] = Integer.valueOf(row.value).intValue();
569
                                        map.put(intRange[iRow]+" ", row);
570
                                }else{
571
                                        doubleRange[iRow] = Double.valueOf(row.value).intValue();
572
                                        map.put(doubleRange[iRow]+" ", row);
573
                                }
574
                        }
575
                                                
576
                        //Ordenamos la lista por el valor del rango
577
                        if(intType)
578
                                Arrays.sort(intRange);
579
                        else
580
                                Arrays.sort(doubleRange);
581
                                                
582
                        int rowAssigned = lenght - 1;
583
                        for(int iRow = 0; iRow < lenght; iRow ++){
584
                                if(intType)
585
                                        row = (Row)map.get(intRange[iRow]+" ");
586
                                else
587
                                        row = (Row)map.get(doubleRange[iRow]+" ");
588
                                setValues(rowAssigned, row.rgb, row.name, row.value, row.alpha);
589
                                rowAssigned --;
590
                        }
591
                } catch (NotInitializeException e) {
592
                        // TODO Auto-generated catch block
593
                        e.printStackTrace();
594
                }
595
        }
596
        
597
        /**
598
         * Carga en el listBox de paletas predefinidas los nombres que hay en la cabecera del fichero 
599
         * de paletas predefinidas.
600
         * 
601
         * @param palettesPath Camino al ficher de paletas predefinidas.
602
         * 
603
         */
604
        public void loadPaletteList(String palettesPath){
605
                
606
                File palettesFile = new File(palettesPath);
607
                if(!palettesFile.exists())
608
                        return;
609
                
610
                ArrayList nameList = new ArrayList();
611
                
612
                try {
613
                        KXmlParser parser = new KXmlParser();
614
                        FileInputStream fileInputStream = new FileInputStream(palettesPath);
615
                        parser.setInput(fileInputStream, null);
616
                        int tag = parser.nextTag();
617
                        parser.require(KXmlParser.START_TAG, null, "palettes");
618
                        tag = parser.nextTag();
619
                        parser.require(KXmlParser.START_TAG, null, "palette_list");
620
                                        
621
                        tag = parser.nextTag();
622
                        while (tag == KXmlParser.START_TAG){
623
                                parser.require(KXmlParser.START_TAG, null, "name");
624
                                nameList.add(parser.nextText());
625
                                parser.require(KXmlParser.END_TAG, null, "name");
626
                                tag = parser.nextTag();
627
                        }
628
                        parser.require(KXmlParser.END_TAG, null, "palette_list");
629
                        
630
                        getCbList().removeAllItems();                           //
631
                        for (int i = 0; i<nameList.size(); i++)    // Solo se a?aden elementos al combo si se ha leido la lista 
632
                                getCbList().addItem(nameList.get(i));  // completa de nombres de paleta sin errores.
633
                        fileInputStream.close();
634
                        return;
635
                        
636
                        
637
                }catch (FileNotFoundException fnfEx) {
638
                        fnfEx.printStackTrace();
639
                }catch (XmlPullParserException xmlEx) {
640
                        System.out.println("El fichero de paletas predeterminadas no tiene la estructura correcta:\n        " + xmlEx.getMessage());
641
                }catch (IOException e) {
642
                }
643
        }
644

    
645
        public String getPalettesPath() {
646
                return palettesPath;
647
        }
648

    
649
        /**
650
         * Obtiene el listener
651
         * @return PalettePanelListener
652
         */
653
        public PalettePanelListener getListener() {
654
                return listener;
655
        }
656
        
657
        /**
658
         * Activar o desactivar los componentes del panel
659
         */
660
        public void setEnabled(boolean enabled){
661
                getCbList().setEnabled(enabled);
662
                getCbInterpolar().setEnabled(enabled);
663
                getPTable().setEnabled(enabled);
664
        }
665
        
666
        /**
667
         * Funci?n que informa de si est? acivo o no la selecci?n de paleta en el panel
668
         * @return true si est? activo y false si no lo est?.
669
         */
670
        public boolean isActivePanel(){
671
                return this.getCActive().isSelected();
672
        }
673
}  //  @jve:decl-index=0:visual-constraint="10,10"
674