root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / ui / ColorTablePanel.java @ 13777
History | View | Annotate | Download (22.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.colortable.ui; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.FlowLayout; |
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ActionListener; |
26 |
import java.io.File; |
27 |
import java.io.FileNotFoundException; |
28 |
import java.io.IOException; |
29 |
import java.util.ArrayList; |
30 |
import java.util.EventObject; |
31 |
|
32 |
import javax.swing.ImageIcon; |
33 |
import javax.swing.JButton; |
34 |
import javax.swing.JCheckBox; |
35 |
import javax.swing.JComponent; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JScrollPane; |
38 |
import javax.swing.JSplitPane; |
39 |
import javax.swing.JTabbedPane; |
40 |
import javax.swing.event.ChangeEvent; |
41 |
import javax.swing.event.ChangeListener; |
42 |
|
43 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
44 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
45 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
46 |
import org.gvsig.gui.beans.imagenavigator.ImageNavigator; |
47 |
import org.gvsig.gui.beans.listview.ListViewComponent; |
48 |
import org.gvsig.gui.beans.listview.ListViewItem; |
49 |
import org.gvsig.gui.beans.listview.ListViewListener; |
50 |
import org.gvsig.raster.dataset.io.rmf.RmfBlocksManager; |
51 |
import org.gvsig.raster.datastruct.ColorTable; |
52 |
import org.gvsig.raster.datastruct.Extent; |
53 |
import org.gvsig.raster.datastruct.serializer.ColorTableLibraryPersistence; |
54 |
import org.gvsig.raster.datastruct.serializer.ColorTableRmfSerializer; |
55 |
import org.gvsig.raster.grid.GridPalette; |
56 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
57 |
import org.gvsig.raster.grid.filter.bands.ColorTableFilter; |
58 |
import org.gvsig.raster.grid.render.Rendering; |
59 |
import org.gvsig.raster.util.RasterToolsUtil; |
60 |
import org.gvsig.raster.util.RasterUtilities; |
61 |
import org.gvsig.rastertools.colortable.ColorTableListener; |
62 |
import org.gvsig.rastertools.colortable.panels.TabInterpolated; |
63 |
import org.gvsig.rastertools.colortable.panels.TabTable; |
64 |
|
65 |
import com.iver.andami.PluginServices; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
67 |
/**
|
68 |
* ColorTablePanel es el panel donde se gestionara todo el comportamiento de las
|
69 |
* tablas de color.
|
70 |
*
|
71 |
* @version 26/06/2007
|
72 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
73 |
*/
|
74 |
public class ColorTablePanel extends DefaultButtonsPanel implements ActionListener, ChangeListener, ListViewListener { |
75 |
private static final long serialVersionUID = 6028780107787443656L; |
76 |
|
77 |
private ImageNavigator imageNavigator = null; |
78 |
private ColorTableListener colorTableListener = null; |
79 |
private boolean active = false; |
80 |
private FLayer fLayer = null; |
81 |
private ArrayList filterStatus = null; |
82 |
|
83 |
private ColorTable lastColorTable = null; |
84 |
private ColorTable lastColorTableCloned = null; |
85 |
|
86 |
//[start]Variables UI
|
87 |
private TabTable tabTable = null; |
88 |
private TabInterpolated tabInterpolated = null; |
89 |
private ListViewComponent listViewComponent = null; |
90 |
private JTabbedPane tabbedPane = null; |
91 |
private JSplitPane jPanelRight = null; |
92 |
private JPanel jPanelPreview = null; |
93 |
private JPanel jPanelListView = null; |
94 |
private JPanel jPanelBottom = null; |
95 |
private JPanel panelButtons = null; |
96 |
private JCheckBox checkBoxInterpolated = null; |
97 |
private JCheckBox checkBoxEnabled = null; |
98 |
private JButton buttonAdd = null; |
99 |
private JButton buttonDel = null; |
100 |
//[end]
|
101 |
|
102 |
private String palettesPath = System.getProperty("user.home") + |
103 |
File.separator +
|
104 |
"gvSIG" + // PluginServices.getArguments()[0] + |
105 |
File.separator + "colortable"; |
106 |
|
107 |
/**
|
108 |
* Construir un nuevo ColorTablePanel
|
109 |
*/
|
110 |
public ColorTablePanel() {
|
111 |
super(ButtonsPanel.BUTTONS_NONE);
|
112 |
getButtonsPanel().addButton(PluginServices.getText(this, "guardar_predeterminado"), ButtonsPanel.BUTTON_LAST + 2); |
113 |
getButtonsPanel().addAccept(); |
114 |
getButtonsPanel().addApply(); |
115 |
getButtonsPanel().addCancel(); |
116 |
initialize(); |
117 |
} |
118 |
|
119 |
//[start] Code UI
|
120 |
private void initialize() { |
121 |
setLayout(new BorderLayout(8, 8)); |
122 |
|
123 |
JPanel panelLeft = new JPanel(); |
124 |
panelLeft.setPreferredSize(new Dimension(390,0)); |
125 |
panelLeft.setLayout(new BorderLayout(8, 8)); |
126 |
panelLeft.add(getTabbedPane(), BorderLayout.CENTER);
|
127 |
panelLeft.add(getPanelBottom(), BorderLayout.SOUTH);
|
128 |
|
129 |
JSplitPane jSplitPane1 = new JSplitPane(); |
130 |
jSplitPane1.setLeftComponent(panelLeft); |
131 |
jSplitPane1.setRightComponent(getPanelRight()); |
132 |
jSplitPane1.setResizeWeight(1.0);
|
133 |
jSplitPane1.setOneTouchExpandable(true);
|
134 |
jSplitPane1.setContinuousLayout(true);
|
135 |
jSplitPane1.setBorder(null);
|
136 |
|
137 |
add(jSplitPane1, BorderLayout.CENTER);
|
138 |
|
139 |
ArrayList fileList = ColorTableLibraryPersistence.getPaletteFileList(palettesPath);
|
140 |
|
141 |
for (int i = 0; i < fileList.size(); i++) { |
142 |
ArrayList paletteItems = new ArrayList(); |
143 |
String paletteName = ColorTableLibraryPersistence.loadPalette(palettesPath, (String) fileList.get(i), paletteItems); |
144 |
|
145 |
if (paletteItems.size() <= 0) |
146 |
continue;
|
147 |
|
148 |
ColorTable colorTable = new ColorTable();
|
149 |
colorTable.setName(paletteName); |
150 |
colorTable.createPaletteFromColorItems(paletteItems, true);
|
151 |
colorTable.setInterpolated(true);
|
152 |
|
153 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), paletteName); |
154 |
item.setTag(fileList.get(i)); |
155 |
getListViewComponent().addItem(item); |
156 |
} |
157 |
getListViewComponent().setSelectedIndex(0);
|
158 |
refreshItems(true);
|
159 |
} |
160 |
|
161 |
private JTabbedPane getTabbedPane() { |
162 |
if (tabbedPane == null) { |
163 |
tabbedPane = new JTabbedPane(); |
164 |
|
165 |
tabbedPane.addTab(PluginServices.getText(this, "tabla"), getTabTable()); |
166 |
tabbedPane.addTab(PluginServices.getText(this, "rampa"), getTabInterpolated()); |
167 |
tabbedPane.addChangeListener(this);
|
168 |
} |
169 |
return tabbedPane;
|
170 |
} |
171 |
|
172 |
private TabTable getTabTable() {
|
173 |
if (tabTable == null) { |
174 |
tabTable = new TabTable(this); |
175 |
tabTable.getTableContainer().getTable().getJTable().getModel().addTableModelListener(tabTable); |
176 |
} |
177 |
return tabTable;
|
178 |
} |
179 |
|
180 |
|
181 |
private TabInterpolated getTabInterpolated() {
|
182 |
if (tabInterpolated == null) { |
183 |
tabInterpolated = new TabInterpolated(this); |
184 |
} |
185 |
return tabInterpolated;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Devuelve el componente para la vista previa
|
190 |
* @return
|
191 |
*/
|
192 |
private ImageNavigator getImageNavigator() {
|
193 |
if (imageNavigator == null) { |
194 |
imageNavigator = new ImageNavigator(getColorTableListener());
|
195 |
imageNavigator.setFocusable(true);
|
196 |
imageNavigator.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
|
197 |
} |
198 |
return imageNavigator;
|
199 |
} |
200 |
|
201 |
private JPanel getPanelPreview() { |
202 |
if (jPanelPreview == null) { |
203 |
jPanelPreview = new JPanel(); |
204 |
JPanel jsubpanel2 = new JPanel(); |
205 |
jPanelPreview.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "vista_previa"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
206 |
jPanelPreview.setLayout(new BorderLayout()); |
207 |
jsubpanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); |
208 |
jsubpanel2.setLayout(new BorderLayout()); |
209 |
|
210 |
jsubpanel2.add(getImageNavigator(), BorderLayout.CENTER);
|
211 |
jPanelPreview.add(jsubpanel2, BorderLayout.CENTER);
|
212 |
|
213 |
jPanelPreview.setPreferredSize(new Dimension(237, 237)); |
214 |
jPanelPreview.setMinimumSize(new Dimension(237, 237)); |
215 |
jPanelPreview.setMaximumSize(new Dimension(237, 237)); |
216 |
} |
217 |
return jPanelPreview;
|
218 |
} |
219 |
|
220 |
private JPanel getPanelListView() { |
221 |
if (jPanelListView == null) { |
222 |
jPanelListView = new JPanel(); |
223 |
JPanel jsubpanel4 = new JPanel(); |
224 |
jPanelListView.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "libreria"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
225 |
jPanelListView.setLayout(new BorderLayout()); |
226 |
jsubpanel4.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); |
227 |
jsubpanel4.setLayout(new BorderLayout()); |
228 |
|
229 |
JScrollPane jScrollPane = new JScrollPane(); |
230 |
jScrollPane.setViewportView(getListViewComponent()); |
231 |
jScrollPane.setAutoscrolls(true);
|
232 |
|
233 |
jsubpanel4.add(jScrollPane, BorderLayout.CENTER);
|
234 |
|
235 |
jPanelListView.add(jsubpanel4, BorderLayout.CENTER);
|
236 |
jPanelListView.add(getPanelButtons(), BorderLayout.SOUTH);
|
237 |
|
238 |
jPanelListView.setPreferredSize(new Dimension(0, 192)); |
239 |
} |
240 |
return jPanelListView;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* Devuelve el panel donde estar? el widget de preview
|
245 |
* @return
|
246 |
*/
|
247 |
private JSplitPane getPanelRight() { |
248 |
if (jPanelRight == null) { |
249 |
jPanelRight = new JSplitPane(); |
250 |
jPanelRight.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); |
251 |
jPanelRight.setOneTouchExpandable(true);
|
252 |
jPanelRight.setContinuousLayout(true);
|
253 |
jPanelRight.setBorder(null);
|
254 |
jPanelRight.setResizeWeight(0.0);
|
255 |
jPanelRight.setPreferredSize(new Dimension(220, 0)); |
256 |
jPanelRight.setMinimumSize(new Dimension(220, 0)); |
257 |
|
258 |
jPanelRight.setTopComponent(getPanelPreview()); |
259 |
jPanelRight.setBottomComponent(getPanelListView()); |
260 |
} |
261 |
return jPanelRight;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* Obtener el componente que hara la carga pesada de los listeners
|
266 |
* @return
|
267 |
*/
|
268 |
private ColorTableListener getColorTableListener() {
|
269 |
if (colorTableListener == null) { |
270 |
colorTableListener = new ColorTableListener(this); |
271 |
} |
272 |
return colorTableListener;
|
273 |
} |
274 |
|
275 |
public ListViewComponent getListViewComponent() {
|
276 |
if (listViewComponent == null) { |
277 |
listViewComponent = new ListViewComponent();
|
278 |
listViewComponent.addListSelectionListener(this);
|
279 |
listViewComponent.setEditable(true);
|
280 |
} |
281 |
return listViewComponent;
|
282 |
} |
283 |
|
284 |
private JPanel getPanelBottom() { |
285 |
if (jPanelBottom == null) { |
286 |
jPanelBottom = new JPanel(); |
287 |
jPanelBottom.add(getCheckBoxEnabled(), null);
|
288 |
jPanelBottom.add(getCheckBoxInterpolated(), null);
|
289 |
jPanelBottom.setMinimumSize(new Dimension(0, 0)); |
290 |
} |
291 |
return jPanelBottom;
|
292 |
} |
293 |
|
294 |
/**
|
295 |
* Obtiene el jCBInterpolated
|
296 |
* @return
|
297 |
*/
|
298 |
public JCheckBox getCheckBoxInterpolated() { |
299 |
if (checkBoxInterpolated == null) { |
300 |
checkBoxInterpolated = new JCheckBox(PluginServices.getText(this, "interpolado")); |
301 |
checkBoxInterpolated.setSelected(true);
|
302 |
checkBoxInterpolated.addActionListener(this);
|
303 |
} |
304 |
return checkBoxInterpolated;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Obtiene el jCBInterpolated
|
309 |
* @return
|
310 |
*/
|
311 |
public JCheckBox getCheckBoxEnabled() { |
312 |
if (checkBoxEnabled == null) { |
313 |
checkBoxEnabled = new JCheckBox(PluginServices.getText(this, "activar_tablas_color")); |
314 |
checkBoxEnabled.setSelected(true);
|
315 |
checkBoxEnabled.addActionListener(this);
|
316 |
} |
317 |
return checkBoxEnabled;
|
318 |
} |
319 |
|
320 |
/**
|
321 |
* Devuelve el panel de botones de la libreria de a?adir y borrar
|
322 |
* @return
|
323 |
*/
|
324 |
private JPanel getPanelButtons() { |
325 |
if (panelButtons == null) { |
326 |
panelButtons = new JPanel(); |
327 |
panelButtons.setPreferredSize(new Dimension(0, 21)); |
328 |
|
329 |
FlowLayout flowLayout5 = new FlowLayout(); |
330 |
flowLayout5.setHgap(5);
|
331 |
flowLayout5.setVgap(0);
|
332 |
flowLayout5.setAlignment(java.awt.FlowLayout.CENTER); |
333 |
panelButtons.setLayout(flowLayout5); |
334 |
|
335 |
panelButtons.add(getButtonAdd(), null);
|
336 |
panelButtons.add(getButtonDel(), null);
|
337 |
} |
338 |
return panelButtons;
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* Devuelve el jButtonAdd
|
343 |
* @return
|
344 |
*/
|
345 |
public JButton getButtonAdd() { |
346 |
if (buttonAdd == null) { |
347 |
ImageIcon icon = null; |
348 |
try {
|
349 |
icon = new ImageIcon(getClass().getClassLoader().getResource("images/addlayer.png")); |
350 |
} catch (NullPointerException n) { |
351 |
// No ha encontrado el icono, no lo muestra.
|
352 |
} |
353 |
|
354 |
buttonAdd = new JButton(icon); |
355 |
buttonAdd.setPreferredSize(new Dimension(22, 19)); |
356 |
buttonAdd.addActionListener(this);
|
357 |
buttonAdd.setToolTipText(PluginServices.getText(this, "nueva_libreria")); |
358 |
} |
359 |
return buttonAdd;
|
360 |
} |
361 |
|
362 |
/**
|
363 |
* Devuelve el jButtonDel
|
364 |
* @return
|
365 |
*/
|
366 |
public JButton getButtonDel() { |
367 |
if (buttonDel == null) { |
368 |
ImageIcon icon = null; |
369 |
try {
|
370 |
icon = new ImageIcon(getClass().getClassLoader().getResource("images/delall.png")); |
371 |
} catch (NullPointerException n) { |
372 |
// No ha encontrado el icono, no lo muestra.
|
373 |
} |
374 |
buttonDel = new JButton(icon); |
375 |
buttonDel.setPreferredSize(new Dimension(22, 19)); |
376 |
buttonDel.addActionListener(this);
|
377 |
buttonDel.setToolTipText(PluginServices.getText(this, "borrar_libreria")); |
378 |
} |
379 |
return buttonDel;
|
380 |
} |
381 |
//[end]
|
382 |
|
383 |
/**
|
384 |
* Especificar el layer para el recorte
|
385 |
* @param layer
|
386 |
*/
|
387 |
public void setLayer(FLayer fLayer) { |
388 |
this.fLayer = fLayer;
|
389 |
|
390 |
// Especificar las dimensiones de la capa en la vista previa
|
391 |
Extent extent2 = ((FLyrRasterSE) fLayer).getBufferFactory().getExtent(); |
392 |
getImageNavigator().setViewDimensions(extent2.getMin().getX(), extent2.getMax().getY(), extent2.getMax().getX(), extent2.getMin().getY()); |
393 |
getImageNavigator().setZoom(1.0/((FLyrRasterSE) fLayer).getBufferFactory().getXCellSize());
|
394 |
getImageNavigator().setAutoAdjusted(); |
395 |
|
396 |
RasterFilterList rasterFilterList = ((FLyrRasterSE) getLayer()).getRender().getFilterList(); |
397 |
|
398 |
filterStatus = rasterFilterList.getStatusCloned(); |
399 |
|
400 |
ColorTableFilter colorTableFilter = (ColorTableFilter) rasterFilterList.getByName(ColorTableFilter.names[0]);
|
401 |
if (colorTableFilter != null) { |
402 |
GridPalette gridPalette = new GridPalette((ColorTable) colorTableFilter.getColorTable().clone());
|
403 |
if (gridPalette.isCompressible()) {
|
404 |
if (RasterToolsUtil.messageBoxYesOrNot("comprimir_paleta", this)) |
405 |
gridPalette.compressPalette(); |
406 |
} |
407 |
|
408 |
ColorTable colorTable = new ColorTable();
|
409 |
colorTable.setName(PluginServices.getText(this, "tabla_actual")); |
410 |
colorTable.createPaletteFromColorItems(gridPalette.getColorItems(), false);
|
411 |
colorTable.setInterpolated(gridPalette.isInterpolated()); |
412 |
getCheckBoxInterpolated().setSelected(gridPalette.isInterpolated()); |
413 |
|
414 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), PluginServices.getText(this, "tabla_actual")); |
415 |
getListViewComponent().addItem(0, item);
|
416 |
getListViewComponent().setSelectedIndex(0);
|
417 |
refreshItems(true);
|
418 |
setEnabledPanel(true);
|
419 |
} else {
|
420 |
setEnabledPanel(false);
|
421 |
getCheckBoxEnabled().setSelected(false);
|
422 |
} |
423 |
} |
424 |
|
425 |
/**
|
426 |
* Especificar el layer para el recorte
|
427 |
* @param layer
|
428 |
*/
|
429 |
public FLayer getLayer() {
|
430 |
return fLayer;
|
431 |
} |
432 |
|
433 |
/**
|
434 |
* Recarga la tabla de elementos
|
435 |
* @param isNewSelection
|
436 |
*/
|
437 |
public void refreshItems(boolean isNewSelection) { |
438 |
if (getListViewComponent().getLastSelectedItem() == null) |
439 |
return;
|
440 |
|
441 |
active = false;
|
442 |
|
443 |
if (isNewSelection)
|
444 |
((ColorTableIconPainter) getListViewComponent().getLastSelectedItem().getIcon()).getColorTable().compressPalette(); |
445 |
|
446 |
ArrayList colorItems = ((ColorTableIconPainter) getListViewComponent().getLastSelectedItem().getIcon()).getColorItems();
|
447 |
|
448 |
/*
|
449 |
switch (getTabbedPane().getSelectedIndex()) {
|
450 |
case 0:
|
451 |
getTabTable().reloadItems(colorItems);
|
452 |
break;
|
453 |
case 1:
|
454 |
getTabInterpolated().reloadItems(colorItems);
|
455 |
break;
|
456 |
}
|
457 |
*/
|
458 |
|
459 |
getTabTable().reloadItems(colorItems); |
460 |
getTabInterpolated().reloadItems(colorItems); |
461 |
|
462 |
lastColorTable = ((ColorTableIconPainter) getListViewComponent().getLastSelectedItem().getIcon()).getColorTable(); |
463 |
if (isNewSelection)
|
464 |
lastColorTableCloned = (ColorTable) ((ColorTableIconPainter) getListViewComponent().getLastSelectedItem().getIcon()).getColorTable().clone(); |
465 |
|
466 |
active = true;
|
467 |
getImageNavigator().updateBuffer(); |
468 |
} |
469 |
|
470 |
/**
|
471 |
* Comprueba si el usuario ha cambiado los valores de la tabla de colores,
|
472 |
* si es as?, le pregunta al usuario si quiere guardar los datos, y seg?n la
|
473 |
* selecci?n, restaura los datos antiguos o los machaca.
|
474 |
*/
|
475 |
public void testLibraryChanged() { |
476 |
if (!lastColorTable.equals(lastColorTableCloned)) {
|
477 |
if (RasterToolsUtil.messageBoxYesOrNot("desea_guardar_cambios", this)) { |
478 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, lastColorTable); |
479 |
} else {
|
480 |
} |
481 |
} |
482 |
} |
483 |
|
484 |
ArrayList statusList = new ArrayList(); |
485 |
public class StatusComponent { |
486 |
private JComponent object; |
487 |
private boolean enabled; |
488 |
|
489 |
public boolean isEnabled() { |
490 |
return enabled;
|
491 |
} |
492 |
|
493 |
public void setEnabled(boolean enabled) { |
494 |
this.enabled = enabled;
|
495 |
} |
496 |
|
497 |
public JComponent getObject() { |
498 |
return object;
|
499 |
} |
500 |
|
501 |
public void setObject(JComponent object) { |
502 |
this.object = object;
|
503 |
} |
504 |
} |
505 |
|
506 |
private void saveComponentsStatus(JComponent component) { |
507 |
// Guardar estado
|
508 |
StatusComponent auxStatus = new StatusComponent();
|
509 |
auxStatus.setEnabled(component.isEnabled()); |
510 |
auxStatus.setObject(component); |
511 |
statusList.add(auxStatus); |
512 |
|
513 |
for (int i = 0; i < component.getComponentCount(); i++) |
514 |
if (component.getComponent(i) instanceof JComponent) |
515 |
saveComponentsStatus((JComponent) component.getComponent(i));
|
516 |
} |
517 |
|
518 |
public void setEnabledRecursive(JComponent component, boolean enabled, int level) { |
519 |
if (enabled == true) { |
520 |
boolean auxEnabled = false; |
521 |
boolean finded = false; |
522 |
// Buscar estado de dicho componente
|
523 |
for (int i = 0; i < statusList.size(); i++) { |
524 |
StatusComponent auxStatus = (StatusComponent) statusList.get(i); |
525 |
if (auxStatus.getObject() == component) {
|
526 |
auxEnabled = auxStatus.isEnabled(); |
527 |
statusList.remove(i); |
528 |
i--; |
529 |
finded = true;
|
530 |
break;
|
531 |
} |
532 |
} |
533 |
|
534 |
// Asignar su estado
|
535 |
if (finded)
|
536 |
component.setEnabled(auxEnabled); |
537 |
} else {
|
538 |
// Si es la primera llamada, guardamos el estado de todos los componentes
|
539 |
if (level == 0) |
540 |
saveComponentsStatus(component); |
541 |
|
542 |
// Desactivar componente
|
543 |
component.setEnabled(false);
|
544 |
} |
545 |
|
546 |
for (int i = 0; i < component.getComponentCount(); i++) |
547 |
if (component.getComponent(i) instanceof JComponent) |
548 |
setEnabledRecursive((JComponent) component.getComponent(i), enabled, level + 1); |
549 |
} |
550 |
|
551 |
public void setEnabledPanel(boolean enabled) { |
552 |
getCheckBoxInterpolated().setEnabled(enabled); |
553 |
getTabbedPane().setEnabled(enabled); |
554 |
switch (getTabbedPane().getSelectedIndex()) {
|
555 |
case 0: |
556 |
//getTabTable().getTableContainer().setEnabled(enabled);
|
557 |
setEnabledRecursive(getTabTable(), enabled, 0);
|
558 |
break;
|
559 |
case 1: |
560 |
setEnabledRecursive(getTabInterpolated(), enabled, 0);
|
561 |
break;
|
562 |
} |
563 |
setEnabledRecursive(getPanelPreview(), enabled, 0);
|
564 |
setEnabledRecursive(getPanelListView(), enabled, 0);
|
565 |
} |
566 |
|
567 |
public void actionPerformed(ActionEvent e) { |
568 |
if (e.getSource() == getCheckBoxInterpolated()) {
|
569 |
for (int i = 0; i < getListViewComponent().getItems().size(); i++) { |
570 |
((ColorTableIconPainter) ((ListViewItem) getListViewComponent().getItems().get(i)).getIcon()).setInterpolated(getCheckBoxInterpolated().isSelected()); |
571 |
} |
572 |
lastColorTableCloned.setInterpolated(getCheckBoxInterpolated().isSelected()); |
573 |
getListViewComponent().repaint(); |
574 |
getImageNavigator().updateBuffer(); |
575 |
if (getTabbedPane().getSelectedIndex() == 1) |
576 |
getTabInterpolated().setInterpolated(getCheckBoxInterpolated().isSelected()); |
577 |
return;
|
578 |
} |
579 |
if (e.getSource() == getCheckBoxEnabled()) {
|
580 |
setEnabledPanel(getCheckBoxEnabled().isSelected()); |
581 |
} |
582 |
if (e.getSource() == getButtonAdd()) {
|
583 |
ColorTable colorTable = new ColorTable();
|
584 |
colorTable.setName(PluginServices.getText(this, "nueva_libreria")); |
585 |
colorTable.createPaletteFromColorItems(new ArrayList(), true); |
586 |
colorTable.setInterpolated(true);
|
587 |
|
588 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), PluginServices.getText(this, "nueva_libreria")); |
589 |
getListViewComponent().addItem(item); |
590 |
getListViewComponent().setSelectedIndex(getListViewComponent().getItems().size() - 1);
|
591 |
refreshItems(true);
|
592 |
((ColorTableIconPainter) item.getIcon()).getColorTable().setName(item.getName()); |
593 |
|
594 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, lastColorTable); |
595 |
} |
596 |
if (e.getSource() == getButtonDel()) {
|
597 |
if (getListViewComponent().getSelectedIndices().length > 0) { |
598 |
if (RasterToolsUtil.messageBoxYesOrNot("desea_borrar_librerias", this)) { |
599 |
File oldFile = new File(palettesPath + File.separator + lastColorTable.getName() + ".xml"); |
600 |
oldFile.delete(); |
601 |
int pos = getListViewComponent().getSelectedIndices()[0]; |
602 |
getListViewComponent().removeSelecteds(); |
603 |
getListViewComponent().setSelectedIndex(pos - 1);
|
604 |
refreshItems(true);
|
605 |
} |
606 |
} |
607 |
return;
|
608 |
} |
609 |
} |
610 |
|
611 |
public void tabChanged() { |
612 |
if (!active)
|
613 |
return;
|
614 |
|
615 |
active = false;
|
616 |
ArrayList colorItems = ((ColorTableIconPainter) getListViewComponent().getLastSelectedItem().getIcon()).getColorItems();
|
617 |
getTabTable().reloadItems(colorItems); |
618 |
active = true;
|
619 |
|
620 |
getListViewComponent().repaint(); |
621 |
getImageNavigator().updateBuffer(); |
622 |
} |
623 |
|
624 |
|
625 |
public GridPalette getGridPalette() {
|
626 |
if (getListViewComponent().getLastSelectedItem() == null) |
627 |
return null; |
628 |
return new GridPalette(((ColorTableIconPainter) getListViewComponent().getLastSelectedItem().getIcon()).getColorTable()); |
629 |
} |
630 |
|
631 |
/**
|
632 |
* Cuando se aceptan los cambios en el panel ejecutaremos el aceptar del
|
633 |
* listener
|
634 |
*/
|
635 |
public void accept() { |
636 |
colorTableListener.accept(); |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Volvemos todo a la normalidad cuando se cancela
|
641 |
*/
|
642 |
public void cancel() { |
643 |
getLayer().getMapContext().invalidate(); |
644 |
} |
645 |
|
646 |
/**
|
647 |
* Volvemos todo a la normalidad cuando se cancela
|
648 |
*/
|
649 |
public void restoreFilters() { |
650 |
Rendering rendering = ((FLyrRasterSE) getLayer()).getRender(); |
651 |
rendering.getFilterList().setStatus(getFilterStatus()); |
652 |
} |
653 |
|
654 |
/**
|
655 |
* Devuelve el arrayList de filtros inicial
|
656 |
* @return
|
657 |
*/
|
658 |
public ArrayList getFilterStatus() { |
659 |
return filterStatus;
|
660 |
} |
661 |
|
662 |
public void stateChanged(ChangeEvent e) { |
663 |
refreshItems(true);
|
664 |
} |
665 |
|
666 |
/**
|
667 |
* @return the active
|
668 |
*/
|
669 |
public boolean isActive() { |
670 |
return active;
|
671 |
} |
672 |
|
673 |
|
674 |
public void actionItemNameChanged(EventObject e, String oldName, String newName) { |
675 |
File oldFile = new File(palettesPath + File.separator + oldName + ".xml"); |
676 |
oldFile.delete(); |
677 |
|
678 |
lastColorTable.setName(newName); |
679 |
|
680 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, lastColorTable); |
681 |
} |
682 |
|
683 |
/**
|
684 |
* Accion que se ejecuta cuando cambia la seleccion de un item del
|
685 |
* ListViewComponent
|
686 |
*/
|
687 |
public void actionValueChanged(EventObject e) { |
688 |
testLibraryChanged(); |
689 |
refreshItems(true);
|
690 |
} |
691 |
|
692 |
/**
|
693 |
* Salva la georreferenciaci?n a fichero rmf.
|
694 |
* @param fName
|
695 |
* @throws IOException
|
696 |
*/
|
697 |
public void saveToRmf() { |
698 |
RmfBlocksManager manager = ((FLyrRasterSE) getLayer()).getDataSource().getDataset(0)[0].getRmfBlocksManager(); |
699 |
ColorTableRmfSerializer ser = new ColorTableRmfSerializer(lastColorTable);
|
700 |
if(!manager.checkRmf())
|
701 |
return;
|
702 |
manager.addClient(ser); |
703 |
try {
|
704 |
RasterUtilities.copyFile(manager.getPath(), manager.getPath() + "~");
|
705 |
manager.write(); |
706 |
} catch (FileNotFoundException e) { |
707 |
e.printStackTrace(); |
708 |
} catch (IOException e) { |
709 |
e.printStackTrace(); |
710 |
} |
711 |
manager.removeClient(ser.getClass()); |
712 |
} |
713 |
} |