root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / BandSetupPanel.java @ 17042
History | View | Annotate | Download (22.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools.properties.panels; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.event.ActionEvent; |
24 |
import java.awt.event.ActionListener; |
25 |
import java.awt.event.ComponentEvent; |
26 |
import java.awt.event.ComponentListener; |
27 |
import java.awt.image.DataBuffer; |
28 |
import java.io.File; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Vector; |
31 |
|
32 |
import javax.swing.AbstractCellEditor; |
33 |
import javax.swing.JRadioButton; |
34 |
import javax.swing.JScrollPane; |
35 |
import javax.swing.JTable; |
36 |
import javax.swing.SwingConstants; |
37 |
import javax.swing.SwingUtilities; |
38 |
import javax.swing.event.TableModelEvent; |
39 |
import javax.swing.event.TableModelListener; |
40 |
import javax.swing.table.DefaultTableModel; |
41 |
import javax.swing.table.TableCellEditor; |
42 |
import javax.swing.table.TableCellRenderer; |
43 |
import javax.swing.table.TableColumn; |
44 |
|
45 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
46 |
import org.gvsig.fmap.raster.layers.IRasterLayerActions; |
47 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
48 |
import org.gvsig.raster.dataset.IRasterDataSource; |
49 |
import org.gvsig.raster.dataset.RasterDataset; |
50 |
import org.gvsig.raster.gui.properties.dialog.RasterPropertiesTocMenuEntry; |
51 |
import org.gvsig.raster.hierarchy.IRasterDataset; |
52 |
import org.gvsig.raster.hierarchy.IRasterProperties; |
53 |
import org.gvsig.raster.hierarchy.IRasterRendering; |
54 |
import org.gvsig.rastertools.properties.control.BandSetupListener; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
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 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
64 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
65 |
*/
|
66 |
public class BandSetupPanel extends AbstractPanel implements TableModelListener, ComponentListener { |
67 |
final private static long serialVersionUID = -3370601314380922368L; |
68 |
|
69 |
/**
|
70 |
* Variables para la asignaci?n de tama?o de los componentes del panel.
|
71 |
*/
|
72 |
private int wComp = 445, hComp = 239; |
73 |
private int wFileList = wComp, hFileList = (int)Math.round(hComp * 0.46); |
74 |
private int wBand = wFileList, hBand = hComp - hFileList - 20; |
75 |
|
76 |
/**
|
77 |
* Asigna la banda del rojo
|
78 |
*/
|
79 |
public static final int RED_BAND = RasterDataset.RED_BAND; |
80 |
|
81 |
/**
|
82 |
* Asigna la banda del verde
|
83 |
*/
|
84 |
public static final int GREEN_BAND = RasterDataset.GREEN_BAND; |
85 |
|
86 |
/**
|
87 |
* Asigna banda del azul
|
88 |
*/
|
89 |
public static final int BLUE_BAND = RasterDataset.BLUE_BAND; |
90 |
private final static String[] columnNames = { "R", "G", "B", "Band" }; |
91 |
|
92 |
FLayer fLayer = null;
|
93 |
|
94 |
/**
|
95 |
* Nombre del panel
|
96 |
*/
|
97 |
// private String id = "bands_panel";
|
98 |
private BandSetupFileList fileList = null; |
99 |
private JTable rgbTable = null; |
100 |
private JScrollPane rgbBandAssignPane = null; |
101 |
RGBBandAsignTableModel tableModel = null;
|
102 |
private byte mode = 3; |
103 |
// Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo
|
104 |
private int[] col = { 0, 1 }; |
105 |
private BandSetupListener panelListener = null; |
106 |
private IRasterProperties prop = null; |
107 |
private IRasterDataset dataset = null; |
108 |
private IRasterRendering render = null; |
109 |
|
110 |
/**
|
111 |
* This method initializes
|
112 |
*/
|
113 |
public BandSetupPanel() {
|
114 |
super();
|
115 |
initialize(); |
116 |
panelListener = new BandSetupListener(this); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* This method initializes this
|
121 |
*
|
122 |
* @return void
|
123 |
*/
|
124 |
protected void initialize() { |
125 |
// this.setPreferredSize(new Dimension(wComp, hComp));
|
126 |
this.setLayout(null); |
127 |
this.setLocation(0, 0); |
128 |
this.add(getFileList(), null); |
129 |
this.add(getRGBBandAssignPane(), null); |
130 |
this.addComponentListener(this); |
131 |
this.setComponentSize(wComp, hComp);
|
132 |
super.setLabel(PluginServices.getText(this, "bands_panel")); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* A?ade la lista de georasterfiles a la tabla
|
137 |
*
|
138 |
* @param files
|
139 |
*/
|
140 |
public void addFiles(IRasterDataSource mDataset) { |
141 |
getFileList().clear(); |
142 |
clear(); |
143 |
for (int i = 0; i < mDataset.getDatasetCount(); i++) { |
144 |
String fName = mDataset.getDataset(i)[0].getFName(); |
145 |
getFileList().addFName(fName); |
146 |
|
147 |
String bandName = new File(fName).getName(); |
148 |
String bandType = ""; |
149 |
|
150 |
switch (mDataset.getDataset(i)[0].getDataType()[0]) { |
151 |
case DataBuffer.TYPE_BYTE: |
152 |
bandType = "8U";
|
153 |
break;
|
154 |
case DataBuffer.TYPE_INT: |
155 |
bandType = "32";
|
156 |
break;
|
157 |
case DataBuffer.TYPE_DOUBLE: |
158 |
bandType = "64";
|
159 |
break;
|
160 |
case DataBuffer.TYPE_FLOAT: |
161 |
bandType = "32";
|
162 |
break;
|
163 |
case DataBuffer.TYPE_SHORT: |
164 |
bandType = "16";
|
165 |
break;
|
166 |
case DataBuffer.TYPE_USHORT: |
167 |
bandType = "16U";
|
168 |
break;
|
169 |
case DataBuffer.TYPE_UNDEFINED: |
170 |
bandType = "??";
|
171 |
break;
|
172 |
} |
173 |
|
174 |
for (int b = 0; b < mDataset.getDataset(i)[0].getBandCount(); b++) |
175 |
addBand((b + 1) + " [" + bandType + "] " + bandName); |
176 |
} |
177 |
readDrawedBands(); |
178 |
saveStatus(); |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Elimina un fichero de la lista
|
183 |
* @param file Nombre del fichero a eliminar
|
184 |
*/
|
185 |
public void removeFile(String file) { |
186 |
getFileList().removeFName(file); |
187 |
|
188 |
for (int i = 0; i < ((DefaultTableModel) getRGBTable().getModel()).getRowCount(); i++) { |
189 |
// Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
|
190 |
// esta visibilidad a la banda inmediata superior y si esta acci?n produce
|
191 |
// una excepci?n (porque no hay) se pasa al inmediato inferior.
|
192 |
if (((String) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 3)).endsWith(file)) { |
193 |
try {
|
194 |
if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 0)).booleanValue()) { |
195 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 0); |
196 |
} |
197 |
} catch (ArrayIndexOutOfBoundsException exc) { |
198 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 0); |
199 |
} |
200 |
|
201 |
try {
|
202 |
if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 1)).booleanValue()) { |
203 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1); |
204 |
} |
205 |
} catch (ArrayIndexOutOfBoundsException exc) { |
206 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1); |
207 |
} |
208 |
|
209 |
try {
|
210 |
if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 2)).booleanValue()) { |
211 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2); |
212 |
} |
213 |
} catch (ArrayIndexOutOfBoundsException exc) { |
214 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2); |
215 |
} |
216 |
|
217 |
((DefaultTableModel) getRGBTable().getModel()).removeRow(i);
|
218 |
i--; // Ojo! que hemos eliminado una fila
|
219 |
} |
220 |
} |
221 |
panelListener.setNewBandsPositionInRendering(); |
222 |
} |
223 |
|
224 |
public void assignMode(byte mode) { |
225 |
this.mode = mode;
|
226 |
} |
227 |
|
228 |
public byte getMode() { |
229 |
return mode;
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
|
234 |
* debemos resetear la tabla de checkbox para que no haya activados m?s de los
|
235 |
* permitidos
|
236 |
* @param mode
|
237 |
*/
|
238 |
public void resetMode(int mode) { |
239 |
// Reseteamos los checkbox
|
240 |
for (int i = 0; i < (getRGBTable().getColumnCount() - 1); i++) |
241 |
for (int j = 0; j < getRGBTable().getRowCount(); j++) |
242 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(false), j, i); |
243 |
|
244 |
// Asignamos los valores
|
245 |
if (this.getNBands() >= 3) { |
246 |
switch (mode) {
|
247 |
case 3: |
248 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 2, 2); |
249 |
case 2: |
250 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 1, 1); |
251 |
case 1: |
252 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 0); |
253 |
} |
254 |
} else if (this.getNBands() == 2) { |
255 |
switch (mode) {
|
256 |
case 3: |
257 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 1, 2); |
258 |
case 2: |
259 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 1, 1); |
260 |
case 1: |
261 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 0); |
262 |
} |
263 |
} else if (this.getNBands() == 1) { |
264 |
switch (mode) {
|
265 |
case 3: |
266 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 2); |
267 |
case 2: |
268 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 1); |
269 |
case 1: |
270 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(true), 0, 0); |
271 |
} |
272 |
} |
273 |
|
274 |
col[0] = 0; |
275 |
col[1] = 1; |
276 |
} |
277 |
|
278 |
/**
|
279 |
* Asigna modo 1, 2, o 3 bandas. El modo 1 solo permite seleccionar en la
|
280 |
* tabla un checkbox, el 2 dos checkbox en distintar bandas y el 3 tres
|
281 |
* checkbox tambi?n en distintas bandas.
|
282 |
* @param mode
|
283 |
*/
|
284 |
private void setMode(int mode) { |
285 |
// Solo hay un checkbox activado
|
286 |
if (mode == 1) { |
287 |
for (int i = 0; i < getRGBTable().getRowCount(); i++) |
288 |
for (int j = 0; j < (getRGBTable().getColumnCount() - 1); j++) { |
289 |
if ((i != getRGBTable().getSelectedRow()) || (j != getRGBTable().getSelectedColumn())) {
|
290 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(false), i, j); |
291 |
} |
292 |
} |
293 |
|
294 |
// Hay dos checkbox activados
|
295 |
} else if (mode == 2) { |
296 |
int n = 0; |
297 |
|
298 |
for (int i = 0; i < (getRGBTable().getColumnCount() - 1); i++) |
299 |
for (int j = 0; j < getRGBTable().getRowCount(); j++) |
300 |
if (((Boolean) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(j, i)).booleanValue()) { |
301 |
n++; |
302 |
} |
303 |
|
304 |
// Si se ha seleccionado 3 bandas hay eliminar una de ellas. Siempre ser?
|
305 |
// la m?s antigua que se clickeo
|
306 |
if (n > 2) { |
307 |
for (int i = 0; i < getRGBTable().getRowCount(); i++) |
308 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(new Boolean(false), i, col[0]); |
309 |
} |
310 |
|
311 |
// Rotamos el punto pinchado m?s antiguo para que se eliminen
|
312 |
// alternativamente
|
313 |
if ((col[0] == getRGBTable().getSelectedColumn()) || ((col[0] != getRGBTable().getSelectedColumn()) && (col[1] != getRGBTable().getSelectedColumn()))) { |
314 |
col[0] = col[1]; |
315 |
col[1] = getRGBTable().getSelectedColumn();
|
316 |
} |
317 |
|
318 |
// El modo 3 es el comportamiento original
|
319 |
} else if (mode == 3) { |
320 |
return;
|
321 |
} |
322 |
} |
323 |
|
324 |
/**
|
325 |
* Obtiene el panel que contiene la lista de ficheros por banda.
|
326 |
* @return Panel FileList
|
327 |
*/
|
328 |
public BandSetupFileList getFileList() {
|
329 |
if (fileList == null) { |
330 |
fileList = new BandSetupFileList();
|
331 |
} |
332 |
return fileList;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* This method initializes jTable
|
337 |
* @return javax.swing.JTable
|
338 |
*/
|
339 |
private JScrollPane getRGBBandAssignPane() { |
340 |
if (rgbBandAssignPane == null) { |
341 |
rgbBandAssignPane = new JScrollPane(getRGBTable()); |
342 |
|
343 |
TableColumn column = null; |
344 |
|
345 |
for (int i = 0; i < 3; i++) { |
346 |
column = getRGBTable().getColumnModel().getColumn(i); |
347 |
column.setCellRenderer(new RadioColumnRenderer());
|
348 |
column.setCellEditor(new RadioColumnEditor());
|
349 |
column.setMaxWidth(22);
|
350 |
column.setMinWidth(22);
|
351 |
} |
352 |
} |
353 |
|
354 |
return rgbBandAssignPane;
|
355 |
} |
356 |
|
357 |
/**
|
358 |
* Obtiene la Tabla
|
359 |
* @return Tabla de bandas de la imagen
|
360 |
*/
|
361 |
public JTable getRGBTable() { |
362 |
if (rgbTable == null) { |
363 |
tableModel = new RGBBandAsignTableModel();
|
364 |
tableModel.addTableModelListener(this);
|
365 |
rgbTable = new JTable(tableModel); |
366 |
rgbTable.setPreferredScrollableViewportSize(new Dimension(328, 72)); |
367 |
} |
368 |
return rgbTable;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Asigna al combo de n?mero de bandas a mostrar el valor correspondiente
|
373 |
* dependiendo del n?mero de bandas de la imagen.
|
374 |
*/
|
375 |
public void setList() { |
376 |
String[] l = null; |
377 |
|
378 |
if (this.getNBands() == 1) { |
379 |
l = new String[1]; |
380 |
l[0] = "1"; |
381 |
} |
382 |
|
383 |
if (this.getNBands() == 2) { |
384 |
l = new String[2]; |
385 |
l[0] = "1"; |
386 |
l[1] = "2"; |
387 |
} |
388 |
|
389 |
if (this.getNBands() == 3) { |
390 |
l = new String[3]; |
391 |
l[0] = "1"; |
392 |
l[1] = "2"; |
393 |
l[2] = "3"; |
394 |
} |
395 |
|
396 |
if (this.getNBands() > 0) { |
397 |
getFileList().setList(l); |
398 |
} |
399 |
} |
400 |
|
401 |
/**
|
402 |
* A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
|
403 |
* valor a los checkbox
|
404 |
* @param bandName Nombre de la banda
|
405 |
*/
|
406 |
private void addBand(String bandName) { |
407 |
Vector v = new Vector(); |
408 |
v.add(new Boolean(false)); |
409 |
v.add(new Boolean(false)); |
410 |
v.add(new Boolean(false)); |
411 |
v.add(bandName); |
412 |
((DefaultTableModel) getRGBTable().getModel()).addRow(v);
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* Elimina todas las entradas de la tabla de bandas.
|
417 |
*/
|
418 |
private void clear() { |
419 |
int rows = ((DefaultTableModel) getRGBTable().getModel()).getRowCount(); |
420 |
if (rows > 0) { |
421 |
for (int i = 0; i < rows; i++) |
422 |
((DefaultTableModel) getRGBTable().getModel()).removeRow(0); |
423 |
} |
424 |
} |
425 |
|
426 |
/**
|
427 |
* Obtiene el n?mero de bandas de la lista
|
428 |
*
|
429 |
* @return
|
430 |
*/
|
431 |
public int getNBands() { |
432 |
return ((DefaultTableModel) getRGBTable().getModel()).getRowCount(); |
433 |
} |
434 |
|
435 |
/**
|
436 |
* Obtiene el nombre de la banda de la posici?n i de la tabla
|
437 |
*
|
438 |
* @param i
|
439 |
* @return
|
440 |
*/
|
441 |
public String getBandName(int i) { |
442 |
String s = (String) ((DefaultTableModel) getRGBTable().getModel()).getValueAt(i, 3); |
443 |
return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
444 |
} |
445 |
|
446 |
/**
|
447 |
* Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le
|
448 |
* corresponde
|
449 |
*
|
450 |
* @param nBand Banda de la imagen que corresponde
|
451 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
452 |
*/
|
453 |
public void assignBand(int nBand, int flag) { |
454 |
Boolean t = new Boolean(true); |
455 |
try {
|
456 |
if ((flag & RED_BAND) == RED_BAND)
|
457 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 0); |
458 |
|
459 |
if ((flag & GREEN_BAND) == GREEN_BAND)
|
460 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 1); |
461 |
|
462 |
if ((flag & BLUE_BAND) == BLUE_BAND)
|
463 |
((DefaultTableModel) getRGBTable().getModel()).setValueAt(t, nBand, 2); |
464 |
} catch (ArrayIndexOutOfBoundsException e) { |
465 |
|
466 |
} |
467 |
} |
468 |
|
469 |
/**
|
470 |
* Obtiene la correspondencia entre el R, G o B y la banda asignada
|
471 |
*
|
472 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
473 |
* @return Banda de la imagen asignada al flag pasado por par?metro
|
474 |
*/
|
475 |
public int getAssignedBand(int flag) { |
476 |
DefaultTableModel model = ((DefaultTableModel) getRGBTable().getModel()); |
477 |
if ((flag & RED_BAND) == RED_BAND) {
|
478 |
for (int nBand = 0; nBand < getRGBTable().getRowCount(); nBand++) |
479 |
if (((Boolean) model.getValueAt(nBand, 0)).booleanValue()) |
480 |
return nBand;
|
481 |
} |
482 |
|
483 |
if ((flag & GREEN_BAND) == GREEN_BAND) {
|
484 |
for (int nBand = 0; nBand < getRGBTable().getRowCount(); nBand++) |
485 |
if (((Boolean) model.getValueAt(nBand, 1)).booleanValue()) |
486 |
return nBand;
|
487 |
} |
488 |
|
489 |
if ((flag & BLUE_BAND) == BLUE_BAND) {
|
490 |
for (int nBand = 0; nBand < getRGBTable().getRowCount(); nBand++) |
491 |
if (((Boolean) model.getValueAt(nBand, 2)).booleanValue()) |
492 |
return nBand;
|
493 |
} |
494 |
|
495 |
return -1; |
496 |
} |
497 |
|
498 |
/*
|
499 |
* (non-Javadoc)
|
500 |
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
|
501 |
*/
|
502 |
public void tableChanged(TableModelEvent e) { |
503 |
getRGBTable().revalidate(); |
504 |
rgbBandAssignPane.revalidate(); |
505 |
revalidate(); |
506 |
} |
507 |
|
508 |
class RadioColumnEditor extends AbstractCellEditor implements TableCellEditor { |
509 |
final private static long serialVersionUID = -3370601314380922368L; |
510 |
public JRadioButton theRadioButton; |
511 |
|
512 |
public RadioColumnEditor() {
|
513 |
super();
|
514 |
theRadioButton = new JRadioButton(); |
515 |
theRadioButton.addActionListener(new ActionListener() { |
516 |
public void actionPerformed(ActionEvent event) { |
517 |
fireEditingStopped(); |
518 |
setMode(mode); |
519 |
onlyApply(); |
520 |
} |
521 |
}); |
522 |
} |
523 |
|
524 |
public Component getTableCellEditorComponent(JTable table, Object obj, boolean isSelected, int row, int col) { |
525 |
theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER);
|
526 |
|
527 |
Boolean lValueAsBoolean = (Boolean) obj; |
528 |
theRadioButton.setSelected(lValueAsBoolean.booleanValue()); |
529 |
|
530 |
return theRadioButton;
|
531 |
} |
532 |
|
533 |
public Object getCellEditorValue() { |
534 |
return new Boolean(theRadioButton.isSelected()); |
535 |
} |
536 |
} |
537 |
|
538 |
class RadioColumnRenderer extends JRadioButton implements TableCellRenderer { |
539 |
final private static long serialVersionUID = -3370601314380922368L; |
540 |
|
541 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
542 |
if (value == null) { |
543 |
this.setSelected(false); |
544 |
} |
545 |
|
546 |
Boolean ValueAsBoolean = (Boolean) value; |
547 |
this.setSelected(ValueAsBoolean.booleanValue());
|
548 |
this.setHorizontalAlignment(SwingConstants.CENTER); |
549 |
|
550 |
return this; |
551 |
} |
552 |
} |
553 |
|
554 |
class RGBBandAsignTableModel extends DefaultTableModel { |
555 |
final private static long serialVersionUID = -3370601314380922368L; |
556 |
|
557 |
public RGBBandAsignTableModel() {
|
558 |
super(new Object[0][4], columnNames); |
559 |
} |
560 |
|
561 |
public Class getColumnClass(int c) { |
562 |
if (c < 3) { |
563 |
return Boolean.class; |
564 |
} |
565 |
|
566 |
return String.class; |
567 |
} |
568 |
|
569 |
public void setValueAt(Object value, int row, int col) { |
570 |
if ((col < 3) && ((Boolean) value).booleanValue()) { |
571 |
for (int i = 0; i < getRowCount(); i++) { |
572 |
if (i != row) {
|
573 |
setValueAt(new Boolean(false), i, col); |
574 |
} |
575 |
} |
576 |
} |
577 |
|
578 |
super.setValueAt(value, row, col);
|
579 |
} |
580 |
|
581 |
public void addNew() { |
582 |
super.addRow(new Object[] { new Boolean(false), new Boolean(false), new Boolean(false), "" }); |
583 |
} |
584 |
} |
585 |
|
586 |
public void setComponentSize(int w, int h) { |
587 |
wComp = w; |
588 |
hComp = h; |
589 |
wFileList = wComp - 18;
|
590 |
hFileList = (int) Math.round(hComp * 0.46); |
591 |
wBand = wFileList; |
592 |
hBand = hComp - hFileList - 20;
|
593 |
|
594 |
this.setPreferredSize(new Dimension(wComp, hComp)); |
595 |
this.setSize(wComp, hComp);
|
596 |
rgbBandAssignPane.setBounds(10, hFileList + 12, wBand, hBand); |
597 |
getFileList().setBounds(9, 9, wFileList, hFileList); |
598 |
|
599 |
} |
600 |
|
601 |
/**
|
602 |
* Redimensiona el panel cuando se redimensiona el contenedor de ?ste
|
603 |
*/
|
604 |
public void componentResized(ComponentEvent e) { |
605 |
if (e.getSource() == this) { |
606 |
int nWidth = this.getSize().width; |
607 |
int nHeight = this.getSize().height; |
608 |
int difWidth = nWidth - 445; |
609 |
int difHeight = nHeight - 239; |
610 |
getFileList().setResize(difWidth, difHeight); |
611 |
rgbBandAssignPane.setBounds(10, 123 + difHeight / 2, 427 + difWidth, 104 + difHeight / 2); |
612 |
|
613 |
} |
614 |
} |
615 |
|
616 |
private void actionEnabled() { |
617 |
boolean enabled = true; |
618 |
|
619 |
FLyrRasterSE fLyrRasterSE = ((FLyrRasterSE) fLayer); |
620 |
|
621 |
if (!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST))
|
622 |
enabled = false;
|
623 |
getFileList().setEnabled(enabled); |
624 |
|
625 |
enabled = true;
|
626 |
if (!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_RGB))
|
627 |
enabled = false;
|
628 |
getRGBTable().setEnabled(enabled); |
629 |
|
630 |
// TODO: Mirar el setVisible...
|
631 |
if (!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST) &&
|
632 |
!fLyrRasterSE.isActionEnabled(IRasterLayerActions.BANDS_RGB)) |
633 |
setVisible(false);
|
634 |
else
|
635 |
setVisible(true);
|
636 |
} |
637 |
|
638 |
/**
|
639 |
* Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho.
|
640 |
*/
|
641 |
public void readDrawedBands() { |
642 |
if (prop.getRender() != null) { |
643 |
int[] renderBands = render.getRenderBands(); |
644 |
for (int i = 0; i < renderBands.length; i++) { |
645 |
if (renderBands[i] >= 0) { |
646 |
switch (i) {
|
647 |
case 0: |
648 |
this.assignBand(renderBands[i], RasterDataset.RED_BAND);
|
649 |
break;
|
650 |
case 1: |
651 |
this.assignBand(renderBands[i], RasterDataset.GREEN_BAND);
|
652 |
break;
|
653 |
case 2: |
654 |
this.assignBand(renderBands[i], RasterDataset.BLUE_BAND);
|
655 |
break;
|
656 |
} |
657 |
} |
658 |
} |
659 |
} |
660 |
} |
661 |
|
662 |
/*
|
663 |
* (non-Javadoc)
|
664 |
* @see org.gvsig.gui.beans.panelGroup.panels.IPanel#accept()
|
665 |
*/
|
666 |
public void accept() { |
667 |
if (!getPanelGroup().isPanelInGUI(this)) |
668 |
return;
|
669 |
|
670 |
onlyApply(); |
671 |
} |
672 |
|
673 |
/**
|
674 |
* Aplica y guarda los cambios del panel
|
675 |
*/
|
676 |
public void apply() { |
677 |
if (!getPanelGroup().isPanelInGUI(this)) |
678 |
return;
|
679 |
|
680 |
onlyApply(); |
681 |
saveStatus(); |
682 |
} |
683 |
|
684 |
/**
|
685 |
* Aplicar los cambios sin guardar su estado
|
686 |
*/
|
687 |
public void onlyApply() { |
688 |
if (RasterPropertiesTocMenuEntry.enableEvents)
|
689 |
panelListener.apply(); |
690 |
} |
691 |
|
692 |
/**
|
693 |
* Guarda el estado actual del panel
|
694 |
*/
|
695 |
private void saveStatus() { |
696 |
ArrayList aux = new ArrayList(); |
697 |
int[] renderBands = render.getRenderBands(); |
698 |
for (int i = 0; i < renderBands.length; i++) { |
699 |
aux.add(new Integer(renderBands[i])); |
700 |
} |
701 |
|
702 |
getPanelGroup().getProperties().put("renderBands", aux);
|
703 |
} |
704 |
|
705 |
|
706 |
/**
|
707 |
* Deja la capa en el ?ltimo estado guardado y la refresca
|
708 |
*/
|
709 |
public void restoreStatus() { |
710 |
|
711 |
ArrayList aux = (ArrayList) getPanelGroup().getProperties().get("renderBands"); |
712 |
|
713 |
int[] renderBands = new int[aux.size()]; |
714 |
for (int i = 0; i < aux.size(); i++) |
715 |
renderBands[i] = ((Integer) aux.get(i)).intValue();
|
716 |
|
717 |
render.setRenderBands(renderBands); |
718 |
|
719 |
if (fLayer != null) |
720 |
fLayer.getMapContext().invalidate(); |
721 |
} |
722 |
|
723 |
/*
|
724 |
* (non-Javadoc)
|
725 |
* @see org.gvsig.gui.beans.panelGroup.panels.IPanel#cancel()
|
726 |
*/
|
727 |
public void cancel() { |
728 |
if (!getPanelGroup().isPanelInGUI(this)) |
729 |
return;
|
730 |
|
731 |
restoreStatus(); |
732 |
} |
733 |
|
734 |
/**
|
735 |
* Activa y desactiva el control
|
736 |
* @param enabled true para activar y false para desactivar
|
737 |
*/
|
738 |
public void setEnabled(boolean enabled) { |
739 |
if (panelListener != null) |
740 |
panelListener.setEnabledPanelAction(enabled); |
741 |
getRGBTable().setEnabled(enabled); |
742 |
getRGBBandAssignPane().setEnabled(enabled); |
743 |
getFileList().setEnabled(enabled); |
744 |
} |
745 |
|
746 |
/*
|
747 |
* (non-Javadoc)
|
748 |
* @see org.gvsig.gui.beans.panelGroup.panels.AbstractPanel#setReference(java.lang.Object)
|
749 |
*/
|
750 |
public void setReference(Object ref) { |
751 |
super.setReference(ref);
|
752 |
|
753 |
if (!(ref instanceof FLayer)) |
754 |
return;
|
755 |
|
756 |
fLayer = (FLayer) ref; |
757 |
|
758 |
actionEnabled(); |
759 |
|
760 |
clear(); |
761 |
getFileList().clear(); |
762 |
|
763 |
if (fLayer instanceof IRasterProperties) |
764 |
prop = (IRasterProperties) fLayer; |
765 |
|
766 |
if (fLayer instanceof IRasterRendering) { |
767 |
render = (IRasterRendering)fLayer; |
768 |
if (((IRasterRendering) fLayer).existColorTable()) {
|
769 |
panelListener.init(null, null, fLayer); |
770 |
return;
|
771 |
} |
772 |
} |
773 |
|
774 |
if (fLayer instanceof IRasterDataset) { |
775 |
dataset = (IRasterDataset) fLayer; |
776 |
addFiles(dataset.getDataSource()); |
777 |
} |
778 |
|
779 |
panelListener.init(dataset, prop, fLayer); |
780 |
} |
781 |
|
782 |
public void componentHidden(ComponentEvent e) {} |
783 |
public void componentShown(ComponentEvent e) {} |
784 |
public void componentMoved(ComponentEvent e) {} |
785 |
public void selected() {} |
786 |
} |