Statistics
| Revision:

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

History | View | Annotate | Download (22.3 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.gui.properties.dialog.IRegistrablePanel;
49
import org.gvsig.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry;
50
import org.gvsig.raster.gui.properties.dialog.RegistrableTabPanel;
51
import org.gvsig.raster.hierarchy.IRasterDataset;
52
import org.gvsig.raster.hierarchy.IRasterProperties;
53
import org.gvsig.raster.hierarchy.IRasterRendering;
54
import org.gvsig.rastertools.properties.control.BandSetupListener;
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
        private boolean               visible = true;
109
        
110
        /**
111
         * This method initializes
112
         */
113
        public BandSetupPanel() {
114
                super();
115
                id = PluginServices.getText(this, id);
116
                initialize();
117
                panelListener = new BandSetupListener(this);
118
        }
119

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
342
                return fileList;
343
        }
344

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

    
353
                        TableColumn column = null;
354

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

    
364
                return rgbBandAssignPane;
365
        }
366

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

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

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

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

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

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

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

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

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

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

    
456
        /**
457
         * Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
458
         * corresponde
459
         *
460
         * @param nBand Banda de la imagen que corresponde
461
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
462
         */
463
        public void assignBand(int nBand, int flag) {
464
                Boolean t = new Boolean(true);
465
                try {
466
                        if ((flag & RED_BAND) == RED_BAND)
467
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 0);
468

    
469
                        if ((flag & GREEN_BAND) == GREEN_BAND)
470
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 1);
471

    
472
                        if ((flag & BLUE_BAND) == BLUE_BAND)
473
                                ((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 2);
474
                } catch (ArrayIndexOutOfBoundsException e) {
475

    
476
                }
477
        }
478

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

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

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

    
505
                return -1;
506
        }
507

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

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

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

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

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

    
540
                        return theRadioButton;
541
                }
542

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

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

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

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

    
560
                        return this;
561
                }
562
        }
563

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

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

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

    
576
                        return String.class;
577
                }
578

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

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

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

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

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

    
609
        }
610

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

    
623
                }
624
        }
625

    
626

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

    
636
                if (lyr instanceof IRasterProperties)
637
                        prop = (IRasterProperties) lyr;
638

    
639
                if (lyr instanceof IRasterRendering) {
640
                        if (((IRasterRendering) lyr).existColorTable()) {
641
                                panelListener.init(null, null, lyr);
642
                                this.setEnabled(false);
643
                                return;
644
                        }
645
                }
646

    
647
                this.setEnabled(true);
648

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

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

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

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

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

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

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

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

    
718

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

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

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

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

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

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

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

    
753
        /**
754
         * Activa y desactiva el control
755
         * @param enabled true para activar y false para desactivar
756
         */
757
        public void setEnabled(boolean enabled) {
758
                if (panelListener != null)
759
                        panelListener.setEnabledPanelAction(enabled);
760
                this.getRGBTable().setEnabled(enabled);
761
                this.getRGBBandAssignPane().setEnabled(enabled);
762
                getFileList().setEnabled(enabled);
763
        }
764
        
765
        /*
766
         * (non-Javadoc)
767
         * @see org.gvsig.raster.gui.properties.dialog.IRegistrablePanel#setVisiblePanel(boolean)
768
         */
769
        public void setVisiblePanel(boolean visible) {
770
                this.visible = visible;
771
        }
772

    
773
        /*
774
         * (non-Javadoc)
775
         * @see org.gvsig.raster.gui.properties.dialog.IRegistrablePanel#isVisiblePanel()
776
         */
777
        public boolean isVisiblePanel() {
778
                return visible;
779
        }
780

    
781
        public void selectTab(String id) {}
782
        public void componentHidden(ComponentEvent e) {}
783
        public void componentShown(ComponentEvent e) {}
784
        public void componentMoved(ComponentEvent e) {}
785
}