Statistics
| Revision:

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

History | View | Annotate | Download (22.7 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.fmap.raster.layers.FLyrRasterSE;
47
import org.gvsig.raster.dataset.IRasterDataSource;
48
import org.gvsig.raster.dataset.RasterDataset;
49
import org.gvsig.raster.gui.properties.dialog.IRegistrablePanel;
50
import org.gvsig.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry;
51
import org.gvsig.raster.gui.properties.dialog.RegistrableTabPanel;
52
import org.gvsig.raster.hierarchy.IRasterDataset;
53
import org.gvsig.raster.hierarchy.IRasterProperties;
54
import org.gvsig.raster.hierarchy.IRasterRendering;
55
import org.gvsig.rastertools.properties.control.BandSetupListener;
56

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

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

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

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

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

    
93
        FLayer                          fLayer = null;
94

    
95
        /**
96
         * Nombre del panel
97
         */
98
        private String                  id                = "bands_panel";
99
        private BandSetupFileList       fileList          = null;
100
        private JTable                  rgbTable          = null;
101
        private JScrollPane             rgbBandAssignPane = null;
102
        RGBBandAsignTableModel          tableModel        = null;
103
        private byte                    mode              = 3;
104
        // Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo
105
        private int[]                   col               = { 0, 1 };
106
        private BandSetupListener       panelListener     = null;
107
        private IRasterProperties       prop              = null;
108
        private IRasterDataset          dataset           = null;
109
        private boolean                 visible           = true;
110
        
111
        /**
112
         * This method initializes
113
         */
114
        public BandSetupPanel() {
115
                super();
116
                id = PluginServices.getText(this, id);
117
                initialize();
118
                panelListener = new BandSetupListener(this);
119
        }
120

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
343
                return fileList;
344
        }
345

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

    
354
                        TableColumn column = null;
355

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

    
365
                return rgbBandAssignPane;
366
        }
367

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

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

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

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

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

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

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

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

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

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

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

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

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

    
477
                }
478
        }
479

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

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

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

    
506
                return -1;
507
        }
508

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

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

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

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

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

    
541
                        return theRadioButton;
542
                }
543

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

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

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

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

    
561
                        return this;
562
                }
563
        }
564

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

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

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

    
577
                        return String.class;
578
                }
579

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

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

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

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

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

    
610
        }
611

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

    
624
                }
625
        }
626

    
627

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

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

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

    
648
                this.setEnabled(true);
649

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

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

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

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

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

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

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

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

    
719

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

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

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

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

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

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

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

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

    
774
        /*
775
         * (non-Javadoc)
776
         * @see org.gvsig.raster.gui.properties.dialog.IRegistrablePanel#isVisiblePanel()
777
         */
778
        public boolean isVisiblePanel() {
779
                return visible;
780
        }
781
        
782
        /*
783
         * (non-Javadoc)
784
         * @see org.gvsig.raster.gui.properties.dialog.IRegistrablePanel#getLayerClass()
785
         */
786
        public Class getLayerClass() {
787
                return FLyrRasterSE.class;
788
        }
789

    
790
        public void selectTab(String id) {}
791
        public void componentHidden(ComponentEvent e) {}
792
        public void componentShown(ComponentEvent e) {}
793
        public void componentMoved(ComponentEvent e) {}
794
}