Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / BandSetupPanel.java @ 12383

History | View | Annotate | Download (21.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.Component;
22
import java.awt.Dimension;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
25
import java.awt.event.ComponentEvent;
26
import java.awt.event.ComponentListener;
27
import java.awt.image.DataBuffer;
28
import java.io.File;
29
import java.util.ArrayList;
30
import java.util.Vector;
31

    
32
import javax.swing.AbstractCellEditor;
33
import javax.swing.JPanel;
34
import javax.swing.JRadioButton;
35
import javax.swing.JScrollPane;
36
import javax.swing.JTable;
37
import javax.swing.SwingConstants;
38
import javax.swing.SwingUtilities;
39
import javax.swing.event.TableModelEvent;
40
import javax.swing.event.TableModelListener;
41
import javax.swing.table.DefaultTableModel;
42
import javax.swing.table.TableCellEditor;
43
import javax.swing.table.TableCellRenderer;
44
import javax.swing.table.TableColumn;
45

    
46
import org.gvsig.raster.dataset.MultiRasterDataset;
47
import org.gvsig.raster.dataset.RasterDataset;
48
import org.gvsig.raster.hierarchy.IRasterDataset;
49
import org.gvsig.raster.hierarchy.IRasterProperties;
50
import org.gvsig.raster.hierarchy.IRasterRendering;
51
import org.gvsig.rastertools.properties.control.BandSetupListener;
52
import org.gvsig.rastertools.properties.dialog.IRegistrablePanel;
53
import org.gvsig.rastertools.properties.dialog.RasterPropertiesTocMenuEntry;
54
import org.gvsig.rastertools.properties.dialog.RegistrableTabPanel;
55

    
56
import com.iver.andami.PluginServices;
57
import com.iver.cit.gvsig.fmap.layers.FLayer;
58
/**
59
 * Selecciona las bandas visibles en un raster. Contiene una tabla con una fila
60
 * por cada banda de la imagen. Por medio de checkbox se selecciona para cada
61
 * RGB que banda de la imagen ser? visualizada.
62
 * 
63
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
64
 * @author Nacho Brodin (brodin_ign@gva.es)
65
 */
66
public class BandSetupPanel extends JPanel implements TableModelListener, ComponentListener, IRegistrablePanel {
67
        final private static long serialVersionUID = -3370601314380922368L;
68

    
69
        /**
70
         * Variables para la asignaci?n de tama?o de los componentes del panel.
71
         */
72
        private int                                                wComp = 445, hComp = 239;
73
        private int                                                wFileList = wComp, hFileList = (int)Math.round(hComp * 0.46);
74
        private int                                                wBand = wFileList, hBand = hComp - hFileList - 20;
75

    
76
        /**
77
         * Asigna la banda del rojo
78
         */
79
        public static final int RED_BAND = RasterDataset.RED_BAND;
80

    
81
        /**
82
         * Asigna la banda del verde
83
         */
84
        public static final int GREEN_BAND = RasterDataset.GREEN_BAND;
85

    
86
        /**
87
         * Asigna banda del azul
88
         */
89
        public static final int BLUE_BAND = RasterDataset.BLUE_BAND;
90
        private final static String[]         columnNames = { "R", "G", "B", "Band" };
91

    
92
        FLayer fLayer = null;
93

    
94
        /**
95
         * Nombre del panel
96
         */
97
        private String                id                = "bands_panel";
98
        private BandSetupFileList     fileList          = null;
99
        private JTable                rgbTable          = null;
100
        private JScrollPane           rgbBandAssignPane = null;
101
        RGBBandAsignTableModel        tableModel        = null;
102
        private byte                  mode              = 3;
103
        // Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo
104
        private int[]                 col               = { 0, 1 };
105
        private BandSetupListener     panelListener     = null;
106
        private IRasterProperties     prop              = null;
107
        private IRasterDataset        dataset           = null;
108

    
109
        /**
110
         * This method initializes
111
         */
112
        public BandSetupPanel() {
113
                super();
114
                id = PluginServices.getText(this, id);
115
                initialize();
116
                panelListener = new BandSetupListener(this);
117
        }
118

    
119
        /**
120
         * This method initializes this
121
         *
122
         * @return void
123
         */
124
        void initialize() {
125
                // this.setPreferredSize(new Dimension(wComp, hComp));
126
                this.setLayout(null);
127
                this.setLocation(0, 0);
128
                this.add(getFileList(), null);
129
                this.add(getRGBBandAssignPane(), null);
130
                this.addComponentListener(this);
131
                this.setComponentSize(wComp, hComp);
132
        }
133

    
134
        /**
135
         * A?ade la lista de georasterfiles a la tabla
136
         *
137
         * @param files
138
         */
139
        public void addFiles(MultiRasterDataset mDataset) {
140
                getFileList().clear();
141
                clear();
142
                for (int i = 0; i < mDataset.getDatasetCount(); i++) {
143
                        String fName = mDataset.getDataset(i).getFName();
144
                        getFileList().addFName(fName);
145

    
146
                        String bandName = new File(fName).getName();
147
                        String bandType = "";
148

    
149
                        switch (mDataset.getDataset(i).getDataType()) {
150
                                case DataBuffer.TYPE_BYTE:
151
                                        bandType = "8U";
152
                                        break;
153
                                case DataBuffer.TYPE_INT:
154
                                        bandType = "32";
155
                                        break;
156
                                case DataBuffer.TYPE_DOUBLE:
157
                                        bandType = "64";
158
                                        break;
159
                                case DataBuffer.TYPE_FLOAT:
160
                                        bandType = "32";
161
                                        break;
162
                                case DataBuffer.TYPE_SHORT:
163
                                        bandType = "16";
164
                                        break;
165
                                case DataBuffer.TYPE_USHORT:
166
                                        bandType = "16U";
167
                                        break;
168
                                case DataBuffer.TYPE_UNDEFINED:
169
                                        bandType = "??";
170
                                        break;
171
                        }
172

    
173
                        for (int b = 0; b < mDataset.getDataset(i).getBandCount(); b++)
174
                                addBand((b + 1) + " [" + bandType + "] " + bandName);
175

    
176
/*
177
                        if (mDataset.getDataset(i).getBandCount() > 1) {
178
                                for (int b = 0; b < mDataset.getDataset(i).getBandCount(); b++)
179
                                        addBand((b + 1) + " [" + bandType + "] " + bandName);
180
                        } else {
181
                                addBand("1 [" + bandType + "] " + bandName);
182
                        }
183
*/
184
                }
185
                readDrawedBands();
186
                saveStatus();
187
        }
188

    
189
        /**
190
         * Elimina un fichero de la lista
191
         * @param file Nombre del fichero a eliminar
192
         */
193
        public void removeFile(String file) {
194
                getFileList().removeFName(file);
195

    
196
                for (int i = 0; i < ((DefaultTableModel) getRGBTable().getModel()).getRowCount(); i++) {
197
                        // Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
198
                        // esta visibilidad a la banda inmediata superior y si esta acci?n produce
199
                        // una excepci?n (porque no hay) se pasa al inmediato inferior.
200
                        if (((String) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 3)).endsWith(file)) {
201
                                try {
202
                                        if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 0)).booleanValue()) {
203
                                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 0);
204
                                        }
205
                                } catch (ArrayIndexOutOfBoundsException exc) {
206
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 0);
207
                                }
208

    
209
                                try {
210
                                        if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 1)).booleanValue()) {
211
                                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1);
212
                                        }
213
                                } catch (ArrayIndexOutOfBoundsException exc) {
214
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1);
215
                                }
216

    
217
                                try {
218
                                        if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 2)).booleanValue()) {
219
                                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2);
220
                                        }
221
                                } catch (ArrayIndexOutOfBoundsException exc) {
222
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2);
223
                                }
224

    
225
                                ((DefaultTableModel) getRGBTable().getModel()).removeRow(i);
226
                                i--; // Ojo! que hemos eliminado una fila
227
                        }
228
                }
229
                panelListener.setNewBandsPositionInRendering();
230
        }
231

    
232
        public void assignMode(byte mode) {
233
                this.mode = mode;
234
        }
235

    
236
        public byte getMode() {
237
                return mode;
238
        }
239

    
240
        /**
241
         * Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
242
         * debemos resetear la tabla de checkbox para que no haya activados m?s de los
243
         * permitidos
244
         * @param mode
245
         */
246
        public void resetMode(int mode) {
247
                // Reseteamos los checkbox
248
                for (int i = 0; i < (getRGBTable().getColumnCount() - 1); i++)
249
                        for (int j = 0; j < getRGBTable().getRowCount(); j++)
250
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(false), j, i);
251

    
252
                // Asignamos los valores
253
                if (this.getNBands() >= 3) {
254
                        switch (mode) {
255
                                case 3:
256
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 2, 2);
257
                                case 2:
258
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 1, 1);
259
                                case 1:
260
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 0);
261
                        }
262
                } else if (this.getNBands() == 2) {
263
                        switch (mode) {
264
                                case 3:
265
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 1, 2);
266
                                case 2:
267
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 1, 1);
268
                                case 1:
269
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 0);
270
                        }
271
                } else if (this.getNBands() == 1) {
272
                        switch (mode) {
273
                                case 3:
274
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 2);
275
                                case 2:
276
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 1);
277
                                case 1:
278
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 0);
279
                        }
280
                }
281

    
282
                col[0] = 0;
283
                col[1] = 1;
284
        }
285

    
286
        /**
287
         * Asigna modo 1, 2, o 3 bandas. El modo 1 solo permite seleccionar en la
288
         * tabla un checkbox, el 2 dos checkbox en distintar bandas y el 3 tres
289
         * checkbox tambi?n en distintas bandas.
290
         * @param mode
291
         */
292
        private void setMode(int mode) {
293
                // Solo hay un checkbox activado
294
                if (mode == 1) {
295
                        for (int i = 0; i < getRGBTable().getRowCount(); i++)
296
                                for (int j = 0; j < (getRGBTable().getColumnCount() - 1); j++) {
297
                                        if ((i != getRGBTable().getSelectedRow()) || (j != getRGBTable().getSelectedColumn())) {
298
                                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(false), i, j);
299
                                        }
300
                                }
301

    
302
                        // Hay dos checkbox activados
303
                } else if (mode == 2) {
304
                        int n = 0;
305

    
306
                        for (int i = 0; i < (getRGBTable().getColumnCount() - 1); i++)
307
                                for (int j = 0; j < getRGBTable().getRowCount(); j++)
308
                                        if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(j, i)).booleanValue()) {
309
                                                n++;
310
                                        }
311

    
312
                        // Si se ha seleccionado 3 bandas hay eliminar una de ellas. Siempre ser?
313
                        // la m?s antigua que se clickeo
314
                        if (n > 2) {
315
                                for (int i = 0; i < getRGBTable().getRowCount(); i++)
316
                                        ((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(false), i, col[0]);
317
                        }
318

    
319
                        // Rotamos el punto pinchado m?s antiguo para que se eliminen
320
                        // alternativamente
321
                        if ((col[0] == getRGBTable().getSelectedColumn()) || ((col[0] != getRGBTable().getSelectedColumn()) && (col[1] != getRGBTable().getSelectedColumn()))) {
322
                                col[0] = col[1];
323
                                col[1] = getRGBTable().getSelectedColumn();
324
                        }
325

    
326
                        // El modo 3 es el comportamiento original
327
                } else if (mode == 3) {
328
                        return;
329
                }
330
        }
331

    
332
        /**
333
         * Obtiene el panel que contiene la lista de ficheros por banda.
334
         * @return Panel FileList
335
         */
336
        public BandSetupFileList getFileList() {
337
                if (fileList == null) {
338
                        fileList = new BandSetupFileList();
339
                }
340

    
341
                return fileList;
342
        }
343

    
344
        /**
345
         * This method initializes jTable
346
         * @return javax.swing.JTable
347
         */
348
        private JScrollPane getRGBBandAssignPane() {
349
                if (rgbBandAssignPane == null) {
350
                        rgbBandAssignPane = new JScrollPane(getRGBTable());
351

    
352
                        TableColumn column = null;
353

    
354
                        for (int i = 0; i < 3; i++) {
355
                                column = getRGBTable().getColumnModel().getColumn(i);
356
                                column.setCellRenderer(new RadioColumnRenderer());
357
                                column.setCellEditor(new RadioColumnEditor());
358
                                column.setMaxWidth(22);
359
                                column.setMinWidth(22);
360
                        }
361
                }
362

    
363
                return rgbBandAssignPane;
364
        }
365

    
366
        /**
367
         * Obtiene la Tabla
368
         * @return Tabla de bandas de la imagen
369
         */
370
        public JTable getRGBTable() {
371
                if (rgbTable == null) {
372
                        tableModel = new RGBBandAsignTableModel();
373
                        tableModel.addTableModelListener(this);
374
                        rgbTable = new JTable(tableModel);
375
                        rgbTable.setPreferredScrollableViewportSize(new Dimension(328, 72));
376
                }
377
                return rgbTable;
378
        }
379

    
380
        /**
381
         * Asigna al combo de n?mero de bandas a mostrar el valor correspondiente
382
         * dependiendo del n?mero de bandas de la imagen.
383
         */
384
        public void setList() {
385
                String[] l = null;
386

    
387
                if (this.getNBands() == 1) {
388
                        l = new String[1];
389
                        l[0] = "1";
390
                }
391

    
392
                if (this.getNBands() == 2) {
393
                        l = new String[2];
394
                        l[0] = "1";
395
                        l[1] = "2";
396
                }
397

    
398
                if (this.getNBands() == 3) {
399
                        l = new String[3];
400
                        l[0] = "1";
401
                        l[1] = "2";
402
                        l[2] = "3";
403
                }
404

    
405
                if (this.getNBands() > 0) {
406
                        getFileList().setList(l);
407
                }
408
        }
409

    
410
        /**
411
         * A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
412
         * valor a los checkbox
413
         * @param bandName Nombre de la banda
414
         */
415
        private void addBand(String bandName) {
416
                Vector v = new Vector();
417
                v.add(new Boolean(false));
418
                v.add(new Boolean(false));
419
                v.add(new Boolean(false));
420
                v.add(bandName);
421
                ((DefaultTableModel) getRGBTable().getModel()).addRow(v);
422
        }
423

    
424
        /**
425
         * Elimina todas las entradas de la tabla de bandas.
426
         */
427
        private void clear() {
428
                int rows = ((DefaultTableModel) getRGBTable().getModel()).getRowCount();
429
                if (rows > 0) {
430
                        for (int i = 0; i < rows; i++)
431
                                ((DefaultTableModel) getRGBTable().getModel()).removeRow(0);
432
                }
433
        }
434

    
435
        /**
436
         * Obtiene el n?mero de bandas de la lista
437
         *
438
         * @return
439
         */
440
        public int getNBands() {
441
                return ((DefaultTableModel) getRGBTable().getModel()).getRowCount();
442
        }
443

    
444
        /**
445
         * Obtiene el nombre de la banda de la posici?n i de la tabla
446
         *
447
         * @param i
448
         * @return
449
         */
450
        public String getBandName(int i) {
451
                String s = (String) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 3);
452
                return s.substring(s.lastIndexOf("[8U]") + 5, s.length());
453
        }
454

    
455
        /**
456
         * Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
457
         * corresponde
458
         *
459
         * @param nBand Banda de la imagen que corresponde
460
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
461
         */
462
        public void assignBand(int nBand, int flag) {
463
                Boolean t = new Boolean(true);
464
                try {
465
                        if ((flag & RED_BAND) == RED_BAND)
466
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 0);
467
                        
468
                        if ((flag & GREEN_BAND) == GREEN_BAND)
469
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 1);
470
                        
471
                        if ((flag & BLUE_BAND) == BLUE_BAND)
472
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 2);
473
                } catch (ArrayIndexOutOfBoundsException e) {
474
                        
475
                }
476
        }
477

    
478
        /**
479
         * Obtiene la correspondencia entre el R, G o B y la banda asignada
480
         *
481
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
482
         * @return Banda de la imagen asignada al flag pasado por par?metro
483
         */
484
        public int getAssignedBand(int flag) {
485
                DefaultTableModel model = ((DefaultTableModel) getRGBTable().getModel());
486
                if ((flag & RED_BAND) == RED_BAND) {
487
                        for (int nBand = 0; nBand < getRGBTable().getRowCount(); nBand++)
488
                                if (((Boolean) model.getValueAt(nBand, 0)).booleanValue())
489
                                        return nBand;
490
                }
491

    
492
                if ((flag & GREEN_BAND) == GREEN_BAND) {
493
                        for (int nBand = 0; nBand < getRGBTable().getRowCount(); nBand++)
494
                                if (((Boolean) model.getValueAt(nBand, 1)).booleanValue())
495
                                        return nBand;
496
                }
497

    
498
                if ((flag & BLUE_BAND) == BLUE_BAND) {
499
                        for (int nBand = 0; nBand < getRGBTable().getRowCount(); nBand++)
500
                                if (((Boolean) model.getValueAt(nBand, 2)).booleanValue())
501
                                        return nBand;
502
                }
503

    
504
                return -1;
505
        }
506

    
507
        /*
508
         * (non-Javadoc)
509
         * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
510
         */
511
        public void tableChanged(TableModelEvent e) {
512
                getRGBTable().revalidate();
513
                rgbBandAssignPane.revalidate();
514
                revalidate();
515
        }
516

    
517
        class RadioColumnEditor extends AbstractCellEditor implements TableCellEditor {
518
                final private static long serialVersionUID = -3370601314380922368L;
519
                public JRadioButton       theRadioButton;
520

    
521
                public RadioColumnEditor() {
522
                        super();
523
                        theRadioButton = new JRadioButton();
524
                        theRadioButton.addActionListener(new ActionListener() {
525
                                public void actionPerformed(ActionEvent event) {
526
                                        fireEditingStopped();
527
                                        setMode(mode);
528
                                        onlyApply();
529
                                }
530
                        });
531
                }
532

    
533
                public Component getTableCellEditorComponent(JTable table, Object obj, boolean isSelected, int row, int col) {
534
                        theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER);
535

    
536
                        Boolean lValueAsBoolean = (Boolean) obj;
537
                        theRadioButton.setSelected(lValueAsBoolean.booleanValue());
538

    
539
                        return theRadioButton;
540
                }
541

    
542
                public Object getCellEditorValue() {
543
                        return new Boolean(theRadioButton.isSelected());
544
                }
545
        }
546

    
547
        class RadioColumnRenderer extends JRadioButton implements TableCellRenderer {
548
                final private static long serialVersionUID = -3370601314380922368L;
549

    
550
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
551
                        if (value == null) {
552
                                this.setSelected(false);
553
                        }
554

    
555
                        Boolean ValueAsBoolean = (Boolean) value;
556
                        this.setSelected(ValueAsBoolean.booleanValue());
557
                        this.setHorizontalAlignment(SwingConstants.CENTER);
558

    
559
                        return this;
560
                }
561
        }
562

    
563
        class RGBBandAsignTableModel extends DefaultTableModel {
564
                final private static long serialVersionUID = -3370601314380922368L;
565

    
566
                public RGBBandAsignTableModel() {
567
                        super(new Object[0][4], columnNames);
568
                }
569

    
570
                public Class getColumnClass(int c) {
571
                        if (c < 3) {
572
                                return Boolean.class;
573
                        }
574

    
575
                        return String.class;
576
                }
577

    
578
                public void setValueAt(Object value, int row, int col) {
579
                        if ((col < 3) && ((Boolean) value).booleanValue()) {
580
                                for (int i = 0; i < getRowCount(); i++) {
581
                                        if (i != row) {
582
                                                setValueAt(new Boolean(false), i, col);
583
                                        }
584
                                }
585
                        }
586

    
587
                        super.setValueAt(value, row, col);
588
                }
589

    
590
                public void addNew() {
591
                        super.addRow(new Object[] { new Boolean(false), new Boolean(false), new Boolean(false), "" });
592
                }
593
        }
594

    
595
        public void setComponentSize(int w, int h) {
596
                wComp = w;
597
                hComp = h;
598
                wFileList = wComp - 18;
599
                hFileList = (int) Math.round(hComp * 0.46);
600
                wBand = wFileList;
601
                hBand = hComp - hFileList - 20;
602

    
603
                this.setPreferredSize(new Dimension(wComp, hComp));
604
                this.setSize(wComp, hComp);
605
                rgbBandAssignPane.setBounds(10, hFileList + 12, wBand, hBand);
606
                fileList.setBounds(9, 9, wFileList, hFileList);
607

    
608
        }
609

    
610
        /**
611
         * Redimensiona el panel cuando se redimensiona el contenedor de ?ste
612
         */
613
        public void componentResized(ComponentEvent e) {
614
                if (e.getSource() == this) {
615
                        int nWidth = this.getSize().width;
616
                        int nHeight = this.getSize().height;
617
                        int difWidth = nWidth - 445;
618
                        int difHeight = nHeight - 239;
619
                        this.fileList.setResize(difWidth, difHeight);
620
                        this.rgbBandAssignPane.setBounds(10, 123 + difHeight / 2, 427 + difWidth, 104 + difHeight / 2);
621

    
622
                }
623
        }
624

    
625

    
626
        /*
627
         * (non-Javadoc)
628
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLyrDefault)
629
         */
630
        public void setLayer(FLayer lyr) {
631
                fLayer = lyr;
632
                clear();
633
                getFileList().clear();
634

    
635
                if (lyr instanceof IRasterRendering) {
636
                        if (((IRasterRendering) lyr).existColorTable()) {
637
                                panelListener.init(null, null, lyr);
638
                                this.setEnabled(false);
639
                                return;
640
                        }
641
                }
642

    
643
                this.setEnabled(true);
644

    
645
                if (lyr instanceof IRasterProperties)
646
                        prop = (IRasterProperties) lyr;
647

    
648
                if (lyr instanceof IRasterDataset) {
649
                        dataset = (IRasterDataset) lyr;
650
                        addFiles(dataset.getGeoRasterMultiDataset());
651
                }
652

    
653
                panelListener.init(dataset, prop, lyr);
654
        }
655

    
656
        /**
657
         * Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho. 
658
         */
659
        public void readDrawedBands() {
660
                if (prop.getRender() != null) {
661
                        int[] renderBands = prop.getRender().getRenderBands();
662
                        for (int i = 0; i < renderBands.length; i++) {
663
                                if (renderBands[i] >= 0) {
664
                                        switch (i) {
665
                                                case 0:
666
                                                        this.assignBand(renderBands[i], RasterDataset.RED_BAND);
667
                                                        break;
668
                                                case 1:
669
                                                        this.assignBand(renderBands[i], RasterDataset.GREEN_BAND);
670
                                                        break;
671
                                                case 2:
672
                                                        this.assignBand(renderBands[i], RasterDataset.BLUE_BAND);
673
                                                        break;
674
                                        }
675
                                }
676
                        }
677
                }
678
        }
679

    
680
        /*
681
         * (non-Javadoc)
682
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
683
         */
684
        public void accept() {
685
                onlyApply();
686
        }
687

    
688
        /**
689
         * Aplica y guarda los cambios del panel
690
         */
691
        public void apply() {
692
                onlyApply();
693
                saveStatus();
694
        }
695

    
696
        /**
697
         * Aplicar los cambios sin guardar su estado
698
         */
699
        public void onlyApply() {
700
                if (RasterPropertiesTocMenuEntry.enableEvents)
701
                        panelListener.apply();
702
        }
703

    
704
        /**
705
         * Guarda el estado actual del panel
706
         */
707
        private void saveStatus() {
708
                ArrayList aux = new ArrayList();
709
                int[] renderBands = prop.getRender().getRenderBands();
710
                for (int i = 0; i < renderBands.length; i++) {
711
                        aux.add(new Integer(renderBands[i]));
712
                }
713

    
714
                RegistrableTabPanel.initialProperties.put("renderBands", aux);
715
        }
716

    
717

    
718
        /**
719
         * Deja la capa en el ?ltimo estado guardado y la refresca
720
         */
721
        public void restoreStatus() {
722

    
723
                ArrayList aux = (ArrayList) RegistrableTabPanel.initialProperties.get("renderBands");
724

    
725
                int[] renderBands = new int[aux.size()];
726
                for (int i = 0; i < aux.size(); i++) {
727
                        renderBands[i] = ((Integer) aux.get(i)).intValue();
728
                }
729

    
730
                prop.getRender().setRenderBands(renderBands);
731

    
732
                if (fLayer != null)
733
                        fLayer.getMapContext().invalidate();
734
        }
735

    
736
        /*
737
         * (non-Javadoc)
738
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
739
         */
740
        public void cancel() {
741
                restoreStatus();
742
        }
743

    
744
        /*
745
         * (non-Javadoc)
746
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
747
         */
748
        public String getID() {
749
                return id;
750
        }
751

    
752
        /**
753
         * Activa y desactiva el control
754
         * @param enabled true para activar y false para desactivar
755
         */
756
        public void setEnabled(boolean enabled) {
757
                if (panelListener != null)
758
                        panelListener.setEnabledPanelAction(enabled);
759
                this.getRGBTable().setEnabled(enabled);
760
                this.getRGBBandAssignPane().setEnabled(enabled);
761
                getFileList().setEnabled(enabled);
762
        }
763

    
764
        public void selectTab(String id) {}
765
        public void componentHidden(ComponentEvent e) {}
766
        public void componentShown(ComponentEvent e) {}
767
        public void componentMoved(ComponentEvent e) {}
768
}