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 @ 4170
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.util.ArrayList; |
32 |
import java.util.List; |
33 |
|
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JComboBox; |
36 |
import javax.swing.JLabel; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.event.TableModelEvent; |
39 |
import javax.swing.event.TableModelListener; |
40 |
import javax.swing.table.DefaultTableModel; |
41 |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
43 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
44 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
45 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
46 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
47 |
import org.gvsig.gui.beans.table.TableContainer; |
48 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
49 |
import org.gvsig.i18n.Messages; |
50 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
51 |
import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
52 |
import org.gvsig.raster.mainplugin.properties.RasterPropertiesTocMenuEntry; |
53 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
54 |
|
55 |
/**
|
56 |
* Selecciona las bandas visibles en un raster. Contiene una tabla con una fila
|
57 |
* por cada banda de la imagen. Por medio de checkbox se selecciona para cada
|
58 |
* RGB que banda de la imagen ser? visualizada.
|
59 |
*
|
60 |
|
61 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
62 |
*/
|
63 |
public class BandSelectorPanel extends AbstractPanel implements TableModelListener { |
64 |
final private static long serialVersionUID = -3370601314380922368L; |
65 |
public static final int TYPE_PROPERTIES = 0; |
66 |
public static final int TYPE_DIALOG = 1; |
67 |
|
68 |
private final String[] columnNames = { "A", "R", "G", "B", "Band" }; |
69 |
private final int[] columnWidths = { 22, 22, 22, 22, 334 }; |
70 |
|
71 |
private FLyrRaster fLayer = null; |
72 |
|
73 |
private BandSelectorFileList fileList = null; |
74 |
|
75 |
// Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo
|
76 |
private int[] col = { 0, 1 }; |
77 |
private AbstractBandSelectorListener
|
78 |
panelListener = null;
|
79 |
private TableContainer table = null; |
80 |
private JButton saveButton = null; |
81 |
|
82 |
private JPanel buttonsPanel = null; |
83 |
private JComboBox jComboBox = null; |
84 |
|
85 |
/**
|
86 |
* Constructor to be instantiated from the properties panels
|
87 |
*/
|
88 |
public BandSelectorPanel() {
|
89 |
super();
|
90 |
panelListener = new BandSelectorPropertiesListener(this); |
91 |
initialize(); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* This method initializes
|
96 |
*/
|
97 |
public BandSelectorPanel(int type) { |
98 |
super();
|
99 |
if(type == TYPE_PROPERTIES)
|
100 |
panelListener = new BandSelectorPropertiesListener(this); |
101 |
if(type == TYPE_DIALOG)
|
102 |
panelListener = new BandSelectorNewLayerListener(this); |
103 |
initialize(); |
104 |
} |
105 |
|
106 |
public AbstractBandSelectorListener getListener() {
|
107 |
return panelListener;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* This method initializes this
|
112 |
*
|
113 |
* @return void
|
114 |
*/
|
115 |
protected void initialize() { |
116 |
GridBagConstraints gbc = new GridBagConstraints(); |
117 |
setLayout(new GridBagLayout()); |
118 |
gbc.insets = new Insets(0, 0, 0, 0); |
119 |
gbc.fill = GridBagConstraints.BOTH;
|
120 |
|
121 |
gbc.weightx = 1.0;
|
122 |
gbc.weighty = 1.0;
|
123 |
add(getFileList(), gbc); |
124 |
|
125 |
gbc.gridy = 1;
|
126 |
add(getARGBTable(), gbc); |
127 |
|
128 |
gbc.weighty = 0;
|
129 |
gbc.gridy = 2;
|
130 |
gbc.fill = GridBagConstraints.EAST;
|
131 |
gbc.anchor = GridBagConstraints.EAST;
|
132 |
gbc.insets = new Insets(0, 0, 0, 8); |
133 |
if(panelListener instanceof BandSelectorPropertiesListener) |
134 |
add(getButtonsPanel(), gbc); |
135 |
|
136 |
this.setPreferredSize(new Dimension(100, 80)); |
137 |
super.setLabel(Messages.getText("bands_panel")); |
138 |
|
139 |
this.setPriority(80); |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Obtiene el panel que contiene la lista de ficheros por banda.
|
144 |
* @return Panel FileList
|
145 |
*/
|
146 |
public BandSelectorFileList getFileList() {
|
147 |
if (fileList == null) |
148 |
fileList = new BandSelectorFileList();
|
149 |
return fileList;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Obtiene la Tabla
|
154 |
* @return Tabla de bandas de la imagen
|
155 |
*/
|
156 |
public TableContainer getARGBTable() {
|
157 |
if (table == null) { |
158 |
ArrayList<AbstractBandSelectorListener> listeners = new ArrayList<AbstractBandSelectorListener>(); |
159 |
listeners.add(panelListener); |
160 |
table = new TableContainer(columnNames, columnWidths, listeners);
|
161 |
table.setModel("ARGBBandSelectorModel");
|
162 |
table.setControlVisible(false);
|
163 |
table.getModel().addTableModelListener(this);
|
164 |
table.initialize(); |
165 |
} |
166 |
return table;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Obtiene el Panel con bot?n de salvado y selector de bandas.
|
171 |
* @return JPanel
|
172 |
*/
|
173 |
public JPanel getButtonsPanel() { |
174 |
if (buttonsPanel == null) { |
175 |
buttonsPanel = new JPanel(); |
176 |
buttonsPanel.setLayout(new GridBagLayout()); |
177 |
JLabel lbandasVisibles = new JLabel(); |
178 |
lbandasVisibles.setText(Messages.getText("bands"));
|
179 |
|
180 |
GridBagConstraints gbc = new GridBagConstraints(); |
181 |
gbc.insets = new Insets(0, 8, 0, 0); |
182 |
gbc.fill = GridBagConstraints.BOTH;
|
183 |
gbc.weightx = 1.0;
|
184 |
buttonsPanel.add(lbandasVisibles, gbc); |
185 |
|
186 |
gbc = new GridBagConstraints(); |
187 |
gbc.insets = new Insets(0, 8, 0, 0); |
188 |
gbc.fill = GridBagConstraints.BOTH;
|
189 |
gbc.gridx = 1;
|
190 |
getNumBandSelectorCombo().setMinimumSize(new Dimension(50, getNumBandSelectorCombo().getMinimumSize().height)); |
191 |
getNumBandSelectorCombo().setPreferredSize(new Dimension(50, getNumBandSelectorCombo().getMinimumSize().height)); |
192 |
buttonsPanel.add(getNumBandSelectorCombo(), gbc); |
193 |
|
194 |
gbc = new GridBagConstraints(); |
195 |
gbc.insets = new Insets(0, 8, 0, 0); |
196 |
gbc.fill = GridBagConstraints.BOTH;
|
197 |
gbc.weightx = 1.0;
|
198 |
gbc.gridx = 2;
|
199 |
buttonsPanel.add(getSaveButton(), gbc); |
200 |
} |
201 |
return buttonsPanel;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* Obtiene el combo del selector del n?mero de bandas
|
206 |
* @return JComboBox
|
207 |
*/
|
208 |
public JComboBox getNumBandSelectorCombo() { |
209 |
if (jComboBox == null) { |
210 |
String[] list = { "1", "2", "3" }; |
211 |
jComboBox = new JComboBox(list); |
212 |
jComboBox.setSelectedIndex(2);
|
213 |
jComboBox.setPreferredSize(new java.awt.Dimension(36, 25)); |
214 |
} |
215 |
|
216 |
return jComboBox;
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* Bot?n de salvar la interpretaci?n de color seleccionada como predeterminada en
|
221 |
* la capa
|
222 |
* @return JButton
|
223 |
*/
|
224 |
public JButton getSaveButton() { |
225 |
if(saveButton == null) { |
226 |
saveButton = new JButton(Messages.getText("save")); |
227 |
saveButton.setToolTipText(Messages.getText("save_color_interpretation"));
|
228 |
saveButton.addActionListener(panelListener); |
229 |
} |
230 |
return saveButton;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* A?ade la lista de georasterfiles a la tabla
|
235 |
*
|
236 |
* @param files
|
237 |
* @throws NotInitializeException
|
238 |
*/
|
239 |
public void addFiles(RasterDataStore dstore) throws NotInitializeException { |
240 |
getFileList().clear(); |
241 |
clear(); |
242 |
if(dstore.isMultiFile()) {
|
243 |
String[] files = dstore.getURIByProvider(); |
244 |
for (int i = 0; i < files.length; i++) { |
245 |
getFileList().addFName(files[i]); |
246 |
} |
247 |
} else
|
248 |
getFileList().addFName(dstore.getName()); |
249 |
|
250 |
int nbands = dstore.getBandCount();
|
251 |
for (int i = 0; i < nbands; i++) { |
252 |
String fName = dstore.getURIByBand(i);
|
253 |
|
254 |
String bandName = new File(fName).getName(); |
255 |
String bandType = ""; |
256 |
|
257 |
switch (dstore.getDataType()[0]) { |
258 |
case DataBuffer.TYPE_BYTE: |
259 |
bandType = "8U";
|
260 |
break;
|
261 |
case DataBuffer.TYPE_INT: |
262 |
bandType = "32";
|
263 |
break;
|
264 |
case DataBuffer.TYPE_DOUBLE: |
265 |
bandType = "64";
|
266 |
break;
|
267 |
case DataBuffer.TYPE_FLOAT: |
268 |
bandType = "32";
|
269 |
break;
|
270 |
case DataBuffer.TYPE_SHORT: |
271 |
bandType = "16";
|
272 |
break;
|
273 |
case DataBuffer.TYPE_USHORT: |
274 |
bandType = "16U";
|
275 |
break;
|
276 |
case DataBuffer.TYPE_UNDEFINED: |
277 |
bandType = "??";
|
278 |
break;
|
279 |
} |
280 |
|
281 |
addBand((i + 1) + " [" + bandType + "] " + bandName); |
282 |
} |
283 |
|
284 |
if(fLayer != null) { |
285 |
readDrawedBands(); |
286 |
saveStatus(); |
287 |
} |
288 |
//evaluateControlsEnabled();
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* Elimina un fichero de la lista
|
293 |
* @param file Nombre del fichero a eliminar
|
294 |
*/
|
295 |
public void removeFile(String file) { |
296 |
getFileList().removeFName(file); |
297 |
|
298 |
for (int i = 0; i < ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); i++) { |
299 |
// Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
|
300 |
// esta visibilidad a la banda inmediata superior y si esta acci?n produce
|
301 |
// una excepci?n (porque no hay) se pasa al inmediato inferior.
|
302 |
if (((String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 4)).endsWith(file)) { |
303 |
try {
|
304 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 0)).booleanValue()) { |
305 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1); |
306 |
} |
307 |
} catch (ArrayIndexOutOfBoundsException exc) { |
308 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1); |
309 |
} |
310 |
|
311 |
try {
|
312 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 1)).booleanValue()) { |
313 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2); |
314 |
} |
315 |
} catch (ArrayIndexOutOfBoundsException exc) { |
316 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2); |
317 |
} |
318 |
|
319 |
try {
|
320 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 2)).booleanValue()) { |
321 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 3); |
322 |
} |
323 |
} catch (ArrayIndexOutOfBoundsException exc) { |
324 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 3); |
325 |
} |
326 |
|
327 |
((DefaultTableModel) getARGBTable().getModel()).removeRow(i);
|
328 |
i--; // Ojo! que hemos eliminado una fila
|
329 |
} |
330 |
} |
331 |
panelListener.setNewBandsPositionInRendering(); |
332 |
} |
333 |
|
334 |
/**
|
335 |
* Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
|
336 |
* debemos resetear la tabla de checkbox para que no haya activados m?s de los
|
337 |
* permitidos
|
338 |
* @param mode
|
339 |
*/
|
340 |
public void resetMode(int mode) { |
341 |
DefaultTableModel model = getARGBTable().getModel();
|
342 |
// Reseteamos los checkbox
|
343 |
for (int i = 0; i < (model.getColumnCount() - 1); i++) |
344 |
for (int j = 0; j < model.getRowCount(); j++) |
345 |
model.setValueAt(Boolean.FALSE, j, i);
|
346 |
|
347 |
// Asignamos los valores
|
348 |
if (getNBands() >= 1) { |
349 |
switch (mode) {
|
350 |
case 3: |
351 |
int b = 2; |
352 |
if (getNBands() < 3) |
353 |
b = getNBands() - 1;
|
354 |
model.setValueAt(Boolean.TRUE, b, 3); |
355 |
case 2: |
356 |
int g = 1; |
357 |
if (getNBands() == 1) |
358 |
g = 0;
|
359 |
model.setValueAt(Boolean.TRUE, g, 2); |
360 |
case 1: |
361 |
model.setValueAt(Boolean.TRUE, 0, 1); |
362 |
} |
363 |
} |
364 |
|
365 |
col[0] = 0; |
366 |
col[1] = 1; |
367 |
} |
368 |
|
369 |
/**
|
370 |
* A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
|
371 |
* valor a los checkbox
|
372 |
* @param bandName Nombre de la banda
|
373 |
* @throws NotInitializeException
|
374 |
*/
|
375 |
private void addBand(String bandName) throws NotInitializeException { |
376 |
Object[] row = { new Boolean(false), |
377 |
new Boolean(false), |
378 |
new Boolean(false), |
379 |
new Boolean(false), |
380 |
bandName }; |
381 |
getARGBTable().addRow(row); |
382 |
} |
383 |
|
384 |
/**
|
385 |
* Elimina todas las entradas de la tabla de bandas.
|
386 |
*/
|
387 |
private void clear() { |
388 |
int rows = ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); |
389 |
if (rows > 0) { |
390 |
for (int i = 0; i < rows; i++) |
391 |
((DefaultTableModel) getARGBTable().getModel()).removeRow(0); |
392 |
} |
393 |
} |
394 |
|
395 |
/**
|
396 |
* Obtiene el n?mero de bandas de la lista
|
397 |
*
|
398 |
* @return
|
399 |
*/
|
400 |
public int getNBands() { |
401 |
return ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); |
402 |
} |
403 |
|
404 |
/**
|
405 |
* Obtiene el nombre de la banda de la posici?n i de la tabla
|
406 |
*
|
407 |
* @param i
|
408 |
* @return
|
409 |
*/
|
410 |
public String getBandName(int i) { |
411 |
String s = (String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 3); |
412 |
return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
413 |
} |
414 |
|
415 |
/**
|
416 |
* Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
|
417 |
* corresponde
|
418 |
*
|
419 |
* @param nBand Banda de la imagen que corresponde
|
420 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
421 |
*/
|
422 |
public void assignBand(int nBand, int flag) { |
423 |
Boolean t = new Boolean(true); |
424 |
try {
|
425 |
if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND)
|
426 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 0); |
427 |
|
428 |
if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND)
|
429 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 1); |
430 |
|
431 |
if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND)
|
432 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 2); |
433 |
|
434 |
if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND)
|
435 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 3); |
436 |
} catch (ArrayIndexOutOfBoundsException e) { |
437 |
|
438 |
} |
439 |
} |
440 |
|
441 |
/**
|
442 |
* Obtiene la correspondencia entre el R, G o B y la banda asignada
|
443 |
*
|
444 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
445 |
* @return Banda de la imagen asignada al flag pasado por par?metro
|
446 |
*/
|
447 |
public int getColorInterpretationByColorBandBand(int flag) { |
448 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
449 |
if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND) {
|
450 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
451 |
if (((Boolean) model.getValueAt(nBand, 0)).booleanValue()) |
452 |
return nBand;
|
453 |
} |
454 |
|
455 |
if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND) {
|
456 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
457 |
if (((Boolean) model.getValueAt(nBand, 1)).booleanValue()) |
458 |
return nBand;
|
459 |
} |
460 |
|
461 |
if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND) {
|
462 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
463 |
if (((Boolean) model.getValueAt(nBand, 2)).booleanValue()) |
464 |
return nBand;
|
465 |
} |
466 |
|
467 |
if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND) {
|
468 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
469 |
if (((Boolean) model.getValueAt(nBand, 3)).booleanValue()) |
470 |
return nBand;
|
471 |
} |
472 |
|
473 |
return -1; |
474 |
} |
475 |
|
476 |
/**
|
477 |
* Obtiene la interpretaci?n de color por n?mero de banda
|
478 |
* @param nBand N?mero de banda
|
479 |
* @return Interpretaci?n de color. Constante definida en DatasetColorInterpretation
|
480 |
*/
|
481 |
public String getColorInterpretationByBand(int nBand) { |
482 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
483 |
for (int col = 0; col < 4; col++) { |
484 |
if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) { |
485 |
switch (col) {
|
486 |
case 0: return ColorInterpretation.ALPHA_BAND; |
487 |
case 1: return ColorInterpretation.RED_BAND; |
488 |
case 2: return ColorInterpretation.GREEN_BAND; |
489 |
case 3: return ColorInterpretation.BLUE_BAND; |
490 |
} |
491 |
} |
492 |
} |
493 |
return ColorInterpretation.UNDEF_BAND;
|
494 |
} |
495 |
|
496 |
public ColorInterpretation getSelectedColorInterpretation() {
|
497 |
try {
|
498 |
String[] colorInter = new String[getARGBTable().getRowCount()]; |
499 |
for (int iBand = 0; iBand < getARGBTable().getRowCount(); iBand++) { |
500 |
if(isSelected(iBand, 1) && isSelected(iBand, 2) && isSelected(iBand, 3)) { |
501 |
colorInter[iBand] = ColorInterpretation.GRAY_BAND; |
502 |
} else if(isSelected(iBand, 1) && isSelected(iBand, 2)) { |
503 |
colorInter[iBand] = ColorInterpretation.RED_GREEN_BAND; |
504 |
} else if(isSelected(iBand, 1) && isSelected(iBand, 3)) { |
505 |
colorInter[iBand] = ColorInterpretation.RED_BLUE_BAND; |
506 |
} else if(isSelected(iBand, 2) && isSelected(iBand, 3)) { |
507 |
colorInter[iBand] = ColorInterpretation.GREEN_BLUE_BAND; |
508 |
} else if(isSelected(iBand, 1)) { |
509 |
colorInter[iBand] = ColorInterpretation.RED_BAND; |
510 |
} else if(isSelected(iBand, 2)) { |
511 |
colorInter[iBand] = ColorInterpretation.GREEN_BAND; |
512 |
} else if(isSelected(iBand, 3)) { |
513 |
colorInter[iBand] = ColorInterpretation.BLUE_BAND; |
514 |
} else if(isSelected(iBand, 0)) { |
515 |
colorInter[iBand] = ColorInterpretation.ALPHA_BAND; |
516 |
} else
|
517 |
colorInter[iBand] = ColorInterpretation.UNDEF_BAND; |
518 |
} |
519 |
return RasterLocator.getManager().getDataStructFactory().createColorInterpretation(colorInter);
|
520 |
} catch (NotInitializeException e) {
|
521 |
RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this, e); |
522 |
} |
523 |
return null; |
524 |
} |
525 |
|
526 |
private boolean isSelected(int iBand, int col) { |
527 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
528 |
return ((Boolean) model.getValueAt(iBand, col)).booleanValue(); |
529 |
} |
530 |
|
531 |
public void tableChanged(TableModelEvent e) { |
532 |
getARGBTable().revalidate(); |
533 |
revalidate(); |
534 |
} |
535 |
|
536 |
public RasterDataStore getResult() {
|
537 |
return panelListener.getResult();
|
538 |
} |
539 |
|
540 |
/**
|
541 |
* Activa o desactiva la funcionalidad
|
542 |
*/
|
543 |
private void actionEnabled() { |
544 |
boolean enabled = true; |
545 |
|
546 |
IRasterLayerActions actions = null;
|
547 |
|
548 |
if(fLayer != null && fLayer instanceof IRasterLayerActions) |
549 |
actions = (IRasterLayerActions)fLayer; |
550 |
|
551 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST))
|
552 |
enabled = false;
|
553 |
getFileList().setEnabled(enabled); |
554 |
|
555 |
enabled = true;
|
556 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB))
|
557 |
enabled = false;
|
558 |
getARGBTable().setEnabled(enabled); |
559 |
|
560 |
// TODO: Mirar el setVisible...
|
561 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST) &&
|
562 |
!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB)) |
563 |
setVisible(false);
|
564 |
else
|
565 |
setVisible(true);
|
566 |
|
567 |
if (!actions.isActionEnabled(IRasterLayerActions.SAVE_COLORINTERP))
|
568 |
getSaveButton().setVisible(false);
|
569 |
} |
570 |
|
571 |
/**
|
572 |
* Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho.
|
573 |
*/
|
574 |
public void readDrawedBands() { |
575 |
if (fLayer.getRender() != null) { |
576 |
int[] renderBands = fLayer.getRender().getRenderColorInterpretation().buildRenderBands(); |
577 |
Transparency transp = fLayer.getRender().getRenderingTransparency();
|
578 |
if(transp != null && transp.getAlphaBandNumber() != -1) |
579 |
this.assignBand(transp.getAlphaBandNumber(), RasterDataStore.ALPHA_BAND);
|
580 |
for (int i = 0; i < renderBands.length; i++) { |
581 |
if (renderBands[i] >= 0) { |
582 |
switch (i) {
|
583 |
case 0: |
584 |
this.assignBand(renderBands[i], RasterDataStore.RED_BAND);
|
585 |
break;
|
586 |
case 1: |
587 |
this.assignBand(renderBands[i], RasterDataStore.GREEN_BAND);
|
588 |
break;
|
589 |
case 2: |
590 |
this.assignBand(renderBands[i], RasterDataStore.BLUE_BAND);
|
591 |
break;
|
592 |
} |
593 |
} |
594 |
} |
595 |
} |
596 |
} |
597 |
|
598 |
public void accept() { |
599 |
if (!getPanelGroup().isPanelInGUI(this)) |
600 |
return;
|
601 |
|
602 |
onlyApply(); |
603 |
} |
604 |
|
605 |
/**
|
606 |
* Aplica y guarda los cambios del panel
|
607 |
*/
|
608 |
public void apply() { |
609 |
if (!getPanelGroup().isPanelInGUI(this)) |
610 |
return;
|
611 |
|
612 |
onlyApply(); |
613 |
saveStatus(); |
614 |
} |
615 |
|
616 |
/**
|
617 |
* Aplicar los cambios sin guardar su estado
|
618 |
*/
|
619 |
public void onlyApply() { |
620 |
if (RasterPropertiesTocMenuEntry.enableEvents)
|
621 |
panelListener.apply(); |
622 |
} |
623 |
|
624 |
/**
|
625 |
* Guarda el estado actual del panel
|
626 |
*/
|
627 |
@SuppressWarnings("unchecked") |
628 |
private void saveStatus() { |
629 |
List<String> aux = new ArrayList<String>(); |
630 |
String[] valuesCI = fLayer.getRender().getRenderColorInterpretation().getValues(); |
631 |
for (int i = 0; i < valuesCI.length; i++) { |
632 |
aux.add(valuesCI[i]); |
633 |
} |
634 |
getPanelGroup().getProperties().put("renderBands", aux);
|
635 |
} |
636 |
|
637 |
|
638 |
/**
|
639 |
* Deja la capa en el ?ltimo estado guardado y la refresca
|
640 |
*/
|
641 |
@SuppressWarnings("unchecked") |
642 |
public void restoreStatus() { |
643 |
if (fLayer != null) |
644 |
return;
|
645 |
|
646 |
List<String> aux = (List<String>) getPanelGroup().getProperties().get("renderBands"); |
647 |
|
648 |
if(fLayer.getRender() != null) { |
649 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation((String[])aux.toArray()); |
650 |
fLayer.getRender().setRenderColorInterpretation(ci); |
651 |
} |
652 |
|
653 |
fLayer.getMapContext().invalidate(); |
654 |
} |
655 |
|
656 |
public void cancel() { |
657 |
if (!getPanelGroup().isPanelInGUI(this)) |
658 |
return;
|
659 |
|
660 |
restoreStatus(); |
661 |
} |
662 |
|
663 |
/**
|
664 |
* Activa y desactiva el control
|
665 |
* @param enabled true para activar y false para desactivar
|
666 |
*/
|
667 |
public void setEnabled(boolean enabled) { |
668 |
if (panelListener != null) |
669 |
panelListener.setEnabledPanelAction(enabled); |
670 |
getARGBTable().setEnabled(enabled); |
671 |
getFileList().setEnabled(enabled); |
672 |
} |
673 |
|
674 |
/**
|
675 |
* Sets the current layer when the panel is opened from
|
676 |
* raster properties
|
677 |
*/
|
678 |
public void setReference(Object ref) { |
679 |
super.setReference(ref);
|
680 |
|
681 |
if (!(ref instanceof FLyrRaster)) |
682 |
return;
|
683 |
|
684 |
fLayer = (FLyrRaster) ref; |
685 |
|
686 |
actionEnabled(); |
687 |
|
688 |
clear(); |
689 |
getFileList().clear(); |
690 |
|
691 |
//Si tiene tabla de color inicializamos solamente
|
692 |
|
693 |
if (fLayer.existColorTable()) {
|
694 |
((BandSelectorPropertiesListener)panelListener).init(fLayer); |
695 |
return;
|
696 |
} |
697 |
|
698 |
//Si no tiene tabla de color se a?aden los ficheros e inicializamos
|
699 |
try {
|
700 |
addFiles(fLayer.getDataStore()); |
701 |
} catch (NotInitializeException e) {
|
702 |
RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this); |
703 |
} |
704 |
|
705 |
((BandSelectorPropertiesListener)panelListener).init(fLayer); |
706 |
} |
707 |
|
708 |
public void componentHidden(ComponentEvent e) {} |
709 |
public void componentShown(ComponentEvent e) {} |
710 |
public void componentMoved(ComponentEvent e) {} |
711 |
|
712 |
|
713 |
public void selected() { |
714 |
setReference(fLayer); |
715 |
} |
716 |
} |