Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / BandSelectorPanel.java @ 18278

History | View | Annotate | Download (20.9 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.rastertools.properties.panels;
20

    
21
import java.awt.Dimension;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.ComponentEvent;
26
import java.awt.image.DataBuffer;
27
import java.io.File;
28
import java.util.ArrayList;
29

    
30
import javax.swing.JButton;
31
import javax.swing.JComboBox;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.event.TableModelEvent;
35
import javax.swing.event.TableModelListener;
36
import javax.swing.table.DefaultTableModel;
37

    
38
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
39
import org.gvsig.fmap.raster.layers.IRasterLayerActions;
40
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
41
import org.gvsig.gui.beans.table.TableContainer;
42
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
43
import org.gvsig.raster.dataset.IRasterDataSource;
44
import org.gvsig.raster.dataset.RasterDataset;
45
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
46
import org.gvsig.raster.datastruct.Transparency;
47
import org.gvsig.raster.grid.GridTransparency;
48
import org.gvsig.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry;
49
import org.gvsig.raster.hierarchy.IRasterDataset;
50
import org.gvsig.raster.hierarchy.IRasterProperties;
51
import org.gvsig.raster.hierarchy.IRasterRendering;
52
import org.gvsig.raster.util.RasterToolsUtil;
53
import org.gvsig.rastertools.properties.control.BandSelectorListener;
54

    
55
import com.iver.andami.PluginServices;
56
import com.iver.cit.gvsig.fmap.layers.FLayer;
57
/**
58
 * Selecciona las bandas visibles en un raster. Contiene una tabla con una fila
59
 * por cada banda de la imagen. Por medio de checkbox se selecciona para cada
60
 * RGB que banda de la imagen ser? visualizada.
61
 *
62

63
 * @author Nacho Brodin (brodin_ign@gva.es)
64
 */
65
public class BandSelectorPanel extends AbstractPanel implements TableModelListener {
66
        final private static long       serialVersionUID = -3370601314380922368L;
67

    
68
        private final String[]          columnNames       = { "A", "R", "G", "B", "Band" };
69
        private final int[]             columnWidths      = { 22, 22, 22, 22, 334 };
70

    
71
        FLayer                          fLayer = null;
72

    
73
        private BandSelectorFileList    fileList          = null;
74

    
75
        // Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo
76
        private int[]                   col               = { 0, 1 };
77
        private BandSelectorListener    panelListener     = null;
78
        private IRasterProperties       prop              = null;
79
        private IRasterDataset          dataset           = null;
80
        private IRasterRendering        render            = null;
81
        private TableContainer          table             = null;
82
        private JButton                 saveButton        = null;
83

    
84
        private JPanel                  buttonsPanel      = null;
85
        private JComboBox                        jComboBox = null;
86

    
87
        /**
88
         * This method initializes
89
         */
90
        public BandSelectorPanel() {
91
                super();
92
                panelListener = new BandSelectorListener(this);
93
                initialize();
94
        }
95

    
96
        /**
97
         * This method initializes this
98
         *
99
         * @return void
100
         */
101
        protected void initialize() {
102
                GridBagConstraints gbc = new GridBagConstraints();
103
                setLayout(new GridBagLayout());
104
                gbc.insets = new Insets(0, 0, 0, 0);
105
                gbc.fill = GridBagConstraints.BOTH;
106
                
107
                gbc.weightx = 1.0;
108
                gbc.weighty = 1.0;
109
                add(getFileList(), gbc);
110
                
111
                gbc.gridy = 1;
112
                add(getARGBTable(), gbc);
113
                
114
                gbc.weighty = 0;
115
                gbc.gridy = 2;
116
                gbc.fill = GridBagConstraints.EAST;
117
                gbc.anchor = GridBagConstraints.EAST;
118
                gbc.insets = new Insets(0, 0, 0, 8);
119
                add(getButtonsPanel(), gbc);
120
                
121
                this.setPreferredSize(new Dimension(100, 80)); 
122
                super.setLabel(PluginServices.getText(this, "bands_panel"));
123
        }
124
        
125
        /**
126
         * Obtiene el panel que contiene la lista de ficheros por banda.
127
         * @return Panel FileList
128
         */
129
        public BandSelectorFileList getFileList() {
130
                if (fileList == null) 
131
                        fileList = new BandSelectorFileList();
132
                return fileList;
133
        }
134
        
135
        /**
136
         * Obtiene la Tabla
137
         * @return Tabla de bandas de la imagen
138
         */
139
        public TableContainer getARGBTable() {
140
                if (table == null) {
141
                        ArrayList listeners = new ArrayList();
142
                        listeners.add(panelListener);
143
                        table = new TableContainer(columnNames, columnWidths, listeners);
144
                        table.setModel("ARGBBandSelectorModel");
145
                        table.setControlVisible(false);
146
                        table.getModel().addTableModelListener(this);
147
                        table.initialize();
148
                }
149
                return table;
150
        }
151
        
152
        /**
153
         * Obtiene el Panel con bot?n de salvado y selector de bandas. 
154
         * @return JPanel
155
         */
156
        public JPanel getButtonsPanel() {
157
                if(buttonsPanel == null) {
158
                        buttonsPanel = new JPanel();
159
                        GridBagConstraints gbc = new GridBagConstraints();
160
                        buttonsPanel.setLayout(new GridBagLayout());
161
                        gbc.insets = new Insets(0, 8, 0, 0);
162
                        gbc.fill = GridBagConstraints.BOTH;
163
                        gbc.weightx = 1.0;
164
                        JLabel lbandasVisibles = new JLabel();
165
                        lbandasVisibles.setText("Bandas");
166
                        buttonsPanel.add(lbandasVisibles, gbc);
167
                        gbc.gridx = 1;
168
                        buttonsPanel.add(getNumBandSelectorCombo(), gbc);
169
                        gbc.gridx = 2;
170
                        buttonsPanel.add(getSaveButton(), gbc);
171
                }
172
                return buttonsPanel;
173
        }
174
        
175
        /**
176
         * Obtiene el combo del selector del n?mero de bandas
177
         * @return JComboBox
178
         */
179
        public JComboBox getNumBandSelectorCombo() {
180
                if (jComboBox == null) {
181
                        String[] list = { "1", "2", "3" };
182
                        jComboBox = new JComboBox(list);
183
                        jComboBox.setSelectedIndex(2);
184
                        jComboBox.setPreferredSize(new java.awt.Dimension(36, 25));
185
                }
186

    
187
                return jComboBox;
188
        }
189
        
190
        /**
191
         * Bot?n de salvar la interpretaci?n de color seleccionada como predeterminada en 
192
         * la capa
193
         * @return JButton
194
         */
195
        public JButton getSaveButton() {
196
                if(saveButton == null) {
197
                        saveButton = new JButton(RasterToolsUtil.getText(this, "save"));
198
                        saveButton.setToolTipText(RasterToolsUtil.getText(this, "save_color_interpretation"));
199
                        saveButton.addActionListener(panelListener);
200
                }
201
                return saveButton;
202
        }
203
        
204
        /**
205
         * A?ade la lista de georasterfiles a la tabla
206
         *
207
         * @param files
208
         * @throws NotInitializeException 
209
         */
210
        public void addFiles(IRasterDataSource mDataset) throws NotInitializeException {
211
                getFileList().clear();
212
                clear();
213
                for (int i = 0; i < mDataset.getDatasetCount(); i++) {
214
                        String fName = mDataset.getDataset(i)[0].getFName();
215
                        getFileList().addFName(fName);
216

    
217
                        String bandName = new File(fName).getName();
218
                        String bandType = "";
219

    
220
                        switch (mDataset.getDataset(i)[0].getDataType()[0]) {
221
                        case DataBuffer.TYPE_BYTE:
222
                                bandType = "8U";
223
                                break;
224
                        case DataBuffer.TYPE_INT:
225
                                bandType = "32";
226
                                break;
227
                        case DataBuffer.TYPE_DOUBLE:
228
                                bandType = "64";
229
                                break;
230
                        case DataBuffer.TYPE_FLOAT:
231
                                bandType = "32";
232
                                break;
233
                        case DataBuffer.TYPE_SHORT:
234
                                bandType = "16";
235
                                break;
236
                        case DataBuffer.TYPE_USHORT:
237
                                bandType = "16U";
238
                                break;
239
                        case DataBuffer.TYPE_UNDEFINED:
240
                                bandType = "??";
241
                                break;
242
                        }
243

    
244
                        for (int b = 0; b < mDataset.getDataset(i)[0].getBandCount(); b++)
245
                                addBand((b + 1) + " [" + bandType + "] " + bandName);
246
                }
247
                readDrawedBands();
248
                saveStatus();
249
                evaluateControlsEnabled();
250
        }
251

    
252
        /**
253
         * Elimina un fichero de la lista
254
         * @param file Nombre del fichero a eliminar
255
         */
256
        public void removeFile(String file) {
257
                getFileList().removeFName(file);
258

    
259
                for (int i = 0; i < ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); i++) {
260
                        // Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
261
                        // esta visibilidad a la banda inmediata superior y si esta acci?n produce
262
                        // una excepci?n (porque no hay) se pasa al inmediato inferior.
263
                        if (((String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 4)).endsWith(file)) {
264
                                try {
265
                                        if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 0)).booleanValue()) {
266
                                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1);
267
                                        }
268
                                } catch (ArrayIndexOutOfBoundsException exc) {
269
                                        ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1);
270
                                }
271

    
272
                                try {
273
                                        if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 1)).booleanValue()) {
274
                                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2);
275
                                        }
276
                                } catch (ArrayIndexOutOfBoundsException exc) {
277
                                        ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2);
278
                                }
279

    
280
                                try {
281
                                        if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 2)).booleanValue()) {
282
                                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 3);
283
                                        }
284
                                } catch (ArrayIndexOutOfBoundsException exc) {
285
                                        ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 3);
286
                                }
287

    
288
                                ((DefaultTableModel) getARGBTable().getModel()).removeRow(i);
289
                                i--; // Ojo! que hemos eliminado una fila
290
                        }
291
                }
292
                panelListener.setNewBandsPositionInRendering();
293
                evaluateControlsEnabled();
294
        }
295
        
296
        /**
297
         * Evalua la habilitaci?n o desabilitaci?n de controles
298
         */
299
        public void evaluateControlsEnabled() {
300
                if(getFileList().getNFiles() > 1)
301
                        getSaveButton().setEnabled(false);
302
                else
303
                        getSaveButton().setEnabled(true);
304
        }
305

    
306
        /**
307
         * Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
308
         * debemos resetear la tabla de checkbox para que no haya activados m?s de los
309
         * permitidos
310
         * @param mode
311
         */
312
        public void resetMode(int mode) {
313
                // Reseteamos los checkbox
314
                for (int i = 0; i < (getARGBTable().getModel().getColumnCount() - 1); i++)
315
                        for (int j = 0; j < getARGBTable().getModel().getRowCount(); j++)
316
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(false), j, i);
317

    
318
                // Asignamos los valores
319
                if (this.getNBands() >= 3) {
320
                        switch (mode) {
321
                        case 3:
322
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 2, 3);
323
                        case 2:
324
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 1, 2);
325
                        case 1:
326
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 0, 1);
327
                        }
328
                } else if (this.getNBands() == 2) {
329
                        switch (mode) {
330
                        case 3:
331
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 1, 3);
332
                        case 2:
333
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 1, 2);
334
                        case 1:
335
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 0, 1);
336
                        }
337
                } else if (this.getNBands() == 1) {
338
                        switch (mode) {
339
                        case 3:
340
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 0, 3);
341
                        case 2:
342
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 0, 2);
343
                        case 1:
344
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), 0, 1);
345
                        }
346
                }
347

    
348
                col[0] = 0;
349
                col[1] = 1;
350
        }
351

    
352
        /**
353
         * A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
354
         * valor a los checkbox
355
         * @param bandName Nombre de la banda
356
         * @throws NotInitializeException 
357
         */
358
        private void addBand(String bandName) throws NotInitializeException {
359
                Object[] row = {        new Boolean(false), 
360
                                                        new Boolean(false), 
361
                                                        new Boolean(false), 
362
                                                        new Boolean(false), 
363
                                                        bandName };
364
                getARGBTable().addRow(row);
365
        }
366

    
367
        /**
368
         * Elimina todas las entradas de la tabla de bandas.
369
         */
370
        private void clear() {
371
                int rows = ((DefaultTableModel) getARGBTable().getModel()).getRowCount();
372
                if (rows > 0) {
373
                        for (int i = 0; i < rows; i++)
374
                                ((DefaultTableModel) getARGBTable().getModel()).removeRow(0);
375
                }
376
        }
377

    
378
        /**
379
         * Obtiene el n?mero de bandas de la lista
380
         *
381
         * @return
382
         */
383
        public int getNBands() {
384
                return ((DefaultTableModel) getARGBTable().getModel()).getRowCount();
385
        }
386

    
387
        /**
388
         * Obtiene el nombre de la banda de la posici?n i de la tabla
389
         *
390
         * @param i
391
         * @return
392
         */
393
        public String getBandName(int i) {
394
                String s = (String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 3);
395
                return s.substring(s.lastIndexOf("[8U]") + 5, s.length());
396
        }
397

    
398
        /**
399
         * Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
400
         * corresponde
401
         *
402
         * @param nBand Banda de la imagen que corresponde
403
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
404
         */
405
        public void assignBand(int nBand, int flag) {
406
                Boolean t = new Boolean(true);
407
                try {
408
                        if ((flag & RasterDataset.ALPHA_BAND) == RasterDataset.ALPHA_BAND)
409
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 0);
410
                        
411
                        if ((flag & RasterDataset.RED_BAND) == RasterDataset.RED_BAND)
412
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 1);
413

    
414
                        if ((flag & RasterDataset.GREEN_BAND) == RasterDataset.GREEN_BAND)
415
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 2);
416

    
417
                        if ((flag & RasterDataset.BLUE_BAND) == RasterDataset.BLUE_BAND)
418
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 3);
419
                } catch (ArrayIndexOutOfBoundsException e) {
420

    
421
                }
422
        }
423

    
424
        /**
425
         * Obtiene la correspondencia entre el R, G o B y la banda asignada
426
         *
427
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
428
         * @return Banda de la imagen asignada al flag pasado por par?metro
429
         */
430
        public int getAssignedBand(int flag) {
431
                DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel());
432
                if ((flag & RasterDataset.ALPHA_BAND) == RasterDataset.ALPHA_BAND) {
433
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
434
                                if (((Boolean) model.getValueAt(nBand, 0)).booleanValue())
435
                                        return nBand;
436
                }
437
                
438
                if ((flag & RasterDataset.RED_BAND) == RasterDataset.RED_BAND) {
439
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
440
                                if (((Boolean) model.getValueAt(nBand, 1)).booleanValue())
441
                                        return nBand;
442
                }
443

    
444
                if ((flag & RasterDataset.GREEN_BAND) == RasterDataset.GREEN_BAND) {
445
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
446
                                if (((Boolean) model.getValueAt(nBand, 2)).booleanValue())
447
                                        return nBand;
448
                }
449

    
450
                if ((flag & RasterDataset.BLUE_BAND) == RasterDataset.BLUE_BAND) {
451
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
452
                                if (((Boolean) model.getValueAt(nBand, 3)).booleanValue())
453
                                        return nBand;
454
                }
455

    
456
                return -1;
457
        }
458

    
459
        /**
460
         * Obtiene la interpretaci?n de color por n?mero de banda
461
         * @param nBand N?mero de banda
462
         * @return Interpretaci?n de color. Constante definida en DatasetColorInterpretation
463
         */
464
        public String getColorInterpretationByBand(int nBand) {
465
                DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel());
466
                try {
467
                        for (int iBand = 0; iBand < getARGBTable().getRowCount(); iBand++) {
468
                                for (int col = 0; col < 4; col++) {
469
                                        if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) {
470
                                                switch (col) {
471
                                                case 0: return DatasetColorInterpretation.ALPHA_BAND; 
472
                                                case 1: return DatasetColorInterpretation.RED_BAND; 
473
                                                case 2: return DatasetColorInterpretation.GREEN_BAND;
474
                                                case 3: return DatasetColorInterpretation.BLUE_BAND; 
475
                                                }
476
                                        }
477
                                }        
478
                        }
479
                } catch (NotInitializeException e) {
480
                        RasterToolsUtil.messageBoxError("table_not_initialize", this);
481
                }
482
                return DatasetColorInterpretation.UNDEF_BAND;
483
        }
484
        
485
        /*
486
         * (non-Javadoc)
487
         * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
488
         */
489
        public void tableChanged(TableModelEvent e) {
490
                getARGBTable().revalidate();
491
                revalidate();
492
        }
493

    
494

    
495
        /**
496
         * Activa o desactiva la funcionalidad
497
         */
498
        private void actionEnabled() {
499
                boolean enabled = true;
500

    
501
                FLyrRasterSE fLyrRasterSE = ((FLyrRasterSE) fLayer);
502

    
503
                if (!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST))
504
                        enabled = false;
505
                getFileList().setEnabled(enabled);
506

    
507
                enabled = true;
508
                if (!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_RGB))
509
                        enabled = false;
510
                getARGBTable().setEnabled(enabled);
511

    
512
                // TODO: Mirar el setVisible...
513
                if (!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST) &&
514
                                !fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_RGB))
515
                        setVisible(false);
516
                else
517
                        setVisible(true);
518
        }
519

    
520
        /**
521
         * Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho.
522
         */
523
        public void readDrawedBands() {
524
                if (prop.getRender() != null) {
525
                        int[] renderBands = render.getRenderBands();
526
                        GridTransparency transp = render.getRenderTransparency();
527
                        if(transp != null && transp.isTransparencyActive() && transp.getAlphaBandNumber() != -1)
528
                                this.assignBand(transp.getAlphaBandNumber(), RasterDataset.ALPHA_BAND);
529
                        for (int i = 0; i < renderBands.length; i++) {
530
                                if (renderBands[i] >= 0) {
531
                                        switch (i) {
532
                                        case 0:
533
                                                this.assignBand(renderBands[i], RasterDataset.RED_BAND);
534
                                                break;
535
                                        case 1:
536
                                                this.assignBand(renderBands[i], RasterDataset.GREEN_BAND);
537
                                                break;
538
                                        case 2:
539
                                                this.assignBand(renderBands[i], RasterDataset.BLUE_BAND);
540
                                                break;
541
                                        }
542
                                }
543
                        }
544
                }
545
        }
546

    
547
        /*
548
         * (non-Javadoc)
549
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
550
         */
551
        public void accept() {
552
                if (!getPanelGroup().isPanelInGUI(this))
553
                        return;
554

    
555
                onlyApply();
556
        }
557

    
558
        /**
559
         * Aplica y guarda los cambios del panel
560
         */
561
        public void apply() {
562
                if (!getPanelGroup().isPanelInGUI(this))
563
                        return;
564

    
565
                onlyApply();
566
                saveStatus();
567
        }
568

    
569
        /**
570
         * Aplicar los cambios sin guardar su estado
571
         */
572
        public void onlyApply() {
573
                if (RasterPropertiesTocMenuEntry.enableEvents)
574
                        panelListener.apply();
575
        }
576

    
577
        /**
578
         * Guarda el estado actual del panel
579
         */
580
        private void saveStatus() {
581
                ArrayList aux = new ArrayList();
582
                int[] renderBands = render.getRenderBands();
583
                for (int i = 0; i < renderBands.length; i++) {
584
                        aux.add(new Integer(renderBands[i]));
585
                }
586
                int alphaBand = render.getRenderTransparency().getAlphaBandNumber();
587
                getPanelGroup().getProperties().put("alphaBand", new Integer(alphaBand));
588
                getPanelGroup().getProperties().put("renderBands", aux);
589
        }
590

    
591

    
592
        /**
593
         * Deja la capa en el ?ltimo estado guardado y la refresca
594
         */
595
        public void restoreStatus() {
596

    
597
                ArrayList aux = (ArrayList) getPanelGroup().getProperties().get("renderBands");
598
                Integer alphaBand = (Integer) getPanelGroup().getProperties().get("alphaBand");
599
                
600
                int[] renderBands = new int[aux.size()];
601
                for (int i = 0; i < aux.size(); i++)
602
                        renderBands[i] = ((Integer) aux.get(i)).intValue();
603

    
604
                render.setRenderBands(renderBands);
605
                //Transparencia del dataset
606
                Transparency t = ((FLyrRasterSE)fLayer).getDataSource().getTransparencyFilesStatus();
607
                //Ultima transparencia aplicada en el renderizador
608
                GridTransparency gt = render.getRenderTransparency();
609
                if(alphaBand != null) {
610
                        if(gt != null) 
611
                                gt.setTransparencyBand(alphaBand.intValue());
612
                        if(t != null)
613
                                t.setTransparencyBand(alphaBand.intValue());
614
                }
615

    
616
                if (fLayer != null)
617
                        fLayer.getMapContext().invalidate();
618
        }
619

    
620
        /*
621
         * (non-Javadoc)
622
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
623
         */
624
        public void cancel() {
625
                if (!getPanelGroup().isPanelInGUI(this))
626
                        return;
627

    
628
                restoreStatus();
629
        }
630

    
631
        /**
632
         * Activa y desactiva el control
633
         * @param enabled true para activar y false para desactivar
634
         */
635
        public void setEnabled(boolean enabled) {
636
                if (panelListener != null)
637
                        panelListener.setEnabledPanelAction(enabled);
638
                getARGBTable().setEnabled(enabled);
639
                getFileList().setEnabled(enabled);
640
        }
641
        
642
        /*
643
         * (non-Javadoc)
644
         * @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
645
         */
646
        public void setReference(Object ref) {
647
                super.setReference(ref);
648

    
649
                if (!(ref instanceof FLayer))
650
                        return;
651

    
652
                fLayer = (FLayer) ref;
653

    
654
                actionEnabled();
655

    
656
                clear();
657
                getFileList().clear();
658

    
659
                if (fLayer instanceof IRasterProperties)
660
                        prop = (IRasterProperties) fLayer;
661

    
662
                //Si tiene tabla de color inicializamos solamente
663
                if (fLayer instanceof IRasterRendering) {
664
                        render = (IRasterRendering)fLayer;
665
                        if (((IRasterRendering) fLayer).existColorTable()) {
666
                                panelListener.init(null, null, fLayer);
667
                                return;
668
                        }
669
                }
670

    
671
                //Si no tiene tabla de color se a?aden los ficheros e inicializamos
672
                if (fLayer instanceof IRasterDataset) {
673
                        dataset = (IRasterDataset) fLayer;
674
                        try {
675
                                addFiles(dataset.getDataSource());
676
                        } catch (NotInitializeException e) {
677
                                RasterToolsUtil.messageBoxError("table_not_initialize", this);
678
                        }
679
                }
680

    
681
                panelListener.init(dataset, prop, fLayer);
682
        }
683

    
684
        public void componentHidden(ComponentEvent e) {}
685
        public void componentShown(ComponentEvent e) {}
686
        public void componentMoved(ComponentEvent e) {}
687
        public void selected() {}
688
}