root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / ui / ColorTablePanel.java @ 13120
History | View | Annotate | Download (20.2 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.Color; |
23 |
import java.awt.Dimension; |
24 |
import java.awt.FlowLayout; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.io.File; |
28 |
import java.util.ArrayList; |
29 |
|
30 |
import javax.swing.ImageIcon; |
31 |
import javax.swing.JButton; |
32 |
import javax.swing.JCheckBox; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JScrollPane; |
36 |
import javax.swing.JSplitPane; |
37 |
import javax.swing.JTabbedPane; |
38 |
import javax.swing.JTable; |
39 |
import javax.swing.JTextField; |
40 |
import javax.swing.event.ListSelectionEvent; |
41 |
import javax.swing.event.ListSelectionListener; |
42 |
import javax.swing.event.TableModelEvent; |
43 |
import javax.swing.event.TableModelListener; |
44 |
|
45 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
46 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
47 |
import org.gvsig.gui.beans.colorbutton.ColorButton; |
48 |
import org.gvsig.gui.beans.colorslideredition.ItemColorSlider; |
49 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
50 |
import org.gvsig.gui.beans.imagenavigator.ImageNavigator; |
51 |
import org.gvsig.gui.beans.listview.ListViewComponent; |
52 |
import org.gvsig.gui.beans.listview.ListViewItem; |
53 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
54 |
import org.gvsig.gui.beans.table.models.TableColorModel; |
55 |
import org.gvsig.raster.datastruct.ColorItem; |
56 |
import org.gvsig.raster.datastruct.ColorTable; |
57 |
import org.gvsig.raster.datastruct.Extent; |
58 |
import org.gvsig.raster.datastruct.serializer.ColorTableLibraryPersistence; |
59 |
import org.gvsig.raster.grid.GridPalette; |
60 |
import org.gvsig.raster.grid.GridTransparency; |
61 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
62 |
import org.gvsig.raster.grid.filter.bands.ColorTableFilter; |
63 |
import org.gvsig.raster.grid.render.Rendering; |
64 |
import org.gvsig.rastertools.RasterToolsUtil; |
65 |
import org.gvsig.rastertools.colortable.ColorTableListener; |
66 |
import org.gvsig.rastertools.colortable.panels.TabInterpolated; |
67 |
import org.gvsig.rastertools.colortable.panels.TabTable; |
68 |
|
69 |
import com.iver.andami.PluginServices; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
71 |
/**
|
72 |
* ColorTablePanel es el panel donde se gestionara todo el comportamiento de las
|
73 |
* tablas de color.
|
74 |
*
|
75 |
* @version 26/06/2007
|
76 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
77 |
*/
|
78 |
public class ColorTablePanel extends DefaultButtonsPanel implements ListSelectionListener, ActionListener, TableModelListener { |
79 |
private static final long serialVersionUID = 6028780107787443656L; |
80 |
|
81 |
private ImageNavigator imageNavigator = null; |
82 |
private ColorTableListener colorTableListener = null; |
83 |
private boolean active = false; |
84 |
private FLayer fLayer = null; |
85 |
private ArrayList filterStatus = null; |
86 |
private GridTransparency initTransparency = null; |
87 |
|
88 |
private ColorTable lastColorTable = null; |
89 |
private ColorTable lastColorTableCloned = null; |
90 |
|
91 |
//[start]Variables UI
|
92 |
private TabTable tabTable = null; |
93 |
private TabInterpolated tabInterpolated = null; |
94 |
private ListViewComponent listViewComponent = null; |
95 |
private JTabbedPane tabbedPane = null; |
96 |
private JSplitPane panelPreview = null; |
97 |
private JPanel panelNoData = null; |
98 |
private JPanel panelButtons = null; |
99 |
private JCheckBox checkBoxInterpolated = null; |
100 |
private JButton buttonAdd = null; |
101 |
private JButton buttonDel = null; |
102 |
private JTextField textFieldNoData = null; |
103 |
//[end]
|
104 |
|
105 |
private String palettesPath = System.getProperty("user.home") + |
106 |
File.separator +
|
107 |
"gvSIG" + // PluginServices.getArguments()[0] + |
108 |
File.separator + "colortable"; |
109 |
|
110 |
/**
|
111 |
* Construir un nuevo ColorTablePanel
|
112 |
*/
|
113 |
public ColorTablePanel() {
|
114 |
super(ButtonsPanel.BUTTONS_NONE);
|
115 |
getButtonsPanel().addButton("Guardar como predeterminado", ButtonsPanel.BUTTON_LAST + 2); |
116 |
getButtonsPanel().addAccept(); |
117 |
getButtonsPanel().addApply(); |
118 |
getButtonsPanel().addCancel(); |
119 |
initialize(); |
120 |
} |
121 |
|
122 |
//[start] Code UI
|
123 |
private void initialize() { |
124 |
setLayout(new BorderLayout(8, 8)); |
125 |
|
126 |
JPanel panelLeft = new JPanel(); |
127 |
panelLeft.setPreferredSize(new Dimension(390,0)); |
128 |
panelLeft.setLayout(new BorderLayout(8, 8)); |
129 |
panelLeft.add(getTabbedPane(), BorderLayout.CENTER);
|
130 |
panelLeft.add(getPanelNoData(), BorderLayout.SOUTH);
|
131 |
|
132 |
JSplitPane jSplitPane1 = new JSplitPane(); |
133 |
jSplitPane1.setLeftComponent(panelLeft); |
134 |
jSplitPane1.setRightComponent(getPanelPreview()); |
135 |
jSplitPane1.setResizeWeight(1.0);
|
136 |
jSplitPane1.setOneTouchExpandable(true);
|
137 |
jSplitPane1.setContinuousLayout(true);
|
138 |
jSplitPane1.setBorder(null);
|
139 |
|
140 |
add(jSplitPane1, BorderLayout.CENTER);
|
141 |
|
142 |
ArrayList fileList = ColorTableLibraryPersistence.getPaletteFileList(palettesPath);
|
143 |
|
144 |
for (int i = 0; i < fileList.size(); i++) { |
145 |
ArrayList paletteItems = new ArrayList(); |
146 |
String paletteName = ColorTableLibraryPersistence.loadPalette(palettesPath, (String) fileList.get(i), paletteItems); |
147 |
|
148 |
if (paletteItems.size() <= 0) |
149 |
continue;
|
150 |
|
151 |
ColorTable colorTable = new ColorTable();
|
152 |
colorTable.setName(paletteName); |
153 |
colorTable.createPaletteFromColorItems(paletteItems, true);
|
154 |
colorTable.setInterpolated(true);
|
155 |
|
156 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), paletteName); |
157 |
item.setTag(fileList.get(i)); |
158 |
getListViewComponent().addItem(item); |
159 |
} |
160 |
getListViewComponent().setSelectedIndex(0);
|
161 |
reloadTable(true);
|
162 |
} |
163 |
|
164 |
private JTabbedPane getTabbedPane() { |
165 |
if (tabbedPane == null) { |
166 |
tabbedPane = new JTabbedPane(); |
167 |
|
168 |
tabbedPane.addTab("Tabla", getTabTable());
|
169 |
tabbedPane.addTab("Rampa", getTabInterpolated());
|
170 |
|
171 |
} |
172 |
return tabbedPane;
|
173 |
} |
174 |
|
175 |
private TabTable getTabTable() {
|
176 |
if (tabTable == null) { |
177 |
tabTable = new TabTable();
|
178 |
tabTable.getTableContainer().getTable().getJTable().getModel().addTableModelListener(this);
|
179 |
} |
180 |
return tabTable;
|
181 |
} |
182 |
|
183 |
private TabInterpolated getTabInterpolated() {
|
184 |
if (tabInterpolated == null) { |
185 |
tabInterpolated = new TabInterpolated(this); |
186 |
} |
187 |
return tabInterpolated;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* Devuelve el componente para la vista previa
|
192 |
* @return
|
193 |
*/
|
194 |
private ImageNavigator getImageNavigator() {
|
195 |
if (imageNavigator == null) { |
196 |
imageNavigator = new ImageNavigator(getColorTableListener());
|
197 |
imageNavigator.setFocusable(true);
|
198 |
imageNavigator.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
|
199 |
} |
200 |
return imageNavigator;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* Devuelve el panel donde estar? el widget de preview
|
205 |
* @return
|
206 |
*/
|
207 |
private JSplitPane getPanelPreview() { |
208 |
if (panelPreview == null) { |
209 |
panelPreview = new JSplitPane(); |
210 |
panelPreview.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); |
211 |
panelPreview.setOneTouchExpandable(true);
|
212 |
panelPreview.setContinuousLayout(true);
|
213 |
panelPreview.setBorder(null);
|
214 |
panelPreview.setResizeWeight(0.0);
|
215 |
panelPreview.setPreferredSize(new Dimension(220, 0)); |
216 |
panelPreview.setMinimumSize(new Dimension(220, 0)); |
217 |
|
218 |
|
219 |
JPanel jsubpanel = new JPanel(); |
220 |
JPanel jsubpanel2 = new JPanel(); |
221 |
jsubpanel.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)); |
222 |
jsubpanel.setLayout(new BorderLayout()); |
223 |
jsubpanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); |
224 |
jsubpanel2.setLayout(new BorderLayout()); |
225 |
|
226 |
jsubpanel2.add(getImageNavigator(), BorderLayout.CENTER);
|
227 |
jsubpanel.add(jsubpanel2, BorderLayout.CENTER);
|
228 |
|
229 |
jsubpanel.setPreferredSize(new Dimension(237, 237)); |
230 |
jsubpanel.setMinimumSize(new Dimension(237, 237)); |
231 |
jsubpanel.setMaximumSize(new Dimension(237, 237)); |
232 |
|
233 |
panelPreview.setTopComponent(jsubpanel); |
234 |
|
235 |
JPanel jsubpanel3 = new JPanel(); |
236 |
JPanel jsubpanel4 = new JPanel(); |
237 |
jsubpanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "libreria"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
238 |
jsubpanel3.setLayout(new BorderLayout()); |
239 |
jsubpanel4.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8)); |
240 |
jsubpanel4.setLayout(new BorderLayout()); |
241 |
|
242 |
JScrollPane jScrollPane = new JScrollPane(); |
243 |
jScrollPane.setViewportView(getListViewComponent()); |
244 |
jScrollPane.setAutoscrolls(true);
|
245 |
|
246 |
jsubpanel4.add(jScrollPane, BorderLayout.CENTER);
|
247 |
|
248 |
jsubpanel3.add(jsubpanel4, BorderLayout.CENTER);
|
249 |
jsubpanel3.add(getPanelButtons(), BorderLayout.SOUTH);
|
250 |
|
251 |
jsubpanel3.setPreferredSize(new Dimension(0, 192)); |
252 |
|
253 |
panelPreview.setBottomComponent(jsubpanel3); |
254 |
} |
255 |
return panelPreview;
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* Obtener el componente que hara la carga pesada de los listeners
|
260 |
* @return
|
261 |
*/
|
262 |
private ColorTableListener getColorTableListener() {
|
263 |
if (colorTableListener == null) { |
264 |
colorTableListener = new ColorTableListener(this); |
265 |
} |
266 |
return colorTableListener;
|
267 |
} |
268 |
|
269 |
public ListViewComponent getListViewComponent() {
|
270 |
if (listViewComponent == null) { |
271 |
listViewComponent = new ListViewComponent();
|
272 |
listViewComponent.addListSelectionListener(this);
|
273 |
listViewComponent.setEditable(true);
|
274 |
} |
275 |
return listViewComponent;
|
276 |
} |
277 |
|
278 |
private JTextField getJTFNoData() { |
279 |
if (textFieldNoData == null) { |
280 |
textFieldNoData = new JTextField(); |
281 |
textFieldNoData.setPreferredSize(new Dimension(50, (int) textFieldNoData.getPreferredSize().getHeight())); |
282 |
} |
283 |
return textFieldNoData;
|
284 |
} |
285 |
|
286 |
private JPanel getPanelNoData() { |
287 |
if (panelNoData == null) { |
288 |
panelNoData = new JPanel(); |
289 |
panelNoData.add(new JLabel("No data: "), null); |
290 |
ColorButton buttonColor = new ColorButton();
|
291 |
buttonColor.setColor(Color.black);
|
292 |
panelNoData.add(buttonColor, null);
|
293 |
panelNoData.add(new JLabel("Value:"), null); |
294 |
panelNoData.add(getJTFNoData(), null);
|
295 |
panelNoData.add(getCheckBoxInterpolated(), null);
|
296 |
panelNoData.setMinimumSize(new Dimension(0, 0)); |
297 |
} |
298 |
return panelNoData;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* Obtiene el jCBInterpolated
|
303 |
* @return
|
304 |
*/
|
305 |
public JCheckBox getCheckBoxInterpolated() { |
306 |
if (checkBoxInterpolated == null) { |
307 |
checkBoxInterpolated = new JCheckBox("Interpolado"); |
308 |
checkBoxInterpolated.setSelected(true);
|
309 |
checkBoxInterpolated.addActionListener(this);
|
310 |
} |
311 |
return checkBoxInterpolated;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* Devuelve el panel de botones de la libreria de a?adir y borrar
|
316 |
* @return
|
317 |
*/
|
318 |
private JPanel getPanelButtons() { |
319 |
if (panelButtons == null) { |
320 |
panelButtons = new JPanel(); |
321 |
panelButtons.setPreferredSize(new Dimension(0, 21)); |
322 |
|
323 |
FlowLayout flowLayout5 = new FlowLayout(); |
324 |
flowLayout5.setHgap(5);
|
325 |
flowLayout5.setVgap(0);
|
326 |
flowLayout5.setAlignment(java.awt.FlowLayout.CENTER); |
327 |
panelButtons.setLayout(flowLayout5); |
328 |
|
329 |
panelButtons.add(getButtonAdd(), null);
|
330 |
panelButtons.add(getButtonDel(), null);
|
331 |
} |
332 |
return panelButtons;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* Devuelve el jButtonAdd
|
337 |
* @return
|
338 |
*/
|
339 |
public JButton getButtonAdd() { |
340 |
if (buttonAdd == null) { |
341 |
buttonAdd = new JButton(new ImageIcon("./gvSIG/extensiones/com.iver.cit.gvsig/images/addlayer.png")); |
342 |
buttonAdd.setPreferredSize(new Dimension(22, 19)); |
343 |
buttonAdd.addActionListener(this);
|
344 |
} |
345 |
return buttonAdd;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* Devuelve el jButtonDel
|
350 |
* @return
|
351 |
*/
|
352 |
public JButton getButtonDel() { |
353 |
if (buttonDel == null) { |
354 |
buttonDel = new JButton(new ImageIcon("./gvSIG/extensiones/com.iver.cit.gvsig/images/delall.png")); |
355 |
buttonDel.setPreferredSize(new Dimension(22, 19)); |
356 |
buttonDel.addActionListener(this);
|
357 |
} |
358 |
return buttonDel;
|
359 |
} |
360 |
//[end]
|
361 |
|
362 |
/**
|
363 |
* Especificar el layer para el recorte
|
364 |
* @param layer
|
365 |
*/
|
366 |
public void setLayer(FLayer fLayer) { |
367 |
this.fLayer = fLayer;
|
368 |
Extent extent2 = ((FLyrRasterSE) fLayer).getDatasource().getExtent(); |
369 |
getImageNavigator().setViewDimensions(extent2.getMin().getX(), extent2.getMax().getY(), extent2.getMax().getX(), extent2.getMin().getY()); |
370 |
getImageNavigator().setZoom(1.0/((FLyrRasterSE) fLayer).getDatasource().getXCellSize());
|
371 |
getImageNavigator().setAutoAdjusted(); |
372 |
|
373 |
Rendering rendering = ((FLyrRasterSE) getLayer()).getRender(); |
374 |
|
375 |
RasterFilterList rasterFilterList = rendering.getFilterList(); |
376 |
|
377 |
filterStatus = rasterFilterList.getStatusCloned(); |
378 |
initTransparency = rendering.getLastTransparency(); |
379 |
|
380 |
ColorTableFilter colorTableFilter = (ColorTableFilter) rasterFilterList.getByName(ColorTableFilter.names[0]);
|
381 |
if (colorTableFilter != null) { |
382 |
GridPalette gridPalette = new GridPalette((ColorTable) colorTableFilter.getColorTable().clone());
|
383 |
if (gridPalette.isCompressible()) {
|
384 |
if (RasterToolsUtil.messageBoxYesOrNot("La paleta se puede comprimir. ?Deseas hacerlo?", this)) |
385 |
gridPalette.compressPalette(); |
386 |
} |
387 |
|
388 |
ColorTable colorTable = new ColorTable();
|
389 |
colorTable.setName("Ninguno");
|
390 |
colorTable.createPaletteFromColorItems(gridPalette.getColorItems(), false);
|
391 |
colorTable.setInterpolated(true);
|
392 |
|
393 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), "Ninguno"); |
394 |
getListViewComponent().addItem(0, item);
|
395 |
getListViewComponent().setSelectedIndex(0);
|
396 |
reloadTable(true);
|
397 |
} |
398 |
} |
399 |
|
400 |
/**
|
401 |
* Especificar el layer para el recorte
|
402 |
* @param layer
|
403 |
*/
|
404 |
public FLayer getLayer() {
|
405 |
return fLayer;
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* Recarga la tabla de elementos
|
410 |
* @param isNewSelection
|
411 |
*/
|
412 |
public void reloadTable(boolean isNewSelection) { |
413 |
active = false;
|
414 |
ArrayList colorItems = ((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorItems();
|
415 |
lastColorTable = ((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable(); |
416 |
if (isNewSelection) {
|
417 |
lastColorTableCloned = (ColorTable) ((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable().clone(); |
418 |
} |
419 |
|
420 |
double min = Double.POSITIVE_INFINITY; |
421 |
double max = Double.NEGATIVE_INFINITY; |
422 |
getTabTable().clearTable(); |
423 |
for (int i = 0; i < colorItems.size(); i++) { |
424 |
ColorItem c1 = (ColorItem) colorItems.get(i); |
425 |
Double toRange = null; |
426 |
if (i + 1 < colorItems.size()) |
427 |
toRange = new Double(((ColorItem) colorItems.get(i + 1)).getValue()); |
428 |
if (c1.getValue() > max)
|
429 |
max = c1.getValue(); |
430 |
if (c1.getValue() < min)
|
431 |
min = c1.getValue(); |
432 |
getTabTable().addRowToTable(c1.getColor(), c1.getNameClass(), new Double(c1.getValue()), toRange, c1.getColor().getAlpha() + ""); |
433 |
} |
434 |
|
435 |
getTabInterpolated().clearTable(); |
436 |
for (int i = 0; i < colorItems.size(); i++) { |
437 |
ColorItem c1 = (ColorItem) colorItems.get(i); |
438 |
double percent = (((c1.getValue() - min) * 100) / (max - min)); |
439 |
|
440 |
ItemColorSlider aux = new ItemColorSlider(percent, c1.getColor());
|
441 |
aux.setInterpolated(c1.getInterpolated()); |
442 |
aux.setName(c1.getNameClass()); |
443 |
|
444 |
getTabInterpolated().getColorSliderEdition().addItem(aux, false);
|
445 |
} |
446 |
getTabInterpolated().initialState(); |
447 |
if (min > max) {
|
448 |
min = 0;
|
449 |
max = 255;
|
450 |
} |
451 |
getTabInterpolated().setLimits(min, max); |
452 |
|
453 |
active = true;
|
454 |
getImageNavigator().updateBuffer(); |
455 |
} |
456 |
|
457 |
/**
|
458 |
* Comprueba si el usuario ha cambiado los valores de la tabla de colores,
|
459 |
* si es as?, le pregunta al usuario si quiere guardar los datos, y seg?n la
|
460 |
* selecci?n, restaura los datos antiguos o los machaca.
|
461 |
*/
|
462 |
public void testLibraryChanged() { |
463 |
if (!lastColorTable.equals(lastColorTableCloned)) {
|
464 |
if (RasterToolsUtil.messageBoxYesOrNot("?Desea guardar los cambios?", this)) { |
465 |
|
466 |
} else {
|
467 |
|
468 |
} |
469 |
} |
470 |
} |
471 |
|
472 |
/**
|
473 |
* Accion que se ejecuta cuando cambia la seleccion de un item del
|
474 |
* ListViewComponent
|
475 |
*/
|
476 |
public void valueChanged(ListSelectionEvent e) { |
477 |
testLibraryChanged(); |
478 |
reloadTable(true);
|
479 |
} |
480 |
|
481 |
public void actionPerformed(ActionEvent e) { |
482 |
if (e.getSource() == getCheckBoxInterpolated()) {
|
483 |
for (int i = 0; i < getListViewComponent().getItems().size(); i++) { |
484 |
((ColorTableIconPainter) ((ListViewItem) getListViewComponent().getItems().get(i)).getIcon()).setInterpolated(getCheckBoxInterpolated().isSelected()); |
485 |
} |
486 |
lastColorTableCloned.setInterpolated(getCheckBoxInterpolated().isSelected()); |
487 |
getListViewComponent().repaint(); |
488 |
getImageNavigator().updateBuffer(); |
489 |
getTabInterpolated().setInterpolated(getCheckBoxInterpolated().isSelected()); |
490 |
return;
|
491 |
} |
492 |
if (e.getSource() == getButtonAdd()) {
|
493 |
ColorTable colorTable = new ColorTable();
|
494 |
colorTable.setName("NewLibrary");
|
495 |
colorTable.createPaletteFromColorItems(new ArrayList(), true); |
496 |
colorTable.setInterpolated(true);
|
497 |
|
498 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), "NewLibrary"); |
499 |
getListViewComponent().addItem(item); |
500 |
getListViewComponent().setSelectedIndex(getListViewComponent().getItems().size() - 1);
|
501 |
reloadTable(true);
|
502 |
} |
503 |
if (e.getSource() == getButtonDel()) {
|
504 |
if (getListViewComponent().getSelectedIndices().length > 0) { |
505 |
if (RasterToolsUtil.messageBoxYesOrNot("?Deseas borrar las librer?as seleccionadas?", this)) { |
506 |
int pos = getListViewComponent().getSelectedIndices()[0]; |
507 |
getListViewComponent().removeSelecteds(); |
508 |
getListViewComponent().setSelectedIndex(pos - 1);
|
509 |
reloadTable(true);
|
510 |
} |
511 |
} |
512 |
return;
|
513 |
} |
514 |
} |
515 |
|
516 |
/**
|
517 |
* Convierte la tabla en un array de objetos para poder crear con el el objeto Palette
|
518 |
* @return
|
519 |
* @throws NotInitializeException
|
520 |
*/
|
521 |
public ArrayList getTablePalette() { |
522 |
ArrayList arrayList = new ArrayList(); |
523 |
JTable jTable = getTabTable().getTableContainer().getTable().getJTable();
|
524 |
TableColorModel model = (TableColorModel) jTable.getModel(); |
525 |
for (int iRow = 0; iRow < jTable.getRowCount(); iRow++) { |
526 |
Color rgb = (Color) model.getValueAt(iRow, 0); |
527 |
ColorItem colorItem = new ColorItem();
|
528 |
colorItem.setColor(new Color( |
529 |
rgb.getRed(), |
530 |
rgb.getGreen(), |
531 |
rgb.getBlue(), |
532 |
Integer.valueOf((String) model.getValueAt(iRow, 5)).intValue())); |
533 |
|
534 |
if (model.getValueAt(iRow, 3) != null) |
535 |
colorItem.setValue(((Double) model.getValueAt(iRow, 3)).doubleValue()); |
536 |
// TODO: Hacer algo para conservar el valor de interpolacion
|
537 |
colorItem.setNameClass((String) model.getValueAt(iRow, 1)); |
538 |
arrayList.add(colorItem); |
539 |
} |
540 |
|
541 |
return arrayList;
|
542 |
} |
543 |
|
544 |
public void tableChanged(TableModelEvent e) { |
545 |
if (!active)
|
546 |
return;
|
547 |
|
548 |
((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).setColorItems(getTablePalette(), getCheckBoxInterpolated().isSelected(), false);
|
549 |
((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable().compressPalette(); |
550 |
getListViewComponent().repaint(); |
551 |
|
552 |
reloadTable(false);
|
553 |
} |
554 |
|
555 |
public void tabInterpolatedChanged() { |
556 |
if (!active)
|
557 |
return;
|
558 |
|
559 |
((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).setColorItems(getTabInterpolated().getPalette(), getCheckBoxInterpolated().isSelected(), false);
|
560 |
//((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable().compressPalette();
|
561 |
getListViewComponent().repaint(); |
562 |
|
563 |
getImageNavigator().updateBuffer(); |
564 |
} |
565 |
|
566 |
|
567 |
public GridPalette getGridPalette() {
|
568 |
return new GridPalette(((ColorTableIconPainter) getListViewComponent().getSelectedValue().getIcon()).getColorTable()); |
569 |
} |
570 |
|
571 |
/**
|
572 |
* Cuando se aceptan los cambios en el panel ejecutaremos el aceptar del
|
573 |
* listener
|
574 |
*/
|
575 |
public void accept() { |
576 |
colorTableListener.accept(); |
577 |
} |
578 |
|
579 |
/**
|
580 |
* Volvemos todo a la normalidad cuando se cancela
|
581 |
*/
|
582 |
public void cancel() { |
583 |
getLayer().getMapContext().invalidate(); |
584 |
} |
585 |
|
586 |
/**
|
587 |
* Volvemos todo a la normalidad cuando se cancela
|
588 |
*/
|
589 |
public void restoreFilters() { |
590 |
Rendering rendering = ((FLyrRasterSE) getLayer()).getRender(); |
591 |
rendering.getFilterList().setStatus(getFilterStatus()); |
592 |
rendering.setLastTransparency(initTransparency); |
593 |
} |
594 |
|
595 |
/**
|
596 |
* Devuelve el arrayList de filtros inicial
|
597 |
* @return
|
598 |
*/
|
599 |
public ArrayList getFilterStatus() { |
600 |
return filterStatus;
|
601 |
} |
602 |
} |