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