Statistics
| Revision:

gvsig-raster / org.gvsig.raster.multifile / trunk / org.gvsig.raster.multifile / org.gvsig.raster.multifile.app.multifileclient / src / main / java / org / gvsig / raster / multifile / app / panel / BandSelectorPanel.java @ 4181

History | View | Annotate | Download (21.4 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.multifile.app.panel;
23

    
24
import java.awt.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ComponentEvent;
29
import java.awt.image.DataBuffer;
30
import java.io.File;
31
import java.net.URI;
32
import java.util.ArrayList;
33
import java.util.List;
34

    
35
import javax.swing.JButton;
36
import javax.swing.JComboBox;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39
import javax.swing.event.TableModelEvent;
40
import javax.swing.event.TableModelListener;
41
import javax.swing.table.DefaultTableModel;
42

    
43
import org.gvsig.fmap.dal.coverage.RasterLocator;
44
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
45
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
46
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
47
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
48
import org.gvsig.gui.beans.table.TableContainer;
49
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
50
import org.gvsig.i18n.Messages;
51
import org.gvsig.raster.fmap.layers.FLyrRaster;
52
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
53
import org.gvsig.raster.mainplugin.properties.RasterPropertiesTocMenuEntry;
54
import org.gvsig.raster.swing.RasterSwingLibrary;
55

    
56
/**
57
 * Selecciona las bandas visibles en un raster. Contiene una tabla con una fila
58
 * por cada banda de la imagen. Por medio de checkbox se selecciona para cada
59
 * RGB que banda de la imagen ser? visualizada.
60
 *
61

62
 * @author Nacho Brodin (nachobrodin@gmail.com)
63
 */
64
public class BandSelectorPanel extends AbstractPanel implements TableModelListener {
65
        final private static long       serialVersionUID  = -3370601314380922368L;
66
        public static final int         TYPE_PROPERTIES   = 0;
67
        public static final int         TYPE_DIALOG       = 1;
68

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

    
72
        private FLyrRaster              fLayer = null;
73

    
74
        private BandSelectorFileList    fileList          = null;
75

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

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

    
86
        /**
87
         * Constructor to be instantiated from the properties panels
88
         */
89
        public BandSelectorPanel() {
90
                super();
91
                panelListener = new BandSelectorPropertiesListener(this);
92
                initialize();
93
        }
94

    
95
        /**
96
         * This method initializes
97
         */
98
        public BandSelectorPanel(int type) {
99
                super();
100
                if(type == TYPE_PROPERTIES)
101
                        panelListener = new BandSelectorPropertiesListener(this);
102
                if(type == TYPE_DIALOG)
103
                        panelListener = new BandSelectorNewLayerListener(this);
104
                initialize();
105
        }
106

    
107
        public AbstractBandSelectorListener getListener() {
108
                return panelListener;
109
        }
110

    
111
        /**
112
         * This method initializes this
113
         *
114
         * @return void
115
         */
116
        protected void initialize() {
117
                GridBagConstraints gbc = new GridBagConstraints();
118
                setLayout(new GridBagLayout());
119
                gbc.insets = new Insets(0, 0, 0, 0);
120
                gbc.fill = GridBagConstraints.BOTH;
121

    
122
                gbc.weightx = 1.0;
123
                gbc.weighty = 1.0;
124
                add(getFileList(), gbc);
125

    
126
                gbc.gridy = 1;
127
                add(getARGBTable(), gbc);
128

    
129
                gbc.weighty = 0;
130
                gbc.gridy = 2;
131
                gbc.fill = GridBagConstraints.EAST;
132
                gbc.anchor = GridBagConstraints.EAST;
133
                gbc.insets = new Insets(0, 0, 0, 8);
134
                if(panelListener instanceof BandSelectorPropertiesListener)
135
                        add(getButtonsPanel(), gbc);
136

    
137
                this.setPreferredSize(new Dimension(100, 80));
138
                super.setLabel(Messages.getText("bands_panel"));
139

    
140
                this.setPriority(80);
141
        }
142

    
143
        /**
144
         * Obtiene el panel que contiene la lista de ficheros por banda.
145
         * @return Panel FileList
146
         */
147
        public BandSelectorFileList getFileList() {
148
                if (fileList == null)
149
                        fileList = new BandSelectorFileList();
150
                return fileList;
151
        }
152

    
153
        /**
154
         * Obtiene la Tabla
155
         * @return Tabla de bandas de la imagen
156
         */
157
        public TableContainer getARGBTable() {
158
                if (table == null) {
159
                        ArrayList<AbstractBandSelectorListener> listeners = new ArrayList<AbstractBandSelectorListener>();
160
                        listeners.add(panelListener);
161
                        table = new TableContainer(columnNames, columnWidths, listeners);
162
                        table.setModel("ARGBBandSelectorModel");
163
                        table.setControlVisible(false);
164
                        table.getModel().addTableModelListener(this);
165
                        table.initialize();
166
                }
167
                return table;
168
        }
169

    
170
        /**
171
         * Obtiene el Panel con bot?n de salvado y selector de bandas.
172
         * @return JPanel
173
         */
174
        public JPanel getButtonsPanel() {
175
                if (buttonsPanel == null) {
176
                        buttonsPanel = new JPanel();
177
                        buttonsPanel.setLayout(new GridBagLayout());
178
                        JLabel lbandasVisibles = new JLabel();
179
                        lbandasVisibles.setText(Messages.getText("bands"));
180

    
181
                        GridBagConstraints gbc = new GridBagConstraints();
182
                        gbc.insets = new Insets(0, 8, 0, 0);
183
                        gbc.fill = GridBagConstraints.BOTH;
184
                        gbc.weightx = 1.0;
185
                        buttonsPanel.add(lbandasVisibles, gbc);
186

    
187
                        gbc = new GridBagConstraints();
188
                        gbc.insets = new Insets(0, 8, 0, 0);
189
                        gbc.fill = GridBagConstraints.BOTH;
190
                        gbc.gridx = 1;
191
                        getNumBandSelectorCombo().setMinimumSize(new Dimension(50, getNumBandSelectorCombo().getMinimumSize().height));
192
                        getNumBandSelectorCombo().setPreferredSize(new Dimension(50, getNumBandSelectorCombo().getMinimumSize().height));
193
                        buttonsPanel.add(getNumBandSelectorCombo(), gbc);
194

    
195
                        gbc = new GridBagConstraints();
196
                        gbc.insets = new Insets(0, 8, 0, 0);
197
                        gbc.fill = GridBagConstraints.BOTH;
198
                        gbc.weightx = 1.0;
199
                        gbc.gridx = 2;
200
                        buttonsPanel.add(getSaveButton(), gbc);
201
                }
202
                return buttonsPanel;
203
        }
204

    
205
        /**
206
         * Obtiene el combo del selector del n?mero de bandas
207
         * @return JComboBox
208
         */
209
        public JComboBox getNumBandSelectorCombo() {
210
                if (jComboBox == null) {
211
                        String[] list = { "1", "2", "3" };
212
                        jComboBox = new JComboBox(list);
213
                        jComboBox.setSelectedIndex(2);
214
                        jComboBox.setPreferredSize(new java.awt.Dimension(36, 25));
215
                }
216

    
217
                return jComboBox;
218
        }
219

    
220
        /**
221
         * Bot?n de salvar la interpretaci?n de color seleccionada como predeterminada en
222
         * la capa
223
         * @return JButton
224
         */
225
        public JButton getSaveButton() {
226
                if(saveButton == null) {
227
                        saveButton = new JButton(Messages.getText("save"));
228
                        saveButton.setToolTipText(Messages.getText("save_color_interpretation"));
229
                        saveButton.addActionListener(panelListener);
230
                }
231
                return saveButton;
232
        }
233

    
234
        /**
235
         * A?ade la lista de georasterfiles a la tabla
236
         *
237
         * @param files
238
         * @throws NotInitializeException
239
         */
240
        public void addFiles(RasterDataStore dstore) throws NotInitializeException {
241
                getFileList().clear();
242
                clear();
243
                if(dstore.isMultiFile()) {
244
                        URI[] files = dstore.getURIByProvider();
245
                        for (int i = 0; i < files.length; i++) {
246
                                getFileList().addFName(files[i].getPath());
247
                        }
248
                } else
249
                        getFileList().addFName(dstore.getName());
250

    
251
                int nbands = dstore.getBandCount();
252
                for (int i = 0; i < nbands; i++) {
253
                        String fName = dstore.getURIByBand(i).getPath();
254

    
255
                        String bandName = new File(fName).getName();
256
                        String bandType = "";
257

    
258
                        switch (dstore.getDataType()[0]) {
259
                        case DataBuffer.TYPE_BYTE:
260
                                bandType = "8U";
261
                                break;
262
                        case DataBuffer.TYPE_INT:
263
                                bandType = "32";
264
                                break;
265
                        case DataBuffer.TYPE_DOUBLE:
266
                                bandType = "64";
267
                                break;
268
                        case DataBuffer.TYPE_FLOAT:
269
                                bandType = "32";
270
                                break;
271
                        case DataBuffer.TYPE_SHORT:
272
                                bandType = "16";
273
                                break;
274
                        case DataBuffer.TYPE_USHORT:
275
                                bandType = "16U";
276
                                break;
277
                        case DataBuffer.TYPE_UNDEFINED:
278
                                bandType = "??";
279
                                break;
280
                        }
281

    
282
                        addBand((i + 1) + " [" + bandType + "] " + bandName);
283
                }
284

    
285
                if(fLayer != null) {
286
                        readDrawedBands();
287
                        saveStatus();
288
                }
289
                //evaluateControlsEnabled();
290
        }
291

    
292
        /**
293
         * Elimina un fichero de la lista
294
         * @param file Nombre del fichero a eliminar
295
         */
296
        public void removeFile(String file) {
297
                getFileList().removeFName(file);
298

    
299
                for (int i = 0; i < ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); i++) {
300
                        // Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
301
                        // esta visibilidad a la banda inmediata superior y si esta acci?n produce
302
                        // una excepci?n (porque no hay) se pasa al inmediato inferior.
303
                        if (((String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 4)).endsWith(file)) {
304
                                try {
305
                                        if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 0)).booleanValue()) {
306
                                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1);
307
                                        }
308
                                } catch (ArrayIndexOutOfBoundsException exc) {
309
                                        ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1);
310
                                }
311

    
312
                                try {
313
                                        if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 1)).booleanValue()) {
314
                                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2);
315
                                        }
316
                                } catch (ArrayIndexOutOfBoundsException exc) {
317
                                        ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2);
318
                                }
319

    
320
                                try {
321
                                        if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 2)).booleanValue()) {
322
                                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 3);
323
                                        }
324
                                } catch (ArrayIndexOutOfBoundsException exc) {
325
                                        ((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 3);
326
                                }
327

    
328
                                ((DefaultTableModel) getARGBTable().getModel()).removeRow(i);
329
                                i--; // Ojo! que hemos eliminado una fila
330
                        }
331
                }
332
                panelListener.setNewBandsPositionInRendering();
333
        }
334

    
335
        /**
336
         * Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
337
         * debemos resetear la tabla de checkbox para que no haya activados m?s de los
338
         * permitidos
339
         * @param mode
340
         */
341
        public void resetMode(int mode) {
342
                DefaultTableModel model = getARGBTable().getModel();
343
                // Reseteamos los checkbox
344
                for (int i = 0; i < (model.getColumnCount() - 1); i++)
345
                        for (int j = 0; j < model.getRowCount(); j++)
346
                                model.setValueAt(Boolean.FALSE, j, i);
347

    
348
                // Asignamos los valores
349
                if (getNBands() >= 1) {
350
                        switch (mode) {
351
                                case 3:
352
                                        int b = 2;
353
                                        if (getNBands() < 3)
354
                                                b = getNBands() - 1;
355
                                        model.setValueAt(Boolean.TRUE, b, 3);
356
                                case 2:
357
                                        int g = 1;
358
                                        if (getNBands() == 1)
359
                                                g = 0;
360
                                        model.setValueAt(Boolean.TRUE, g, 2);
361
                                case 1:
362
                                        model.setValueAt(Boolean.TRUE, 0, 1);
363
                        }
364
                }
365

    
366
                col[0] = 0;
367
                col[1] = 1;
368
        }
369

    
370
        /**
371
         * A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
372
         * valor a los checkbox
373
         * @param bandName Nombre de la banda
374
         * @throws NotInitializeException
375
         */
376
        private void addBand(String bandName) throws NotInitializeException {
377
                Object[] row = {        new Boolean(false),
378
                                                        new Boolean(false),
379
                                                        new Boolean(false),
380
                                                        new Boolean(false),
381
                                                        bandName };
382
                getARGBTable().addRow(row);
383
        }
384

    
385
        /**
386
         * Elimina todas las entradas de la tabla de bandas.
387
         */
388
        private void clear() {
389
                int rows = ((DefaultTableModel) getARGBTable().getModel()).getRowCount();
390
                if (rows > 0) {
391
                        for (int i = 0; i < rows; i++)
392
                                ((DefaultTableModel) getARGBTable().getModel()).removeRow(0);
393
                }
394
        }
395

    
396
        /**
397
         * Obtiene el n?mero de bandas de la lista
398
         *
399
         * @return
400
         */
401
        public int getNBands() {
402
                return ((DefaultTableModel) getARGBTable().getModel()).getRowCount();
403
        }
404

    
405
        /**
406
         * Obtiene el nombre de la banda de la posici?n i de la tabla
407
         *
408
         * @param i
409
         * @return
410
         */
411
        public String getBandName(int i) {
412
                String s = (String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 3);
413
                return s.substring(s.lastIndexOf("[8U]") + 5, s.length());
414
        }
415

    
416
        /**
417
         * Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
418
         * corresponde
419
         *
420
         * @param nBand Banda de la imagen que corresponde
421
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
422
         */
423
        public void assignBand(int nBand, int flag) {
424
                Boolean t = new Boolean(true);
425
                try {
426
                        if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND)
427
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 0);
428

    
429
                        if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND)
430
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 1);
431

    
432
                        if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND)
433
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 2);
434

    
435
                        if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND)
436
                                ((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 3);
437
                } catch (ArrayIndexOutOfBoundsException e) {
438

    
439
                }
440
        }
441

    
442
        /**
443
         * Obtiene la correspondencia entre el R, G o B y la banda asignada
444
         *
445
         * @param flag R, G o B se selecciona por medio de un flag que los identifica
446
         * @return Banda de la imagen asignada al flag pasado por par?metro
447
         */
448
        public int getColorInterpretationByColorBandBand(int flag) {
449
                DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel());
450
                if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND) {
451
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
452
                                if (((Boolean) model.getValueAt(nBand, 0)).booleanValue())
453
                                        return nBand;
454
                }
455

    
456
                if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND) {
457
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
458
                                if (((Boolean) model.getValueAt(nBand, 1)).booleanValue())
459
                                        return nBand;
460
                }
461

    
462
                if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND) {
463
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
464
                                if (((Boolean) model.getValueAt(nBand, 2)).booleanValue())
465
                                        return nBand;
466
                }
467

    
468
                if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND) {
469
                        for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++)
470
                                if (((Boolean) model.getValueAt(nBand, 3)).booleanValue())
471
                                        return nBand;
472
                }
473

    
474
                return -1;
475
        }
476

    
477
        /**
478
         * Obtiene la interpretaci?n de color por n?mero de banda
479
         * @param nBand N?mero de banda
480
         * @return Interpretaci?n de color. Constante definida en DatasetColorInterpretation
481
         */
482
        public String getColorInterpretationByBand(int nBand) {
483
                DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel());
484
                for (int col = 0; col < 4; col++) {
485
                        if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) {
486
                                switch (col) {
487
                                case 0: return ColorInterpretation.ALPHA_BAND;
488
                                case 1: return ColorInterpretation.RED_BAND;
489
                                case 2: return ColorInterpretation.GREEN_BAND;
490
                                case 3: return ColorInterpretation.BLUE_BAND;
491
                                }
492
                        }
493
                }
494
                return ColorInterpretation.UNDEF_BAND;
495
        }
496

    
497
        public ColorInterpretation getSelectedColorInterpretation() {
498
                try {
499
                        String[] colorInter = new String[getARGBTable().getRowCount()];
500
                        for (int iBand = 0; iBand < getARGBTable().getRowCount(); iBand++) {
501
                                if(isSelected(iBand, 1) && isSelected(iBand, 2) && isSelected(iBand, 3)) {
502
                                        colorInter[iBand] = ColorInterpretation.GRAY_BAND;
503
                                } else if(isSelected(iBand, 1) && isSelected(iBand, 2)) {
504
                                        colorInter[iBand] = ColorInterpretation.RED_GREEN_BAND;
505
                                } else if(isSelected(iBand, 1) && isSelected(iBand, 3)) {
506
                                        colorInter[iBand] = ColorInterpretation.RED_BLUE_BAND;
507
                                } else if(isSelected(iBand, 2) && isSelected(iBand, 3)) {
508
                                        colorInter[iBand] = ColorInterpretation.GREEN_BLUE_BAND;
509
                                } else if(isSelected(iBand, 1)) {
510
                                        colorInter[iBand] = ColorInterpretation.RED_BAND;
511
                                } else if(isSelected(iBand, 2)) {
512
                                        colorInter[iBand] = ColorInterpretation.GREEN_BAND;
513
                                } else if(isSelected(iBand, 3)) {
514
                                        colorInter[iBand] = ColorInterpretation.BLUE_BAND;
515
                                } else if(isSelected(iBand, 0)) {
516
                                        colorInter[iBand] = ColorInterpretation.ALPHA_BAND;
517
                                } else
518
                                        colorInter[iBand] = ColorInterpretation.UNDEF_BAND;
519
                        }
520
                        return RasterLocator.getManager().getDataStructFactory().createColorInterpretation(colorInter);
521
                } catch (NotInitializeException e) {
522
                        RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this, e);
523
                }
524
                return null;
525
        }
526

    
527
        private boolean isSelected(int iBand, int col) {
528
                DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel());
529
                return ((Boolean) model.getValueAt(iBand, col)).booleanValue();
530
        }
531

    
532
        public void tableChanged(TableModelEvent e) {
533
                getARGBTable().revalidate();
534
                revalidate();
535
        }
536

    
537
        public RasterDataStore getResult() {
538
                return panelListener.getResult();
539
        }
540

    
541
        /**
542
         * Activa o desactiva la funcionalidad
543
         */
544
        private void actionEnabled() {
545
                boolean enabled = true;
546

    
547
                IRasterLayerActions actions = null;
548

    
549
                if(fLayer != null && fLayer instanceof IRasterLayerActions)
550
                        actions = (IRasterLayerActions)fLayer;
551

    
552
                if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST))
553
                        enabled = false;
554
                getFileList().setEnabled(enabled);
555

    
556
                enabled = true;
557
                if (!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB))
558
                        enabled = false;
559
                getARGBTable().setEnabled(enabled);
560

    
561
                // TODO: Mirar el setVisible...
562
                if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST) &&
563
                                !actions.isActionEnabled(IRasterLayerActions.BANDS_RGB))
564
                        setVisible(false);
565
                else
566
                        setVisible(true);
567

    
568
                if (!actions.isActionEnabled(IRasterLayerActions.SAVE_COLORINTERP))
569
                        getSaveButton().setVisible(false);
570
        }
571

    
572
        /**
573
         * Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho.
574
         */
575
        public void readDrawedBands() {
576
                if (fLayer.getRender() != null) {
577
                        int[] renderBands = fLayer.getRender().getRenderColorInterpretation().buildRenderBands();
578
                        Transparency transp = fLayer.getRender().getRenderingTransparency();
579
                        if(transp != null && transp.getAlphaBandNumber() != -1)
580
                                this.assignBand(transp.getAlphaBandNumber(), RasterDataStore.ALPHA_BAND);
581
                        for (int i = 0; i < renderBands.length; i++) {
582
                                if (renderBands[i] >= 0) {
583
                                        switch (i) {
584
                                        case 0:
585
                                                this.assignBand(renderBands[i], RasterDataStore.RED_BAND);
586
                                                break;
587
                                        case 1:
588
                                                this.assignBand(renderBands[i], RasterDataStore.GREEN_BAND);
589
                                                break;
590
                                        case 2:
591
                                                this.assignBand(renderBands[i], RasterDataStore.BLUE_BAND);
592
                                                break;
593
                                        }
594
                                }
595
                        }
596
                }
597
        }
598

    
599
        public void accept() {
600
                if (!getPanelGroup().isPanelInGUI(this))
601
                        return;
602

    
603
                onlyApply();
604
        }
605

    
606
        /**
607
         * Aplica y guarda los cambios del panel
608
         */
609
        public void apply() {
610
                if (!getPanelGroup().isPanelInGUI(this))
611
                        return;
612

    
613
                onlyApply();
614
                saveStatus();
615
        }
616

    
617
        /**
618
         * Aplicar los cambios sin guardar su estado
619
         */
620
        public void onlyApply() {
621
                if (RasterPropertiesTocMenuEntry.enableEvents)
622
                        panelListener.apply();
623
        }
624

    
625
        /**
626
         * Guarda el estado actual del panel
627
         */
628
        @SuppressWarnings("unchecked")
629
        private void saveStatus() {
630
                List<String> aux = new ArrayList<String>();
631
                String[] valuesCI = fLayer.getRender().getRenderColorInterpretation().getValues();
632
                for (int i = 0; i < valuesCI.length; i++) {
633
                        aux.add(valuesCI[i]);
634
                }
635
                getPanelGroup().getProperties().put("renderBands", aux);
636
        }
637

    
638

    
639
        /**
640
         * Deja la capa en el ?ltimo estado guardado y la refresca
641
         */
642
        @SuppressWarnings("unchecked")
643
        public void restoreStatus() {
644
                if (fLayer != null)
645
                        return;
646

    
647
                List<String> aux = (List<String>) getPanelGroup().getProperties().get("renderBands");
648

    
649
                if(fLayer.getRender() != null) {
650
                        ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation((String[])aux.toArray());
651
                        fLayer.getRender().setRenderColorInterpretation(ci);
652
                }
653

    
654
                fLayer.getMapContext().invalidate();
655
        }
656

    
657
        public void cancel() {
658
                if (!getPanelGroup().isPanelInGUI(this))
659
                        return;
660

    
661
                restoreStatus();
662
        }
663

    
664
        /**
665
         * Activa y desactiva el control
666
         * @param enabled true para activar y false para desactivar
667
         */
668
        public void setEnabled(boolean enabled) {
669
                if (panelListener != null)
670
                        panelListener.setEnabledPanelAction(enabled);
671
                getARGBTable().setEnabled(enabled);
672
                getFileList().setEnabled(enabled);
673
        }
674

    
675
        /**
676
         * Sets the current layer when the panel is opened from
677
         * raster properties
678
         */
679
        public void setReference(Object ref) {
680
                super.setReference(ref);
681

    
682
                if (!(ref instanceof FLyrRaster))
683
                        return;
684

    
685
                fLayer = (FLyrRaster) ref;
686

    
687
                actionEnabled();
688

    
689
                clear();
690
                getFileList().clear();
691

    
692
                //Si tiene tabla de color inicializamos solamente
693

    
694
                if (fLayer.existColorTable()) {
695
                        ((BandSelectorPropertiesListener)panelListener).init(fLayer);
696
                        return;
697
                }
698

    
699
                //Si no tiene tabla de color se a?aden los ficheros e inicializamos
700
                try {
701
                        addFiles(fLayer.getDataStore());
702
                } catch (NotInitializeException e) {
703
                        RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this);
704
                }
705

    
706
                ((BandSelectorPropertiesListener)panelListener).init(fLayer);
707
        }
708

    
709
        public void componentHidden(ComponentEvent e) {}
710
        public void componentShown(ComponentEvent e) {}
711
        public void componentMoved(ComponentEvent e) {}
712

    
713

    
714
        public void selected() {
715
                setReference(fLayer);
716
        }
717
}