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