root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / BandSetupPanel.java @ 10940
History | View | Annotate | Download (23.2 KB)
1 | 10740 | nacho | /* 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 | |||
20 | package org.gvsig.rastertools.properties.panels; |
||
21 | |||
22 | import java.awt.Component; |
||
23 | import java.awt.Dimension; |
||
24 | import java.awt.event.ActionEvent; |
||
25 | import java.awt.event.ActionListener; |
||
26 | import java.awt.event.ComponentEvent; |
||
27 | import java.awt.event.ComponentListener; |
||
28 | import java.awt.image.DataBuffer; |
||
29 | import java.io.File; |
||
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 | 10940 | nacho | import org.gvsig.raster.dataset.RasterDataset; |
47 | import org.gvsig.raster.dataset.RasterMultiDataset; |
||
48 | 10740 | nacho | import org.gvsig.raster.shared.IRasterDataset; |
49 | import org.gvsig.raster.shared.IRasterProperties; |
||
50 | import org.gvsig.rastertools.properties.dialog.IRegistrablePanel; |
||
51 | |||
52 | import com.iver.andami.PluginServices; |
||
53 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
54 | |||
55 | |||
56 | /**
|
||
57 | * Selecciona las bandas visibles en un raster. Contiene una tabla con una fila por cada
|
||
58 | * banda de la imagen. Por medio de checkbox se selecciona para cada RGB que banda de la
|
||
59 | * imagen ser? visualizada.
|
||
60 | * @author Luis W. Sevilla (sevilla_lui@gva.es)
|
||
61 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
62 | */
|
||
63 | public class BandSetupPanel extends JPanel implements TableModelListener, |
||
64 | ComponentListener,
|
||
65 | IRegistrablePanel{ |
||
66 | final private static long serialVersionUID = -3370601314380922368L; |
||
67 | |||
68 | /**
|
||
69 | * Variables para la asignaci?n de tama?o de los componentes del panel.
|
||
70 | */
|
||
71 | private int wComp = 445, hComp = 239; |
||
72 | private int wFileList = wComp, hFileList = (int)Math.round(hComp * 0.46); |
||
73 | private int wBand = wFileList, hBand = hComp - hFileList - 20; |
||
74 | |||
75 | /**
|
||
76 | * Asigna la banda del rojo
|
||
77 | */
|
||
78 | public static final int RED_BAND = RasterDataset.RED_BAND; |
||
79 | |||
80 | /**
|
||
81 | * Asigna la banda del verde
|
||
82 | */
|
||
83 | public static final int GREEN_BAND = RasterDataset.GREEN_BAND; |
||
84 | |||
85 | /**
|
||
86 | * Asigna banda del azul
|
||
87 | */
|
||
88 | public static final int BLUE_BAND = RasterDataset.BLUE_BAND; |
||
89 | private final static String[] columnNames = { "R", "G", "B", "Band" }; |
||
90 | |||
91 | /**
|
||
92 | * Nombre del panel
|
||
93 | */
|
||
94 | private String id = "bands_panel"; |
||
95 | private BandSetupFileList fileList = null; |
||
96 | private JTable rgbTable = null; |
||
97 | private JScrollPane rgbBandAssignPane = null; |
||
98 | RGBBandAsignTableModel tableModel = null;
|
||
99 | private byte mode = 3; |
||
100 | private int[] col = { 0, 1 }; //Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo |
||
101 | private BandSetupListener panelListener = null; |
||
102 | private IRasterProperties prop = null; |
||
103 | private IRasterDataset dataset = null; |
||
104 | |||
105 | /**
|
||
106 | * This method initializes
|
||
107 | *
|
||
108 | */
|
||
109 | public BandSetupPanel() {
|
||
110 | super();
|
||
111 | id = PluginServices.getText(this, id);
|
||
112 | initialize(); |
||
113 | } |
||
114 | |||
115 | /**
|
||
116 | * This method initializes this
|
||
117 | *
|
||
118 | * @return void
|
||
119 | */
|
||
120 | void initialize() {
|
||
121 | //this.setPreferredSize(new Dimension(wComp, hComp));
|
||
122 | this.setLayout(null); |
||
123 | this.setLocation(0, 0); |
||
124 | this.add(getFileList(), null); |
||
125 | this.add(getRGBBandAssignPane(), null); |
||
126 | this.addComponentListener(this); |
||
127 | this.setComponentSize(wComp, hComp);
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * A?ade la lista de georasterfiles a la tabla
|
||
132 | * @param files
|
||
133 | */
|
||
134 | public void addFiles(RasterMultiDataset mDataset) { |
||
135 | getFileList().clear(); |
||
136 | clear(); |
||
137 | for (int i = 0; i < mDataset.getDatasetCount(); i++) { |
||
138 | String fName = mDataset.getDataset(i).getFName();
|
||
139 | getFileList().addFName(fName); |
||
140 | |||
141 | String bandName = new File(fName).getName(); |
||
142 | String bandType = ""; |
||
143 | |||
144 | switch (mDataset.getDataset(i).getDataType()) {
|
||
145 | case DataBuffer.TYPE_BYTE: |
||
146 | bandType = "8U";
|
||
147 | break;
|
||
148 | case DataBuffer.TYPE_INT: |
||
149 | bandType = "32";
|
||
150 | break;
|
||
151 | case DataBuffer.TYPE_DOUBLE: |
||
152 | bandType = "64";
|
||
153 | break;
|
||
154 | case DataBuffer.TYPE_FLOAT: |
||
155 | bandType = "32";
|
||
156 | break;
|
||
157 | case DataBuffer.TYPE_SHORT: |
||
158 | bandType = "16";
|
||
159 | break;
|
||
160 | case DataBuffer.TYPE_USHORT: |
||
161 | bandType = "16U";
|
||
162 | break;
|
||
163 | case DataBuffer.TYPE_UNDEFINED: |
||
164 | bandType = "??";
|
||
165 | break;
|
||
166 | } |
||
167 | |||
168 | if (mDataset.getDataset(i).getBandCount() > 1) { |
||
169 | for (int b = 0; b < mDataset.getDataset(i).getBandCount(); b++) |
||
170 | addBand((b + 1) + " [" + bandType + "] " + bandName); |
||
171 | } else {
|
||
172 | addBand("1 [" + bandType + "] " + bandName); |
||
173 | } |
||
174 | } |
||
175 | readDrawedBands(); |
||
176 | } |
||
177 | |||
178 | /**
|
||
179 | * Elimina un fichero de la lista
|
||
180 | * @param file Nombre del fichero a eliminar
|
||
181 | */
|
||
182 | public void removeFile(String file) { |
||
183 | getFileList().removeFName(file); |
||
184 | |||
185 | for (int i = 0; i < ((DefaultTableModel) rgbTable.getModel()).getRowCount(); i++) { |
||
186 | //Si el fichero borrado estaba seleccionado como banda visible. Pasaremos
|
||
187 | //esta visibilidad a la banda inmediata superior y si esta acci?n produce
|
||
188 | //una excepci?n (porque no hay) se pasa al inmediato inferior.
|
||
189 | if (((String) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 3)).endsWith(file)) { |
||
190 | try {
|
||
191 | if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 0)).booleanValue()) { |
||
192 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i - 1, 0); |
||
193 | } |
||
194 | } catch (ArrayIndexOutOfBoundsException exc) { |
||
195 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i + 1, 0); |
||
196 | } |
||
197 | |||
198 | try {
|
||
199 | if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 1)).booleanValue()) { |
||
200 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i - 1, 1); |
||
201 | } |
||
202 | } catch (ArrayIndexOutOfBoundsException exc) { |
||
203 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i + 1, 1); |
||
204 | } |
||
205 | |||
206 | try {
|
||
207 | if (((Boolean) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 2)).booleanValue()) { |
||
208 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i - 1, 2); |
||
209 | } |
||
210 | } catch (ArrayIndexOutOfBoundsException exc) { |
||
211 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true), i + 1, 2); |
||
212 | } |
||
213 | |||
214 | ((DefaultTableModel) rgbTable.getModel()).removeRow(i);
|
||
215 | i--; //Ojo! que hemos eliminado una fila
|
||
216 | } |
||
217 | } |
||
218 | panelListener.setNewBandsPositionInRendering(); |
||
219 | } |
||
220 | |||
221 | public void assignMode(byte mode){ |
||
222 | this.mode = mode;
|
||
223 | } |
||
224 | |||
225 | public byte getMode(){ |
||
226 | return mode;
|
||
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 | public 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 BandSetupFileList getFileList() {
|
||
327 | if (fileList == null) { |
||
328 | fileList = new BandSetupFileList();
|
||
329 | } |
||
330 | |||
331 | return fileList;
|
||
332 | } |
||
333 | |||
334 | /**
|
||
335 | * This method initializes jTable
|
||
336 | *
|
||
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 = rgbTable.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 | |||
369 | return rgbTable;
|
||
370 | } |
||
371 | |||
372 | /**
|
||
373 | * Asigna al combo de n?mero de bandas a mostrar el valor correspondiente
|
||
374 | * dependiendo del n?mero de bandas de la imagen.
|
||
375 | */
|
||
376 | public void setList() { |
||
377 | String[] l = null; |
||
378 | |||
379 | if (this.getNBands() == 1) { |
||
380 | l = new String[1]; |
||
381 | l[0] = "1"; |
||
382 | } |
||
383 | |||
384 | if (this.getNBands() == 2) { |
||
385 | l = new String[2]; |
||
386 | l[0] = "1"; |
||
387 | l[1] = "2"; |
||
388 | } |
||
389 | |||
390 | if (this.getNBands() == 3) { |
||
391 | l = new String[3]; |
||
392 | l[0] = "1"; |
||
393 | l[1] = "2"; |
||
394 | l[2] = "3"; |
||
395 | } |
||
396 | |||
397 | if (this.getNBands() > 0) { |
||
398 | getFileList().setList(l); |
||
399 | } |
||
400 | } |
||
401 | |||
402 | /**
|
||
403 | * A?ade una banda a la tabla bandas de la imagen asignandole un
|
||
404 | * nombre y valor a los checkbox
|
||
405 | * @param bandName Nombre de la banda
|
||
406 | */
|
||
407 | private void addBand(String bandName) { |
||
408 | Vector v = new Vector(); |
||
409 | v.add(new Boolean(false)); |
||
410 | v.add(new Boolean(false)); |
||
411 | v.add(new Boolean(false)); |
||
412 | v.add(bandName); |
||
413 | ((DefaultTableModel) rgbTable.getModel()).addRow(v);
|
||
414 | } |
||
415 | |||
416 | /**
|
||
417 | * Elimina todas las entradas de la tabla de bandas.
|
||
418 | */
|
||
419 | private void clear() { |
||
420 | int rows = ((DefaultTableModel) rgbTable.getModel()).getRowCount(); |
||
421 | if(rows > 0){ |
||
422 | for(int i = 0 ; i < rows; i ++) |
||
423 | ((DefaultTableModel) rgbTable.getModel()).removeRow(0); |
||
424 | } |
||
425 | } |
||
426 | |||
427 | /**
|
||
428 | * Obtiene el n?mero de bandas de la lista
|
||
429 | * @return
|
||
430 | */
|
||
431 | public int getNBands() { |
||
432 | return ((DefaultTableModel) rgbTable.getModel()).getRowCount(); |
||
433 | } |
||
434 | |||
435 | /**
|
||
436 | * Obtiene el nombre de la banda de la posici?n i de la tabla
|
||
437 | * @param i
|
||
438 | * @return
|
||
439 | */
|
||
440 | public String getBandName(int i) { |
||
441 | String s = (String) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 3); |
||
442 | return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
||
443 | } |
||
444 | |||
445 | /**
|
||
446 | * Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le corresponde
|
||
447 | * @param nBand Banda de la imagen que corresponde
|
||
448 | * @param flag R, G o B se selecciona por medio de un flag que los identifica
|
||
449 | */
|
||
450 | public void assignBand(int nBand, int flag) { |
||
451 | Boolean t = new Boolean(true); |
||
452 | |||
453 | if ((flag & RED_BAND) == RED_BAND)
|
||
454 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(t, nBand, 0); |
||
455 | |||
456 | if ((flag & GREEN_BAND) == GREEN_BAND)
|
||
457 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(t, nBand, 1); |
||
458 | |||
459 | if ((flag & BLUE_BAND) == BLUE_BAND)
|
||
460 | ((DefaultTableModel) rgbTable.getModel()).setValueAt(t, nBand, 2); |
||
461 | } |
||
462 | |||
463 | /**
|
||
464 | * Obtiene la correspondencia entre el R, G o B y la banda asignada
|
||
465 | * @param flag R, G o B se selecciona por medio de un flag que los identifica
|
||
466 | * @return Banda de la imagen asignada al flag pasado por par?metro
|
||
467 | */
|
||
468 | public int getAssignedBand(int flag) { |
||
469 | DefaultTableModel model = ((DefaultTableModel) rgbTable.getModel()); |
||
470 | if ((flag & RED_BAND) == RED_BAND) {
|
||
471 | for (int nBand = 0; nBand < rgbTable.getRowCount(); nBand++) |
||
472 | if (((Boolean) model.getValueAt(nBand, 0)).booleanValue()) |
||
473 | return nBand;
|
||
474 | } |
||
475 | |||
476 | if ((flag & GREEN_BAND) == GREEN_BAND) {
|
||
477 | for (int nBand = 0; nBand < rgbTable.getRowCount(); nBand++) |
||
478 | if (((Boolean) model.getValueAt(nBand, 1)).booleanValue()) |
||
479 | return nBand;
|
||
480 | } |
||
481 | |||
482 | if ((flag & BLUE_BAND) == BLUE_BAND) {
|
||
483 | for (int nBand = 0; nBand < rgbTable.getRowCount(); nBand++) |
||
484 | if (((Boolean) model.getValueAt(nBand, 2)).booleanValue()) |
||
485 | return nBand;
|
||
486 | } |
||
487 | |||
488 | return -1; |
||
489 | } |
||
490 | |||
491 | /* (non-Javadoc)
|
||
492 | * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
|
||
493 | */
|
||
494 | public void tableChanged(TableModelEvent e) { |
||
495 | rgbTable.revalidate(); |
||
496 | rgbBandAssignPane.revalidate(); |
||
497 | revalidate(); |
||
498 | } |
||
499 | |||
500 | class RadioColumnEditor extends AbstractCellEditor |
||
501 | implements TableCellEditor { |
||
502 | final private static long serialVersionUID = -3370601314380922368L; |
||
503 | public JRadioButton theRadioButton; |
||
504 | |||
505 | public RadioColumnEditor() {
|
||
506 | super();
|
||
507 | theRadioButton = new JRadioButton(); |
||
508 | theRadioButton.addActionListener(new ActionListener() { |
||
509 | public void actionPerformed(ActionEvent event) { |
||
510 | fireEditingStopped() ; |
||
511 | setMode(mode); |
||
512 | } |
||
513 | }); |
||
514 | } |
||
515 | |||
516 | public Component getTableCellEditorComponent(JTable table, Object obj, |
||
517 | boolean isSelected,
|
||
518 | int row, int col) { |
||
519 | theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER);
|
||
520 | |||
521 | Boolean lValueAsBoolean = (Boolean) obj; |
||
522 | theRadioButton.setSelected(lValueAsBoolean.booleanValue()); |
||
523 | |||
524 | return theRadioButton;
|
||
525 | } |
||
526 | |||
527 | public Object getCellEditorValue() { |
||
528 | return new Boolean(theRadioButton.isSelected()); |
||
529 | } |
||
530 | } |
||
531 | |||
532 | class RadioColumnRenderer extends JRadioButton implements TableCellRenderer { |
||
533 | final private static long serialVersionUID = -3370601314380922368L; |
||
534 | |||
535 | public Component getTableCellRendererComponent(JTable table, |
||
536 | Object value,
|
||
537 | boolean isSelected,
|
||
538 | boolean hasFocus,
|
||
539 | int row, int column) { |
||
540 | if (value == null) { |
||
541 | this.setSelected(false); |
||
542 | } |
||
543 | |||
544 | Boolean ValueAsBoolean = (Boolean) value; |
||
545 | this.setSelected(ValueAsBoolean.booleanValue());
|
||
546 | this.setHorizontalAlignment(SwingConstants.CENTER); |
||
547 | |||
548 | return this; |
||
549 | } |
||
550 | } |
||
551 | |||
552 | class RGBBandAsignTableModel extends DefaultTableModel { |
||
553 | final private static long serialVersionUID = -3370601314380922368L; |
||
554 | |||
555 | public RGBBandAsignTableModel() {
|
||
556 | super(new Object[0][4], columnNames); |
||
557 | } |
||
558 | |||
559 | public Class getColumnClass(int c) { |
||
560 | if (c < 3) { |
||
561 | return Boolean.class; |
||
562 | } |
||
563 | |||
564 | return String.class; |
||
565 | } |
||
566 | |||
567 | public void setValueAt(Object value, int row, int col) { |
||
568 | if ((col < 3) && ((Boolean) value).booleanValue()) { |
||
569 | for (int i = 0; i < getRowCount(); i++) { |
||
570 | if (i != row) {
|
||
571 | setValueAt(new Boolean(false), i, col); |
||
572 | } |
||
573 | } |
||
574 | } |
||
575 | |||
576 | super.setValueAt(value, row, col);
|
||
577 | } |
||
578 | |||
579 | public void addNew() { |
||
580 | super.addRow(new Object[] { |
||
581 | new Boolean(false), new Boolean(false), |
||
582 | new Boolean(false), "" |
||
583 | }); |
||
584 | } |
||
585 | } |
||
586 | |||
587 | public void setComponentSize(int w, int h){ |
||
588 | wComp = w; hComp = h; |
||
589 | wFileList = wComp - 18; hFileList = (int)Math.round(hComp * 0.46); |
||
590 | wBand = wFileList; hBand = hComp - hFileList - 20;
|
||
591 | |||
592 | this.setPreferredSize(new Dimension(wComp, hComp)); |
||
593 | this.setSize(wComp, hComp);
|
||
594 | rgbBandAssignPane.setBounds(10, hFileList + 12, wBand, hBand); |
||
595 | fileList.setBounds(9, 9, wFileList, hFileList); |
||
596 | |||
597 | } |
||
598 | |||
599 | public void componentHidden(ComponentEvent e) {} |
||
600 | |||
601 | public void componentMoved(ComponentEvent e) {} |
||
602 | |||
603 | /**
|
||
604 | * Redimensiona el panel cuando se redimensiona el contenedor de ?ste
|
||
605 | */
|
||
606 | public void componentResized(ComponentEvent e) { |
||
607 | if(e.getSource() == this){ |
||
608 | int nWidth = this.getSize().width; |
||
609 | int nHeight = this.getSize().height; |
||
610 | int difWidth = nWidth - 445; |
||
611 | int difHeight = nHeight - 239; |
||
612 | this.fileList.setResize(difWidth, difHeight);
|
||
613 | this.rgbBandAssignPane.setBounds(10, 123 + difHeight/2, 427 + difWidth, 104 + difHeight/2); |
||
614 | |||
615 | } |
||
616 | |||
617 | } |
||
618 | |||
619 | public void componentShown(ComponentEvent e) {} |
||
620 | |||
621 | /*
|
||
622 | * (non-Javadoc)
|
||
623 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLyrDefault)
|
||
624 | */
|
||
625 | public void setLayer(FLayer lyr) { |
||
626 | clear(); |
||
627 | getFileList().clear(); |
||
628 | |||
629 | if(lyr instanceof IRasterProperties) |
||
630 | prop = (IRasterProperties)lyr; |
||
631 | |||
632 | if(lyr instanceof IRasterDataset){ |
||
633 | dataset = (IRasterDataset)lyr; |
||
634 | addFiles(dataset.getGeoRasterMultiDataset()); |
||
635 | } |
||
636 | |||
637 | panelListener = new BandSetupListener(this, dataset, prop, lyr); |
||
638 | } |
||
639 | |||
640 | /**
|
||
641 | * Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho.
|
||
642 | */
|
||
643 | public void readDrawedBands(){ |
||
644 | if(prop.getRender() != null){ |
||
645 | int[] renderBands = prop.getRender().getRenderBands(); |
||
646 | for(int i = 0; i < renderBands.length; i++){ |
||
647 | if(renderBands[i] >= 0){ |
||
648 | switch(i){
|
||
649 | case 0: this.assignBand(renderBands[i], RasterDataset.RED_BAND);break; |
||
650 | case 1: this.assignBand(renderBands[i], RasterDataset.GREEN_BAND);break; |
||
651 | case 2: this.assignBand(renderBands[i], RasterDataset.BLUE_BAND);break; |
||
652 | } |
||
653 | } |
||
654 | } |
||
655 | } |
||
656 | } |
||
657 | |||
658 | /*
|
||
659 | * (non-Javadoc)
|
||
660 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
|
||
661 | */
|
||
662 | public void accept() { |
||
663 | panelListener.accept(); |
||
664 | } |
||
665 | |||
666 | /*
|
||
667 | * (non-Javadoc)
|
||
668 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
|
||
669 | */
|
||
670 | public void apply() { |
||
671 | panelListener.apply(); |
||
672 | } |
||
673 | |||
674 | /*
|
||
675 | * (non-Javadoc)
|
||
676 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
|
||
677 | */
|
||
678 | public void cancel() { |
||
679 | panelListener.cancel(); |
||
680 | } |
||
681 | |||
682 | /*
|
||
683 | * (non-Javadoc)
|
||
684 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
|
||
685 | */
|
||
686 | public String getID() { |
||
687 | return id;
|
||
688 | } |
||
689 | |||
690 | /*
|
||
691 | * (non-Javadoc)
|
||
692 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
||
693 | */
|
||
694 | public void selectTab(String id) { |
||
695 | } |
||
696 | } // @jve:decl-index=0:visual-constraint="10,10" |