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