svn-gvsig-desktop / tags / v1_0_2_Build_899 / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / BandSetupPanel.java @ 10517
History | View | Annotate | Download (22.8 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.ui.raster; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.awt.event.ComponentEvent; |
31 |
import java.awt.event.ComponentListener; |
32 |
import java.awt.event.KeyEvent; |
33 |
import java.awt.event.KeyListener; |
34 |
import java.awt.image.DataBuffer; |
35 |
import java.io.File; |
36 |
import java.util.Vector; |
37 |
|
38 |
import javax.swing.AbstractCellEditor; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JRadioButton; |
41 |
import javax.swing.JScrollPane; |
42 |
import javax.swing.JTable; |
43 |
import javax.swing.SwingConstants; |
44 |
import javax.swing.SwingUtilities; |
45 |
import javax.swing.event.TableModelEvent; |
46 |
import javax.swing.event.TableModelListener; |
47 |
import javax.swing.table.DefaultTableModel; |
48 |
import javax.swing.table.TableCellEditor; |
49 |
import javax.swing.table.TableCellRenderer; |
50 |
import javax.swing.table.TableColumn; |
51 |
|
52 |
import org.cresques.io.GeoRasterFile; |
53 |
|
54 |
|
55 |
/**
|
56 |
* Selecciona las bandas visibles en un raster. Contiene una tabla con una fila por cada
|
57 |
* banda de la imagen. Por medio de checkbox se selecciona para cada RGB que banda de la
|
58 |
* imagen ser? visualizada.
|
59 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
60 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
61 |
*/
|
62 |
public class BandSetupPanel extends JPanel implements TableModelListener, |
63 |
KeyListener,
|
64 |
ActionListener,
|
65 |
ComponentListener,
|
66 |
IResize{ |
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 = GeoRasterFile.RED_BAND; |
80 |
|
81 |
/**
|
82 |
* Asigna la banda del verde
|
83 |
*/
|
84 |
public static final int GREEN_BAND = GeoRasterFile.GREEN_BAND; |
85 |
|
86 |
/**
|
87 |
* Asigna banda del azul
|
88 |
*/
|
89 |
public static final int BLUE_BAND = GeoRasterFile.BLUE_BAND; |
90 |
private final static String[] columnNames = { "R", "G", "B", "Band" }; |
91 |
|
92 |
/**
|
93 |
* Nombre del panel
|
94 |
*/
|
95 |
private String nom = "Bandas"; |
96 |
private FileList fileList = null; |
97 |
private JTable rgbTable = null; |
98 |
private JScrollPane rgbBandAssignPane = null; |
99 |
RGBBandAsignTableModel tableModel = null;
|
100 |
private int sizeX = 445; |
101 |
private int sizeY = 174; |
102 |
private byte mode = 3; |
103 |
private int[] col = { 0, 1 }; //Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo |
104 |
|
105 |
/**
|
106 |
* This method initializes
|
107 |
*
|
108 |
*/
|
109 |
public BandSetupPanel() {
|
110 |
super();
|
111 |
initialize(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* This method initializes this
|
116 |
*
|
117 |
* @return void
|
118 |
*/
|
119 |
void initialize() {
|
120 |
//this.setPreferredSize(new Dimension(wComp, hComp));
|
121 |
this.setLayout(null); |
122 |
this.setLocation(0, 0); |
123 |
this.add(getFileList(), null); |
124 |
this.add(getRGBBandAssignPane(), null); |
125 |
getFileList().getJComboBox().addKeyListener(this);
|
126 |
getFileList().getJComboBox().addActionListener(this);
|
127 |
this.addComponentListener(this); |
128 |
this.setComponentSize(wComp, hComp);
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* Obtiene el nombre del panel
|
133 |
* @return Cadena con el nombre del panel
|
134 |
*/
|
135 |
public String getName(){ |
136 |
return this.nom; |
137 |
} |
138 |
|
139 |
/**
|
140 |
* A?ade la lista de georasterfiles a la tabla
|
141 |
* @param files
|
142 |
*/
|
143 |
public void addFiles(GeoRasterFile[] files) { |
144 |
for (int i = 0; i < files.length; i++) { |
145 |
String fName = files[i].getName();
|
146 |
getFileList().addFName(fName); |
147 |
|
148 |
//((DefaultListModel)fileList.getJList().getModel()).addElement(fName);
|
149 |
String bandName = new File(fName).getName(); |
150 |
String bandType = ""; |
151 |
|
152 |
switch (files[i].getDataType()) {
|
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 |
if (files[i].getBandCount() > 1) { |
177 |
for (int b = 0; b < files[i].getBandCount(); b++) |
178 |
addBand((b + 1) + " [" + bandType + "] " + bandName); |
179 |
} else {
|
180 |
addBand("1 [" + bandType + "] " + bandName); |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Elimina un fichero de la lista
|
187 |
* @param file Nombre del fichero a eliminar
|
188 |
*/
|
189 |
public void removeFile(String file) { |
190 |
getFileList().removeFName(file); |
191 |
|
192 |
for (int i = 0; |
193 |
i < ((DefaultTableModel) rgbTable.getModel()).getRowCount();
|
194 |
i++) { |
195 |
//Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
|
196 |
//esta visibilidad a la banda inmediata superior y si esta acci?n produce
|
197 |
//una excepci?n (porque no hay) se pasa al inmediato inferior.
|
198 |
if (((String) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 3)).endsWith(file)) { |
199 |
try {
|
200 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 0)).booleanValue()) { |
201 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i - 1, 0); |
202 |
} |
203 |
} catch (ArrayIndexOutOfBoundsException exc) { |
204 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i + 1, 0); |
205 |
} |
206 |
|
207 |
try {
|
208 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 1)).booleanValue()) { |
209 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i - 1, 1); |
210 |
} |
211 |
} catch (ArrayIndexOutOfBoundsException exc) { |
212 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i + 1, 1); |
213 |
} |
214 |
|
215 |
try {
|
216 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 2)).booleanValue()) { |
217 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i - 1, 2); |
218 |
} |
219 |
} catch (ArrayIndexOutOfBoundsException exc) { |
220 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i + 1, 2); |
221 |
} |
222 |
|
223 |
((DefaultTableModel) rgbTable.getModel()).removeRow(i);
|
224 |
i--; //Ojo! que hemos eliminado una fila
|
225 |
} |
226 |
} |
227 |
} |
228 |
|
229 |
/**
|
230 |
* Cuando cambiamos el combo de seleccion de numero de bandas a visualizar
|
231 |
* debemos resetear la tabla de checkbox para que no haya activados m?s de
|
232 |
* los permitidos
|
233 |
* @param mode
|
234 |
*/
|
235 |
private void resetMode(int mode) { |
236 |
//Reseteamos los checkbox
|
237 |
for (int i = 0; i < (rgbTable.getColumnCount() - 1); i++) |
238 |
for (int j = 0; j < rgbTable.getRowCount(); j++) |
239 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(false), j, i); |
240 |
|
241 |
//Asignamos los valores
|
242 |
if (this.getNBands() >= 3) { |
243 |
switch (mode) {
|
244 |
case 3: |
245 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 2, 2); |
246 |
case 2: |
247 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 1, 1); |
248 |
case 1: |
249 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 0, 0); |
250 |
} |
251 |
} else if (this.getNBands() == 2) { |
252 |
switch (mode) {
|
253 |
case 3: |
254 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 1, 2); |
255 |
case 2: |
256 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 1, 1); |
257 |
case 1: |
258 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 0, 0); |
259 |
} |
260 |
} else if (this.getNBands() == 1) { |
261 |
switch (mode) {
|
262 |
case 3: |
263 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 0, 2); |
264 |
case 2: |
265 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 0, 1); |
266 |
case 1: |
267 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), 0, 0); |
268 |
} |
269 |
} |
270 |
|
271 |
col[0] = 0; |
272 |
col[1] = 1; |
273 |
} |
274 |
|
275 |
/**
|
276 |
* Asigna modo 1, 2, o 3 bandas. El modo 1 solo permite seleccionar en la
|
277 |
* tabla un checkbox, el 2 dos checkbox en distintar bandas y el 3 tres checkbox
|
278 |
* tambi?n en distintas bandas.
|
279 |
* @param mode
|
280 |
*/
|
281 |
private void setMode(int mode) { |
282 |
//Solo hay un checkbox activado
|
283 |
if (mode == 1) { |
284 |
for (int i = 0; i < rgbTable.getRowCount(); i++) |
285 |
for (int j = 0; j < (rgbTable.getColumnCount() - 1); j++) { |
286 |
if ((i != rgbTable.getSelectedRow()) ||
|
287 |
(j != rgbTable.getSelectedColumn())) { |
288 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(false), i, j); |
289 |
} |
290 |
} |
291 |
|
292 |
//Hay dos checkbox activados
|
293 |
} else if (mode == 2) { |
294 |
int n = 0; |
295 |
|
296 |
for (int i = 0; i < (rgbTable.getColumnCount() - 1); i++) |
297 |
for (int j = 0; j < rgbTable.getRowCount(); j++) |
298 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(j, i)).booleanValue()) { |
299 |
n++; |
300 |
} |
301 |
|
302 |
//Si se ha seleccionado 3 bandas hay eliminar una de ellas. Siempre ser? la m?s antigua que se clickeo
|
303 |
if (n > 2) { |
304 |
for (int i = 0; i < rgbTable.getRowCount(); i++) |
305 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(false), i, col[0]); |
306 |
} |
307 |
|
308 |
//Rotamos el punto pinchado m?s antiguo para que se eliminen alternativamente
|
309 |
if ((col[0] == rgbTable.getSelectedColumn()) || |
310 |
((col[0] != rgbTable.getSelectedColumn()) &&
|
311 |
(col[1] != rgbTable.getSelectedColumn()))) {
|
312 |
col[0] = col[1]; |
313 |
col[1] = rgbTable.getSelectedColumn();
|
314 |
} |
315 |
|
316 |
//El modo 3 es el comportamiento original
|
317 |
} else if (mode == 3) { |
318 |
return;
|
319 |
} |
320 |
} |
321 |
|
322 |
/**
|
323 |
* Obtiene el panel que contiene la lista de ficheros por banda.
|
324 |
* @return Panel FileList
|
325 |
*/
|
326 |
public FileList getFileList() {
|
327 |
if (fileList == null) { |
328 |
fileList = new FileList();
|
329 |
//fileList.setBounds(9, 9, wFileList, hFileList);
|
330 |
} |
331 |
|
332 |
return fileList;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* This method initializes jTable
|
337 |
*
|
338 |
* @return javax.swing.JTable
|
339 |
*/
|
340 |
private JScrollPane getRGBBandAssignPane() { |
341 |
if (rgbBandAssignPane == null) { |
342 |
rgbBandAssignPane = new JScrollPane(getRGBTable()); |
343 |
//rgbBandAssignPane.setBounds(10, 123, wBand, hBand);
|
344 |
|
345 |
TableColumn column = null; |
346 |
|
347 |
for (int i = 0; i < 3; i++) { |
348 |
column = rgbTable.getColumnModel().getColumn(i); |
349 |
column.setCellRenderer(new RadioColumnRenderer());
|
350 |
column.setCellEditor(new RadioColumnEditor());
|
351 |
column.setMaxWidth(22);
|
352 |
column.setMinWidth(22);
|
353 |
} |
354 |
|
355 |
// frame.setContentPane(scrollPane);
|
356 |
} |
357 |
|
358 |
return rgbBandAssignPane;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* Obtiene la Tabla
|
363 |
* @return Tabla de bandas de la imagen
|
364 |
*/
|
365 |
public JTable getRGBTable() { |
366 |
if (rgbTable == null) { |
367 |
tableModel = new RGBBandAsignTableModel();
|
368 |
tableModel.addTableModelListener(this);
|
369 |
rgbTable = new JTable(tableModel); |
370 |
rgbTable.setPreferredScrollableViewportSize(new Dimension(328, 72)); |
371 |
} |
372 |
|
373 |
return rgbTable;
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* Asigna al combo de n?mero de bandas a mostrar el valor correspondiente
|
378 |
* dependiendo del n?mero de bandas de la imagen.
|
379 |
*/
|
380 |
public void setList() { |
381 |
String[] l = null; |
382 |
|
383 |
if (this.getNBands() == 1) { |
384 |
l = new String[1]; |
385 |
l[0] = "1"; |
386 |
} |
387 |
|
388 |
if (this.getNBands() == 2) { |
389 |
l = new String[2]; |
390 |
l[0] = "1"; |
391 |
l[1] = "2"; |
392 |
} |
393 |
|
394 |
if (this.getNBands() == 3) { |
395 |
l = new String[3]; |
396 |
l[0] = "1"; |
397 |
l[1] = "2"; |
398 |
l[2] = "3"; |
399 |
} |
400 |
|
401 |
if (this.getNBands() > 0) { |
402 |
getFileList().setList(l); |
403 |
} |
404 |
} |
405 |
|
406 |
/**
|
407 |
* A?ade una banda a la tabla bandas de la imagen asignandole un
|
408 |
* nombre y valor a los checkbox
|
409 |
* @param bandName Nombre de la banda
|
410 |
*/
|
411 |
private void addBand(String bandName) { |
412 |
Vector v = new Vector(); |
413 |
v.add(new Boolean(false)); |
414 |
v.add(new Boolean(false)); |
415 |
v.add(new Boolean(false)); |
416 |
v.add(bandName); |
417 |
((DefaultTableModel) rgbTable.getModel()).addRow(v);
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* Obtiene el n?mero de bandas de la lista
|
422 |
* @return
|
423 |
*/
|
424 |
public int getNBands() { |
425 |
return ((DefaultTableModel) rgbTable.getModel()).getRowCount(); |
426 |
} |
427 |
|
428 |
/**
|
429 |
* Obtiene el nombre de la banda de la posici?n i de la tabla
|
430 |
* @param i
|
431 |
* @return
|
432 |
*/
|
433 |
public String getBandName(int i) { |
434 |
String s = (String) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 3); |
435 |
return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
436 |
} |
437 |
|
438 |
/**
|
439 |
* Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le corresponde
|
440 |
* @param nBand Banda de la imagen que corresponde
|
441 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
442 |
*/
|
443 |
public void assignBand(int nBand, int flag) { |
444 |
Boolean t = new Boolean(true); |
445 |
|
446 |
if ((flag & RED_BAND) == RED_BAND)
|
447 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(t, nBand, 0); |
448 |
|
449 |
if ((flag & GREEN_BAND) == GREEN_BAND)
|
450 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(t, nBand, 1); |
451 |
|
452 |
if ((flag & BLUE_BAND) == BLUE_BAND)
|
453 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(t, nBand, 2); |
454 |
} |
455 |
|
456 |
/**
|
457 |
* Obtiene la correspondencia entre el R, G o B y la banda asignada
|
458 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica
|
459 |
* @return Banda de la imagen asignada al flag pasado por par?metro
|
460 |
*/
|
461 |
public int getAssignedBand(int flag) { |
462 |
if ((flag & RED_BAND) == RED_BAND) {
|
463 |
for (int nBand = 0; nBand < rgbTable.getRowCount(); nBand++) |
464 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(nBand, |
465 |
0)).booleanValue()) {
|
466 |
return nBand;
|
467 |
} |
468 |
} |
469 |
|
470 |
if ((flag & GREEN_BAND) == GREEN_BAND) {
|
471 |
for (int nBand = 0; nBand < rgbTable.getRowCount(); nBand++) |
472 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(nBand, |
473 |
1)).booleanValue()) {
|
474 |
return nBand;
|
475 |
} |
476 |
} |
477 |
|
478 |
if ((flag & BLUE_BAND) == BLUE_BAND) {
|
479 |
for (int nBand = 0; nBand < rgbTable.getRowCount(); nBand++) |
480 |
if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(nBand, |
481 |
2)).booleanValue()) {
|
482 |
return nBand;
|
483 |
} |
484 |
} |
485 |
|
486 |
return -1; |
487 |
} |
488 |
|
489 |
/* (non-Javadoc)
|
490 |
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
|
491 |
*/
|
492 |
public void tableChanged(TableModelEvent e) { |
493 |
rgbTable.revalidate(); |
494 |
rgbBandAssignPane.revalidate(); |
495 |
revalidate(); |
496 |
} |
497 |
|
498 |
/* (non-Javadoc)
|
499 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
500 |
*/
|
501 |
public void keyPressed(KeyEvent arg0) { |
502 |
// TODO Auto-generated method stub
|
503 |
} |
504 |
|
505 |
/* (non-Javadoc)
|
506 |
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
|
507 |
*/
|
508 |
public void keyReleased(KeyEvent arg0) { |
509 |
// TODO Auto-generated method stub
|
510 |
} |
511 |
|
512 |
/* (non-Javadoc)
|
513 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
514 |
*/
|
515 |
public void keyTyped(KeyEvent arg0) { |
516 |
// TODO Auto-generated method stub
|
517 |
} |
518 |
|
519 |
/**
|
520 |
*Evento que activado cuando se modifica el n?mero de bandas que se desean visualizar.
|
521 |
*Se obtiene este n?mero y se llama a la funci?n que controla el cambio de n?mero
|
522 |
*de bandas visualizadas.
|
523 |
*/
|
524 |
public void actionPerformed(ActionEvent arg0) { |
525 |
String vBands = (String) getFileList().getJComboBox().getSelectedItem(); |
526 |
|
527 |
if (vBands != null) { |
528 |
if (vBands.compareTo("3") == 0) { |
529 |
mode = 3;
|
530 |
} |
531 |
|
532 |
if (vBands.compareTo("2") == 0) { |
533 |
mode = 2;
|
534 |
} |
535 |
|
536 |
if (vBands.compareTo("1") == 0) { |
537 |
mode = 1;
|
538 |
} |
539 |
|
540 |
resetMode(mode); |
541 |
} |
542 |
} |
543 |
|
544 |
class RadioColumnEditor extends AbstractCellEditor |
545 |
implements TableCellEditor { |
546 |
final private static long serialVersionUID = -3370601314380922368L; |
547 |
public JRadioButton theRadioButton; |
548 |
|
549 |
public RadioColumnEditor() {
|
550 |
super();
|
551 |
theRadioButton = new JRadioButton(); |
552 |
theRadioButton.addActionListener(new ActionListener() { |
553 |
public void actionPerformed(ActionEvent event) { |
554 |
fireEditingStopped() ; |
555 |
setMode(mode); |
556 |
} |
557 |
}); |
558 |
} |
559 |
|
560 |
public Component getTableCellEditorComponent(JTable table, Object obj, |
561 |
boolean isSelected,
|
562 |
int row, int col) { |
563 |
theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER);
|
564 |
|
565 |
Boolean lValueAsBoolean = (Boolean) obj; |
566 |
theRadioButton.setSelected(lValueAsBoolean.booleanValue()); |
567 |
|
568 |
return theRadioButton;
|
569 |
} |
570 |
|
571 |
public Object getCellEditorValue() { |
572 |
return new Boolean(theRadioButton.isSelected()); |
573 |
} |
574 |
} |
575 |
|
576 |
class RadioColumnRenderer extends JRadioButton implements TableCellRenderer { |
577 |
final private static long serialVersionUID = -3370601314380922368L; |
578 |
|
579 |
public Component getTableCellRendererComponent(JTable table, |
580 |
Object value,
|
581 |
boolean isSelected,
|
582 |
boolean hasFocus,
|
583 |
int row, int column) { |
584 |
if (value == null) { |
585 |
this.setSelected(false); |
586 |
} |
587 |
|
588 |
Boolean ValueAsBoolean = (Boolean) value; |
589 |
this.setSelected(ValueAsBoolean.booleanValue());
|
590 |
this.setHorizontalAlignment(SwingConstants.CENTER); |
591 |
|
592 |
return this; |
593 |
} |
594 |
} |
595 |
|
596 |
class RGBBandAsignTableModel extends DefaultTableModel { |
597 |
final private static long serialVersionUID = -3370601314380922368L; |
598 |
|
599 |
public RGBBandAsignTableModel() {
|
600 |
super(new Object[0][4], columnNames); |
601 |
} |
602 |
|
603 |
public Class getColumnClass(int c) { |
604 |
if (c < 3) { |
605 |
return Boolean.class; |
606 |
} |
607 |
|
608 |
return String.class; |
609 |
} |
610 |
|
611 |
public void setValueAt(Object value, int row, int col) { |
612 |
if ((col < 3) && ((Boolean) value).booleanValue()) { |
613 |
for (int i = 0; i < getRowCount(); i++) { |
614 |
if (i != row) {
|
615 |
setValueAt(new Boolean(false), i, col); |
616 |
} |
617 |
} |
618 |
} |
619 |
|
620 |
super.setValueAt(value, row, col);
|
621 |
} |
622 |
|
623 |
public void addNew() { |
624 |
super.addRow(new Object[] { |
625 |
new Boolean(false), new Boolean(false), |
626 |
new Boolean(false), "" |
627 |
}); |
628 |
} |
629 |
|
630 |
|
631 |
} |
632 |
|
633 |
|
634 |
public void setComponentSize(int w, int h){ |
635 |
wComp = w; hComp = h; |
636 |
wFileList = wComp - 18; hFileList = (int)Math.round(hComp * 0.46); |
637 |
wBand = wFileList; hBand = hComp - hFileList - 20;
|
638 |
|
639 |
this.setPreferredSize(new Dimension(wComp, hComp)); |
640 |
this.setSize(wComp, hComp);
|
641 |
rgbBandAssignPane.setBounds(10, hFileList + 12, wBand, hBand); |
642 |
fileList.setBounds(9, 9, wFileList, hFileList); |
643 |
|
644 |
} |
645 |
|
646 |
|
647 |
|
648 |
public void componentHidden(ComponentEvent e) { |
649 |
// TODO Auto-generated method stub
|
650 |
|
651 |
} |
652 |
|
653 |
public void componentMoved(ComponentEvent e) { |
654 |
// TODO Auto-generated method stub
|
655 |
|
656 |
} |
657 |
/**
|
658 |
* Redimensiona el panel cuando se redimensiona el contenedor de ?ste
|
659 |
*/
|
660 |
public void componentResized(ComponentEvent e) { |
661 |
/*if(e.getSource() == this){
|
662 |
int nWidth = this.getSize().width;
|
663 |
int nHeight = this.getSize().height;
|
664 |
int difWidth = nWidth - 445;
|
665 |
int difHeight = nHeight - 239;
|
666 |
this.fileList.setResize(difWidth, difHeight);
|
667 |
this.rgbBandAssignPane.setBounds(10, 123 + difHeight/2, 427 + difWidth, 104 + difHeight/2);
|
668 |
|
669 |
}*/
|
670 |
|
671 |
} |
672 |
|
673 |
public void componentShown(ComponentEvent e) { |
674 |
// TODO Auto-generated method stub
|
675 |
|
676 |
} |
677 |
} // @jve:decl-index=0:visual-constraint="10,10"
|