gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.multifile / src / main / java / org / gvsig / raster / tools / app / multifile / panel / BandSelectorPanel.java @ 723
History | View | Annotate | Download (20 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.tools.app.multifile.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.andami.PluginServices; |
42 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
43 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
44 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
45 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
46 |
import org.gvsig.gui.beans.table.TableContainer; |
47 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
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(PluginServices.getText(this, "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("Bandas");
|
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(RasterToolsUtil.getText(this, "save")); |
203 |
saveButton.setToolTipText(RasterToolsUtil.getText(this, "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 |
String[] files = dstore.getURIByProvider(); |
219 |
for (int i = 0; i < files.length; i++) { |
220 |
getFileList().addFName(files[i]); |
221 |
} |
222 |
|
223 |
int nbands = dstore.getBandCount();
|
224 |
for (int i = 0; i < nbands; i++) { |
225 |
String fName = dstore.getURIByBand(i);
|
226 |
|
227 |
String bandName = new File(fName).getName(); |
228 |
String bandType = ""; |
229 |
|
230 |
switch (dstore.getDataType()[0]) { |
231 |
case DataBuffer.TYPE_BYTE: |
232 |
bandType = "8U";
|
233 |
break;
|
234 |
case DataBuffer.TYPE_INT: |
235 |
bandType = "32";
|
236 |
break;
|
237 |
case DataBuffer.TYPE_DOUBLE: |
238 |
bandType = "64";
|
239 |
break;
|
240 |
case DataBuffer.TYPE_FLOAT: |
241 |
bandType = "32";
|
242 |
break;
|
243 |
case DataBuffer.TYPE_SHORT: |
244 |
bandType = "16";
|
245 |
break;
|
246 |
case DataBuffer.TYPE_USHORT: |
247 |
bandType = "16U";
|
248 |
break;
|
249 |
case DataBuffer.TYPE_UNDEFINED: |
250 |
bandType = "??";
|
251 |
break;
|
252 |
} |
253 |
|
254 |
addBand((nbands + 1) + " [" + bandType + "] " + bandName); |
255 |
} |
256 |
readDrawedBands(); |
257 |
saveStatus(); |
258 |
//evaluateControlsEnabled();
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* Elimina un fichero de la lista
|
263 |
* @param file Nombre del fichero a eliminar
|
264 |
*/
|
265 |
public void removeFile(String file) { |
266 |
getFileList().removeFName(file); |
267 |
|
268 |
for (int i = 0; i < ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); i++) { |
269 |
// Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
|
270 |
// esta visibilidad a la banda inmediata superior y si esta acci?n produce
|
271 |
// una excepci?n (porque no hay) se pasa al inmediato inferior.
|
272 |
if (((String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 4)).endsWith(file)) { |
273 |
try {
|
274 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 0)).booleanValue()) { |
275 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1); |
276 |
} |
277 |
} catch (ArrayIndexOutOfBoundsException exc) { |
278 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1); |
279 |
} |
280 |
|
281 |
try {
|
282 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 1)).booleanValue()) { |
283 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2); |
284 |
} |
285 |
} catch (ArrayIndexOutOfBoundsException exc) { |
286 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2); |
287 |
} |
288 |
|
289 |
try {
|
290 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 2)).booleanValue()) { |
291 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 3); |
292 |
} |
293 |
} catch (ArrayIndexOutOfBoundsException exc) { |
294 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 3); |
295 |
} |
296 |
|
297 |
((DefaultTableModel) getARGBTable().getModel()).removeRow(i);
|
298 |
i--; // Ojo! que hemos eliminado una fila
|
299 |
} |
300 |
} |
301 |
panelListener.setNewBandsPositionInRendering(); |
302 |
//evaluateControlsEnabled();
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* Evalua la habilitaci?n o desabilitaci?n de controles
|
307 |
*/
|
308 |
/*public void evaluateControlsEnabled() {
|
309 |
if(getFileList().getNFiles() > 1)
|
310 |
getSaveButton().setEnabled(false);
|
311 |
else
|
312 |
getSaveButton().setEnabled(true);
|
313 |
}*/
|
314 |
|
315 |
/**
|
316 |
* Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
|
317 |
* debemos resetear la tabla de checkbox para que no haya activados m?s de los
|
318 |
* permitidos
|
319 |
* @param mode
|
320 |
*/
|
321 |
public void resetMode(int mode) { |
322 |
DefaultTableModel model = getARGBTable().getModel();
|
323 |
// Reseteamos los checkbox
|
324 |
for (int i = 0; i < (model.getColumnCount() - 1); i++) |
325 |
for (int j = 0; j < model.getRowCount(); j++) |
326 |
model.setValueAt(Boolean.FALSE, j, i);
|
327 |
|
328 |
// Asignamos los valores
|
329 |
if (getNBands() >= 1) { |
330 |
switch (mode) {
|
331 |
case 3: |
332 |
int b = 2; |
333 |
if (getNBands() < 3) |
334 |
b = getNBands() - 1;
|
335 |
model.setValueAt(Boolean.TRUE, b, 3); |
336 |
case 2: |
337 |
int g = 1; |
338 |
if (getNBands() == 1) |
339 |
g = 0;
|
340 |
model.setValueAt(Boolean.TRUE, g, 2); |
341 |
case 1: |
342 |
model.setValueAt(Boolean.TRUE, 0, 1); |
343 |
} |
344 |
} |
345 |
|
346 |
col[0] = 0; |
347 |
col[1] = 1; |
348 |
} |
349 |
|
350 |
/**
|
351 |
* A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
|
352 |
* valor a los checkbox
|
353 |
* @param bandName Nombre de la banda
|
354 |
* @throws NotInitializeException
|
355 |
*/
|
356 |
private void addBand(String bandName) throws NotInitializeException { |
357 |
Object[] row = { new Boolean(false), |
358 |
new Boolean(false), |
359 |
new Boolean(false), |
360 |
new Boolean(false), |
361 |
bandName }; |
362 |
getARGBTable().addRow(row); |
363 |
} |
364 |
|
365 |
/**
|
366 |
* Elimina todas las entradas de la tabla de bandas.
|
367 |
*/
|
368 |
private void clear() { |
369 |
int rows = ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); |
370 |
if (rows > 0) { |
371 |
for (int i = 0; i < rows; i++) |
372 |
((DefaultTableModel) getARGBTable().getModel()).removeRow(0); |
373 |
} |
374 |
} |
375 |
|
376 |
/**
|
377 |
* Obtiene el n?mero de bandas de la lista
|
378 |
*
|
379 |
* @return
|
380 |
*/
|
381 |
public int getNBands() { |
382 |
return ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); |
383 |
} |
384 |
|
385 |
/**
|
386 |
* Obtiene el nombre de la banda de la posici?n i de la tabla
|
387 |
*
|
388 |
* @param i
|
389 |
* @return
|
390 |
*/
|
391 |
public String getBandName(int i) { |
392 |
String s = (String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 3); |
393 |
return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
394 |
} |
395 |
|
396 |
/**
|
397 |
* Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
|
398 |
* corresponde
|
399 |
*
|
400 |
* @param nBand Banda de la imagen que corresponde
|
401 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
402 |
*/
|
403 |
public void assignBand(int nBand, int flag) { |
404 |
Boolean t = new Boolean(true); |
405 |
try {
|
406 |
if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND)
|
407 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 0); |
408 |
|
409 |
if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND)
|
410 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 1); |
411 |
|
412 |
if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND)
|
413 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 2); |
414 |
|
415 |
if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND)
|
416 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 3); |
417 |
} catch (ArrayIndexOutOfBoundsException e) { |
418 |
|
419 |
} |
420 |
} |
421 |
|
422 |
/**
|
423 |
* Obtiene la correspondencia entre el R, G o B y la banda asignada
|
424 |
*
|
425 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
426 |
* @return Banda de la imagen asignada al flag pasado por par?metro
|
427 |
*/
|
428 |
public int getAssignedBand(int flag) { |
429 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
430 |
if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND) {
|
431 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
432 |
if (((Boolean) model.getValueAt(nBand, 0)).booleanValue()) |
433 |
return nBand;
|
434 |
} |
435 |
|
436 |
if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND) {
|
437 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
438 |
if (((Boolean) model.getValueAt(nBand, 1)).booleanValue()) |
439 |
return nBand;
|
440 |
} |
441 |
|
442 |
if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND) {
|
443 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
444 |
if (((Boolean) model.getValueAt(nBand, 2)).booleanValue()) |
445 |
return nBand;
|
446 |
} |
447 |
|
448 |
if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND) {
|
449 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
450 |
if (((Boolean) model.getValueAt(nBand, 3)).booleanValue()) |
451 |
return nBand;
|
452 |
} |
453 |
|
454 |
return -1; |
455 |
} |
456 |
|
457 |
/**
|
458 |
* Obtiene la interpretaci?n de color por n?mero de banda
|
459 |
* @param nBand N?mero de banda
|
460 |
* @return Interpretaci?n de color. Constante definida en DatasetColorInterpretation
|
461 |
*/
|
462 |
public String getColorInterpretationByBand(int nBand) { |
463 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
464 |
try {
|
465 |
for (int iBand = 0; iBand < getARGBTable().getRowCount(); iBand++) { |
466 |
for (int col = 0; col < 4; col++) { |
467 |
if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) { |
468 |
switch (col) {
|
469 |
case 0: return ColorInterpretation.ALPHA_BAND; |
470 |
case 1: return ColorInterpretation.RED_BAND; |
471 |
case 2: return ColorInterpretation.GREEN_BAND; |
472 |
case 3: return ColorInterpretation.BLUE_BAND; |
473 |
} |
474 |
} |
475 |
} |
476 |
} |
477 |
} catch (NotInitializeException e) {
|
478 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
479 |
} |
480 |
return ColorInterpretation.UNDEF_BAND;
|
481 |
} |
482 |
|
483 |
/*
|
484 |
* (non-Javadoc)
|
485 |
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
|
486 |
*/
|
487 |
public void tableChanged(TableModelEvent e) { |
488 |
getARGBTable().revalidate(); |
489 |
revalidate(); |
490 |
} |
491 |
|
492 |
|
493 |
/**
|
494 |
* Activa o desactiva la funcionalidad
|
495 |
*/
|
496 |
private void actionEnabled() { |
497 |
boolean enabled = true; |
498 |
|
499 |
IRasterLayerActions actions = null;
|
500 |
|
501 |
if(fLayer instanceof IRasterLayerActions) |
502 |
actions = (IRasterLayerActions)fLayer; |
503 |
|
504 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST))
|
505 |
enabled = false;
|
506 |
getFileList().setEnabled(enabled); |
507 |
|
508 |
enabled = true;
|
509 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB))
|
510 |
enabled = false;
|
511 |
getARGBTable().setEnabled(enabled); |
512 |
|
513 |
// TODO: Mirar el setVisible...
|
514 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST) &&
|
515 |
!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB)) |
516 |
setVisible(false);
|
517 |
else
|
518 |
setVisible(true);
|
519 |
|
520 |
if (!actions.isActionEnabled(IRasterLayerActions.SAVE_COLORINTERP))
|
521 |
getSaveButton().setVisible(false);
|
522 |
} |
523 |
|
524 |
/**
|
525 |
* Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho.
|
526 |
*/
|
527 |
public void readDrawedBands() { |
528 |
if (fLayer.getRender() != null) { |
529 |
int[] renderBands = fLayer.getRender().getRenderBands(); |
530 |
Transparency transp = fLayer.getRender().getLastTransparency();
|
531 |
if(transp != null && transp.isTransparencyActive() && transp.getAlphaBandNumber() != -1) |
532 |
this.assignBand(transp.getAlphaBandNumber(), RasterDataStore.ALPHA_BAND);
|
533 |
for (int i = 0; i < renderBands.length; i++) { |
534 |
if (renderBands[i] >= 0) { |
535 |
switch (i) {
|
536 |
case 0: |
537 |
this.assignBand(renderBands[i], RasterDataStore.RED_BAND);
|
538 |
break;
|
539 |
case 1: |
540 |
this.assignBand(renderBands[i], RasterDataStore.GREEN_BAND);
|
541 |
break;
|
542 |
case 2: |
543 |
this.assignBand(renderBands[i], RasterDataStore.BLUE_BAND);
|
544 |
break;
|
545 |
} |
546 |
} |
547 |
} |
548 |
} |
549 |
} |
550 |
|
551 |
/*
|
552 |
* (non-Javadoc)
|
553 |
* @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
|
554 |
*/
|
555 |
public void accept() { |
556 |
if (!getPanelGroup().isPanelInGUI(this)) |
557 |
return;
|
558 |
|
559 |
onlyApply(); |
560 |
} |
561 |
|
562 |
/**
|
563 |
* Aplica y guarda los cambios del panel
|
564 |
*/
|
565 |
public void apply() { |
566 |
if (!getPanelGroup().isPanelInGUI(this)) |
567 |
return;
|
568 |
|
569 |
onlyApply(); |
570 |
saveStatus(); |
571 |
} |
572 |
|
573 |
/**
|
574 |
* Aplicar los cambios sin guardar su estado
|
575 |
*/
|
576 |
public void onlyApply() { |
577 |
if (RasterPropertiesTocMenuEntry.enableEvents)
|
578 |
panelListener.apply(); |
579 |
} |
580 |
|
581 |
/**
|
582 |
* Guarda el estado actual del panel
|
583 |
*/
|
584 |
@SuppressWarnings("unchecked") |
585 |
private void saveStatus() { |
586 |
ArrayList<Integer> aux = new ArrayList<Integer>(); |
587 |
int[] renderBands = fLayer.getRender().getRenderBands(); |
588 |
for (int i = 0; i < renderBands.length; i++) { |
589 |
aux.add(new Integer(renderBands[i])); |
590 |
} |
591 |
int alphaBand = fLayer.getRender().getLastAlphaBandNumber();
|
592 |
getPanelGroup().getProperties().put("alphaBand", new Integer(alphaBand)); |
593 |
getPanelGroup().getProperties().put("renderBands", aux);
|
594 |
} |
595 |
|
596 |
|
597 |
/**
|
598 |
* Deja la capa en el ?ltimo estado guardado y la refresca
|
599 |
*/
|
600 |
@SuppressWarnings("unchecked") |
601 |
public void restoreStatus() { |
602 |
ArrayList aux = (ArrayList) getPanelGroup().getProperties().get("renderBands"); |
603 |
Integer alphaBand = (Integer) getPanelGroup().getProperties().get("alphaBand"); |
604 |
|
605 |
int[] renderBands = new int[aux.size()]; |
606 |
for (int i = 0; i < aux.size(); i++) |
607 |
renderBands[i] = ((Integer) aux.get(i)).intValue();
|
608 |
|
609 |
fLayer.getRender().setRenderBands(renderBands); |
610 |
if(alphaBand != null) { |
611 |
// Ultima transparencia aplicada en el renderizador
|
612 |
Transparency gt = fLayer.getRender().getLastTransparency();
|
613 |
if(gt != null) |
614 |
gt.setTransparencyBand(alphaBand.intValue()); |
615 |
} |
616 |
|
617 |
if (fLayer != null) |
618 |
fLayer.getMapContext().invalidate(); |
619 |
} |
620 |
|
621 |
/*
|
622 |
* (non-Javadoc)
|
623 |
* @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
|
624 |
*/
|
625 |
public void cancel() { |
626 |
if (!getPanelGroup().isPanelInGUI(this)) |
627 |
return;
|
628 |
|
629 |
restoreStatus(); |
630 |
} |
631 |
|
632 |
/**
|
633 |
* Activa y desactiva el control
|
634 |
* @param enabled true para activar y false para desactivar
|
635 |
*/
|
636 |
public void setEnabled(boolean enabled) { |
637 |
if (panelListener != null) |
638 |
panelListener.setEnabledPanelAction(enabled); |
639 |
getARGBTable().setEnabled(enabled); |
640 |
getFileList().setEnabled(enabled); |
641 |
} |
642 |
|
643 |
/*
|
644 |
* (non-Javadoc)
|
645 |
* @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
|
646 |
*/
|
647 |
public void setReference(Object ref) { |
648 |
super.setReference(ref);
|
649 |
|
650 |
if (!(ref instanceof FLyrRaster)) |
651 |
return;
|
652 |
|
653 |
fLayer = (FLyrRaster) ref; |
654 |
|
655 |
actionEnabled(); |
656 |
|
657 |
clear(); |
658 |
getFileList().clear(); |
659 |
|
660 |
//Si tiene tabla de color inicializamos solamente
|
661 |
|
662 |
if (fLayer.existColorTable()) {
|
663 |
panelListener.init(fLayer); |
664 |
return;
|
665 |
} |
666 |
|
667 |
//Si no tiene tabla de color se a?aden los ficheros e inicializamos
|
668 |
try {
|
669 |
addFiles(fLayer.getDataStore()); |
670 |
} catch (NotInitializeException e) {
|
671 |
RasterToolsUtil.messageBoxError("table_not_initialize", this); |
672 |
} |
673 |
|
674 |
panelListener.init(fLayer); |
675 |
} |
676 |
|
677 |
public void componentHidden(ComponentEvent e) {} |
678 |
public void componentShown(ComponentEvent e) {} |
679 |
public void componentMoved(ComponentEvent e) {} |
680 |
public void selected() {} |
681 |
} |