svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / ui / ColorTablePanel.java @ 13396
History | View | Annotate | Download (20.7 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.RasterUtilities; |
60 |
import org.gvsig.rastertools.RasterToolsUtil; |
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 |
} |
358 |
return buttonAdd;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* Devuelve el jButtonDel
|
363 |
* @return
|
364 |
*/
|
365 |
public JButton getButtonDel() { |
366 |
if (buttonDel == null) { |
367 |
ImageIcon icon = null; |
368 |
try {
|
369 |
icon = new ImageIcon(getClass().getClassLoader().getResource("images/delall.png")); |
370 |
} catch (NullPointerException n) { |
371 |
// No ha encontrado el icono, no lo muestra.
|
372 |
} |
373 |
buttonDel = new JButton(icon); |
374 |
buttonDel.setPreferredSize(new Dimension(22, 19)); |
375 |
buttonDel.addActionListener(this);
|
376 |
} |
377 |
return buttonDel;
|
378 |
} |
379 |
//[end]
|
380 |
|
381 |
/**
|
382 |
* Especificar el layer para el recorte
|
383 |
* @param layer
|
384 |
*/
|
385 |
public void setLayer(FLayer fLayer) { |
386 |
this.fLayer = fLayer;
|
387 |
|
388 |
// Especificar las dimensiones de la capa en la vista previa
|
389 |
Extent extent2 = ((FLyrRasterSE) fLayer).getBufferFactory().getExtent(); |
390 |
getImageNavigator().setViewDimensions(extent2.getMin().getX(), extent2.getMax().getY(), extent2.getMax().getX(), extent2.getMin().getY()); |
391 |
getImageNavigator().setZoom(1.0/((FLyrRasterSE) fLayer).getBufferFactory().getXCellSize());
|
392 |
getImageNavigator().setAutoAdjusted(); |
393 |
|
394 |
RasterFilterList rasterFilterList = ((FLyrRasterSE) getLayer()).getRender().getFilterList(); |
395 |
|
396 |
filterStatus = rasterFilterList.getStatusCloned(); |
397 |
|
398 |
ColorTableFilter colorTableFilter = (ColorTableFilter) rasterFilterList.getByName(ColorTableFilter.names[0]);
|
399 |
if (colorTableFilter != null) { |
400 |
GridPalette gridPalette = new GridPalette((ColorTable) colorTableFilter.getColorTable().clone());
|
401 |
if (gridPalette.isCompressible()) {
|
402 |
if (RasterToolsUtil.messageBoxYesOrNot("comprimir_paleta", this)) |
403 |
gridPalette.compressPalette(); |
404 |
} |
405 |
|
406 |
ColorTable colorTable = new ColorTable();
|
407 |
colorTable.setName(PluginServices.getText(this, "tabla_actual")); |
408 |
colorTable.createPaletteFromColorItems(gridPalette.getColorItems(), false);
|
409 |
colorTable.setInterpolated(gridPalette.isInterpolated()); |
410 |
getCheckBoxInterpolated().setSelected(gridPalette.isInterpolated()); |
411 |
|
412 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), PluginServices.getText(this, "tabla_actual")); |
413 |
getListViewComponent().addItem(0, item);
|
414 |
getListViewComponent().setSelectedIndex(0);
|
415 |
refreshItems(true);
|
416 |
setEnabledPanel(true);
|
417 |
} else {
|
418 |
setEnabledPanel(false);
|
419 |
getCheckBoxEnabled().setSelected(false);
|
420 |
} |
421 |
} |
422 |
|
423 |
/**
|
424 |
* Especificar el layer para el recorte
|
425 |
* @param layer
|
426 |
*/
|
427 |
public FLayer getLayer() {
|
428 |
return fLayer;
|
429 |
} |
430 |
|
431 |
/**
|
432 |
* Recarga la tabla de elementos
|
433 |
* @param isNewSelection
|
434 |
*/
|
435 |
public void refreshItems(boolean isNewSelection) { |
436 |
if (getListViewComponent().getSelectedValue() == null) |
437 |
return;
|
438 |
|
439 |
active = false;
|
440 |
|
441 |
if (isNewSelection)
|
442 |
((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable().compressPalette(); |
443 |
|
444 |
ArrayList colorItems = ((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorItems();
|
445 |
|
446 |
switch (getTabbedPane().getSelectedIndex()) {
|
447 |
case 0: |
448 |
getTabTable().reloadItems(colorItems); |
449 |
break;
|
450 |
case 1: |
451 |
getTabInterpolated().reloadItems(colorItems); |
452 |
break;
|
453 |
} |
454 |
|
455 |
lastColorTable = ((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable(); |
456 |
if (isNewSelection)
|
457 |
lastColorTableCloned = (ColorTable) ((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable().clone(); |
458 |
|
459 |
active = true;
|
460 |
getImageNavigator().updateBuffer(); |
461 |
} |
462 |
|
463 |
/**
|
464 |
* Comprueba si el usuario ha cambiado los valores de la tabla de colores,
|
465 |
* si es as?, le pregunta al usuario si quiere guardar los datos, y seg?n la
|
466 |
* selecci?n, restaura los datos antiguos o los machaca.
|
467 |
*/
|
468 |
public void testLibraryChanged() { |
469 |
if (!lastColorTable.equals(lastColorTableCloned)) {
|
470 |
if (RasterToolsUtil.messageBoxYesOrNot("desea_guardar_cambios", this)) { |
471 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, lastColorTable); |
472 |
} else {
|
473 |
|
474 |
} |
475 |
} |
476 |
} |
477 |
|
478 |
public void setEnabledRecursive(JComponent component, boolean enabled) { |
479 |
component.setEnabled(enabled); |
480 |
for (int i = 0; i < component.getComponentCount(); i++) |
481 |
if (component.getComponent(i) instanceof JComponent) |
482 |
setEnabledRecursive((JComponent) component.getComponent(i), enabled);
|
483 |
} |
484 |
|
485 |
public void setEnabledPanel(boolean enabled) { |
486 |
getCheckBoxInterpolated().setEnabled(enabled); |
487 |
getTabbedPane().setEnabled(enabled); |
488 |
switch (getTabbedPane().getSelectedIndex()) {
|
489 |
case 0: |
490 |
setEnabledRecursive(getTabTable(), enabled); |
491 |
break;
|
492 |
case 1: |
493 |
setEnabledRecursive(getTabInterpolated(), enabled); |
494 |
break;
|
495 |
} |
496 |
setEnabledRecursive(getPanelPreview(), enabled); |
497 |
setEnabledRecursive(getPanelListView(), enabled); |
498 |
} |
499 |
|
500 |
public void actionPerformed(ActionEvent e) { |
501 |
if (e.getSource() == getCheckBoxInterpolated()) {
|
502 |
for (int i = 0; i < getListViewComponent().getItems().size(); i++) { |
503 |
((ColorTableIconPainter) ((ListViewItem) getListViewComponent().getItems().get(i)).getIcon()).setInterpolated(getCheckBoxInterpolated().isSelected()); |
504 |
} |
505 |
lastColorTableCloned.setInterpolated(getCheckBoxInterpolated().isSelected()); |
506 |
getListViewComponent().repaint(); |
507 |
getImageNavigator().updateBuffer(); |
508 |
if (getTabbedPane().getSelectedIndex() == 1) |
509 |
getTabInterpolated().setInterpolated(getCheckBoxInterpolated().isSelected()); |
510 |
return;
|
511 |
} |
512 |
if (e.getSource() == getCheckBoxEnabled()) {
|
513 |
setEnabledPanel(getCheckBoxEnabled().isSelected()); |
514 |
} |
515 |
if (e.getSource() == getButtonAdd()) {
|
516 |
ColorTable colorTable = new ColorTable();
|
517 |
colorTable.setName(PluginServices.getText(this, "nueva_libreria")); |
518 |
colorTable.createPaletteFromColorItems(new ArrayList(), true); |
519 |
colorTable.setInterpolated(true);
|
520 |
|
521 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), PluginServices.getText(this, "nueva_libreria")); |
522 |
getListViewComponent().addItem(item); |
523 |
getListViewComponent().setSelectedIndex(getListViewComponent().getItems().size() - 1);
|
524 |
refreshItems(true);
|
525 |
} |
526 |
if (e.getSource() == getButtonDel()) {
|
527 |
if (getListViewComponent().getSelectedIndices().length > 0) { |
528 |
if (RasterToolsUtil.messageBoxYesOrNot("desea_borrar_librerias", this)) { |
529 |
File oldFile = new File(palettesPath + File.separator + lastColorTable.getName() + ".xml"); |
530 |
oldFile.delete(); |
531 |
int pos = getListViewComponent().getSelectedIndices()[0]; |
532 |
getListViewComponent().removeSelecteds(); |
533 |
getListViewComponent().setSelectedIndex(pos - 1);
|
534 |
refreshItems(true);
|
535 |
} |
536 |
} |
537 |
return;
|
538 |
} |
539 |
} |
540 |
|
541 |
public void tabChanged() { |
542 |
if (!active)
|
543 |
return;
|
544 |
|
545 |
getListViewComponent().repaint(); |
546 |
|
547 |
getImageNavigator().updateBuffer(); |
548 |
} |
549 |
|
550 |
|
551 |
public GridPalette getGridPalette() {
|
552 |
if (getListViewComponent().getSelectedValue() == null) |
553 |
return null; |
554 |
return new GridPalette(((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable()); |
555 |
} |
556 |
|
557 |
/**
|
558 |
* Cuando se aceptan los cambios en el panel ejecutaremos el aceptar del
|
559 |
* listener
|
560 |
*/
|
561 |
public void accept() { |
562 |
colorTableListener.accept(); |
563 |
} |
564 |
|
565 |
/**
|
566 |
* Volvemos todo a la normalidad cuando se cancela
|
567 |
*/
|
568 |
public void cancel() { |
569 |
getLayer().getMapContext().invalidate(); |
570 |
} |
571 |
|
572 |
/**
|
573 |
* Volvemos todo a la normalidad cuando se cancela
|
574 |
*/
|
575 |
public void restoreFilters() { |
576 |
Rendering rendering = ((FLyrRasterSE) getLayer()).getRender(); |
577 |
rendering.getFilterList().setStatus(getFilterStatus()); |
578 |
} |
579 |
|
580 |
/**
|
581 |
* Devuelve el arrayList de filtros inicial
|
582 |
* @return
|
583 |
*/
|
584 |
public ArrayList getFilterStatus() { |
585 |
return filterStatus;
|
586 |
} |
587 |
|
588 |
public void stateChanged(ChangeEvent e) { |
589 |
refreshItems(true);
|
590 |
} |
591 |
|
592 |
/**
|
593 |
* @return the active
|
594 |
*/
|
595 |
public boolean isActive() { |
596 |
return active;
|
597 |
} |
598 |
|
599 |
|
600 |
public void actionItemNameChanged(EventObject e, String oldName, String newName) { |
601 |
File oldFile = new File(palettesPath + File.separator + oldName + ".xml"); |
602 |
oldFile.delete(); |
603 |
|
604 |
lastColorTable.setName(newName); |
605 |
|
606 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, lastColorTable); |
607 |
} |
608 |
|
609 |
/**
|
610 |
* Accion que se ejecuta cuando cambia la seleccion de un item del
|
611 |
* ListViewComponent
|
612 |
*/
|
613 |
public void actionValueChanged(EventObject e) { |
614 |
testLibraryChanged(); |
615 |
refreshItems(true);
|
616 |
} |
617 |
|
618 |
/**
|
619 |
* Salva la georreferenciaci?n a fichero rmf.
|
620 |
* @param fName
|
621 |
* @throws IOException
|
622 |
*/
|
623 |
public void saveToRmf() { |
624 |
RmfBlocksManager manager = ((FLyrRasterSE) getLayer()).getDataSource().getDataset(0)[0].getRmfBlocksManager(); |
625 |
ColorTableRmfSerializer ser = new ColorTableRmfSerializer(lastColorTable);
|
626 |
if(!manager.checkRmf())
|
627 |
return;
|
628 |
manager.addClient(ser); |
629 |
try {
|
630 |
RasterUtilities.copyFile(manager.getPath(), manager.getPath() + "~");
|
631 |
manager.write(); |
632 |
} catch (FileNotFoundException e) { |
633 |
e.printStackTrace(); |
634 |
} catch (IOException e) { |
635 |
e.printStackTrace(); |
636 |
} |
637 |
manager.removeClient(ser.getClass()); |
638 |
} |
639 |
} |