root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / panels / TabInterpolated.java @ 13777
History | View | Annotate | Download (16.7 KB)
1 | 12914 | bsanchez | /* 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 | package org.gvsig.rastertools.colortable.panels; |
||
20 | |||
21 | 13292 | bsanchez | import java.awt.Color; |
22 | 12939 | bsanchez | import java.awt.GridBagConstraints; |
23 | import java.awt.GridBagLayout; |
||
24 | 13022 | bsanchez | import java.awt.Insets; |
25 | 13173 | bsanchez | import java.awt.event.ActionEvent; |
26 | import java.awt.event.ActionListener; |
||
27 | 13394 | bsanchez | import java.awt.event.FocusEvent; |
28 | import java.awt.event.FocusListener; |
||
29 | 13403 | bsanchez | import java.awt.event.KeyEvent; |
30 | import java.awt.event.KeyListener; |
||
31 | 13022 | bsanchez | import java.util.ArrayList; |
32 | 12914 | bsanchez | |
33 | 13123 | bsanchez | import javax.swing.BorderFactory; |
34 | import javax.swing.JCheckBox; |
||
35 | 13022 | bsanchez | import javax.swing.JLabel; |
36 | 12914 | bsanchez | import javax.swing.JPanel; |
37 | 13123 | bsanchez | import javax.swing.JTextField; |
38 | 12914 | bsanchez | |
39 | 12939 | bsanchez | import org.gvsig.gui.beans.colorbutton.ColorButton; |
40 | import org.gvsig.gui.beans.colorbutton.ColorButtonEvent; |
||
41 | import org.gvsig.gui.beans.colorbutton.ColorButtonListener; |
||
42 | 12914 | bsanchez | import org.gvsig.gui.beans.colorslideredition.ColorSliderEdition; |
43 | 12939 | bsanchez | import org.gvsig.gui.beans.colorslideredition.ColorSliderEvent; |
44 | import org.gvsig.gui.beans.colorslideredition.ColorSliderListener; |
||
45 | import org.gvsig.gui.beans.colorslideredition.ItemColorSlider; |
||
46 | 13715 | bsanchez | import org.gvsig.gui.beans.listview.ListViewItem; |
47 | 13022 | bsanchez | import org.gvsig.raster.datastruct.ColorItem; |
48 | 13292 | bsanchez | import org.gvsig.rastertools.colortable.ui.ColorTableIconPainter; |
49 | 13022 | bsanchez | import org.gvsig.rastertools.colortable.ui.ColorTablePanel; |
50 | 13356 | bsanchez | |
51 | import com.iver.andami.PluginServices; |
||
52 | 12914 | bsanchez | /**
|
53 | 13292 | bsanchez | * Pesta?a para las interpolaciones de la tabla de color, aqui se tratar?n
|
54 | * los gradientes de color, etc...
|
||
55 | 12914 | bsanchez | *
|
56 | * @version 27/06/2007
|
||
57 | * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
||
58 | */
|
||
59 | 13403 | bsanchez | public class TabInterpolated extends JPanel implements ColorSliderListener, ColorButtonListener, ActionListener, FocusListener, KeyListener { |
60 | 13292 | bsanchez | private static final long serialVersionUID = -5208861410196059899L; |
61 | 12914 | bsanchez | |
62 | 13292 | bsanchez | private double min = Double.POSITIVE_INFINITY; |
63 | private double max = Double.NEGATIVE_INFINITY; |
||
64 | private ColorTablePanel colorTablePanel = null; |
||
65 | 13022 | bsanchez | |
66 | 12914 | bsanchez | //[start]Variables UI
|
67 | 13022 | bsanchez | private ColorSliderEdition colorSliderEdition = null; |
68 | private ColorButton colorButton = null; |
||
69 | 13403 | bsanchez | private JTextField jTextClassName = null; |
70 | 13123 | bsanchez | private JPanel jPanelLimits = null; |
71 | private JCheckBox jCheckBoxLimits = null; |
||
72 | 13403 | bsanchez | private JLabel jLabelColor = null; |
73 | private JLabel jLabelClassName = null; |
||
74 | 13173 | bsanchez | private JLabel jLabelMinimum = null; |
75 | private JLabel jLabelMaximum = null; |
||
76 | 13123 | bsanchez | private JTextField jTextFieldMinimum = null; |
77 | |||
78 | private JTextField jTextFieldMaximum = null; |
||
79 | 12914 | bsanchez | //[end]
|
80 | |||
81 | 13292 | bsanchez | /**
|
82 | * Constructor de un TabInterpolated
|
||
83 | * @param colorTablePanel
|
||
84 | */
|
||
85 | 13022 | bsanchez | public TabInterpolated(ColorTablePanel colorTablePanel) {
|
86 | this.colorTablePanel = colorTablePanel;
|
||
87 | 12914 | bsanchez | initialize(); |
88 | } |
||
89 | |||
90 | 13292 | bsanchez | //[start] Code UI
|
91 | /**
|
||
92 | * Creaci?n de todos los componentes del interfaz
|
||
93 | */
|
||
94 | 12914 | bsanchez | public void initialize() { |
95 | 12939 | bsanchez | setLayout(new GridBagLayout()); |
96 | |||
97 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
98 | 13022 | bsanchez | gridBagConstraints.gridwidth = 2;
|
99 | 12939 | bsanchez | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
100 | gridBagConstraints.weightx = 1.0;
|
||
101 | 13022 | bsanchez | gridBagConstraints.insets = new Insets(5, 5, 2, 5); |
102 | 12939 | bsanchez | add(getColorSliderEdition(), gridBagConstraints); |
103 | |||
104 | 13022 | bsanchez | gridBagConstraints = new GridBagConstraints(); |
105 | 13403 | bsanchez | gridBagConstraints.gridx = 0;
|
106 | gridBagConstraints.gridy = 1;
|
||
107 | gridBagConstraints.anchor = GridBagConstraints.EAST;
|
||
108 | gridBagConstraints.weightx = 0.5;
|
||
109 | gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
||
110 | add(getJLabelColor(), gridBagConstraints); |
||
111 | |||
112 | gridBagConstraints = new GridBagConstraints(); |
||
113 | 13022 | bsanchez | gridBagConstraints.gridx = 1;
|
114 | gridBagConstraints.gridy = 1;
|
||
115 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
116 | gridBagConstraints.weightx = 0.5;
|
||
117 | 13123 | bsanchez | gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
118 | 13022 | bsanchez | add(getColorButton(), gridBagConstraints); |
119 | 13403 | bsanchez | |
120 | 13022 | bsanchez | gridBagConstraints = new GridBagConstraints(); |
121 | 12939 | bsanchez | gridBagConstraints.gridx = 0;
|
122 | 13403 | bsanchez | gridBagConstraints.gridy = 2;
|
123 | 13022 | bsanchez | gridBagConstraints.anchor = GridBagConstraints.EAST;
|
124 | 13123 | bsanchez | gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
125 | 13403 | bsanchez | add(getJLabelClassName(), gridBagConstraints); |
126 | |||
127 | 13123 | bsanchez | gridBagConstraints = new GridBagConstraints(); |
128 | 13403 | bsanchez | gridBagConstraints.gridx = 1;
|
129 | gridBagConstraints.gridy = 2;
|
||
130 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
131 | gridBagConstraints.weightx = 1.0;
|
||
132 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
133 | gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
||
134 | add(getJTextClassName(), gridBagConstraints); |
||
135 | |||
136 | gridBagConstraints = new GridBagConstraints(); |
||
137 | 13123 | bsanchez | gridBagConstraints.gridx = 0;
|
138 | 13403 | bsanchez | gridBagConstraints.gridy = 3;
|
139 | 13123 | bsanchez | gridBagConstraints.anchor = GridBagConstraints.CENTER;
|
140 | gridBagConstraints.gridwidth = 2;
|
||
141 | gridBagConstraints.weightx = 1.0;
|
||
142 | gridBagConstraints.insets = new Insets(2, 5, 5, 5); |
||
143 | add(getJPanelLimits(), gridBagConstraints); |
||
144 | 12914 | bsanchez | } |
145 | |||
146 | 13173 | bsanchez | private JLabel getJLabelMinimum() { |
147 | if (jLabelMinimum == null) { |
||
148 | jLabelMinimum = new JLabel(); |
||
149 | 13356 | bsanchez | jLabelMinimum.setText(PluginServices.getText(this, "minimo") + ": "); |
150 | 13173 | bsanchez | jLabelMinimum.setEnabled(false);
|
151 | } |
||
152 | return jLabelMinimum;
|
||
153 | } |
||
154 | |||
155 | private JLabel getJLabelMaximum() { |
||
156 | if (jLabelMaximum == null) { |
||
157 | jLabelMaximum = new JLabel(); |
||
158 | 13356 | bsanchez | jLabelMaximum.setText(PluginServices.getText(this, "maximo")+ ": "); |
159 | 13173 | bsanchez | jLabelMaximum.setEnabled(false);
|
160 | } |
||
161 | return jLabelMaximum;
|
||
162 | } |
||
163 | |||
164 | 13403 | bsanchez | private JLabel getJLabelColor() { |
165 | if (jLabelColor == null) { |
||
166 | jLabelColor = new JLabel(PluginServices.getText(this, "tabinterpolated_color") + ": "); |
||
167 | jLabelColor.setEnabled(false);
|
||
168 | } |
||
169 | return jLabelColor;
|
||
170 | } |
||
171 | |||
172 | private JLabel getJLabelClassName() { |
||
173 | if (jLabelClassName == null) { |
||
174 | jLabelClassName = new JLabel(PluginServices.getText(this, "nombre") + ": "); |
||
175 | jLabelClassName.setEnabled(false);
|
||
176 | } |
||
177 | return jLabelClassName;
|
||
178 | } |
||
179 | |||
180 | 13173 | bsanchez | private JTextField getJTextFieldMinimum() { |
181 | if (jTextFieldMinimum == null) { |
||
182 | jTextFieldMinimum = new JTextField(); |
||
183 | jTextFieldMinimum.setText("0");
|
||
184 | jTextFieldMinimum.setEnabled(false);
|
||
185 | 13394 | bsanchez | jTextFieldMinimum.addFocusListener(this);
|
186 | 13173 | bsanchez | } |
187 | return jTextFieldMinimum;
|
||
188 | } |
||
189 | |||
190 | private JTextField getJTextFieldMaximum() { |
||
191 | if (jTextFieldMaximum == null) { |
||
192 | jTextFieldMaximum = new JTextField(); |
||
193 | jTextFieldMaximum.setText("255");
|
||
194 | jTextFieldMaximum.setEnabled(false);
|
||
195 | 13394 | bsanchez | jTextFieldMaximum.addFocusListener(this);
|
196 | 13173 | bsanchez | } |
197 | return jTextFieldMaximum;
|
||
198 | } |
||
199 | |||
200 | private JCheckBox getJCheckBoxLimits() { |
||
201 | if (jCheckBoxLimits == null) { |
||
202 | jCheckBoxLimits = new JCheckBox(); |
||
203 | 13356 | bsanchez | jCheckBoxLimits.setText(PluginServices.getText(this, "ajustar_limites")); |
204 | 13173 | bsanchez | jCheckBoxLimits.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
205 | jCheckBoxLimits.setMargin(new Insets(0, 0, 0, 0)); |
||
206 | jCheckBoxLimits.addActionListener(this);
|
||
207 | } |
||
208 | return jCheckBoxLimits;
|
||
209 | } |
||
210 | |||
211 | 13123 | bsanchez | private JPanel getJPanelLimits() { |
212 | if (jPanelLimits == null) { |
||
213 | java.awt.GridBagConstraints gridBagConstraints; |
||
214 | |||
215 | jPanelLimits = new JPanel(); |
||
216 | jPanelLimits.setLayout(new GridBagLayout()); |
||
217 | |||
218 | 13356 | bsanchez | jPanelLimits.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "limites"))); |
219 | 13123 | bsanchez | gridBagConstraints = new GridBagConstraints(); |
220 | gridBagConstraints.gridwidth = 2;
|
||
221 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
222 | gridBagConstraints.insets = new Insets(5, 5, 2, 5); |
||
223 | 13173 | bsanchez | jPanelLimits.add(getJCheckBoxLimits(), gridBagConstraints); |
224 | 13123 | bsanchez | |
225 | gridBagConstraints = new GridBagConstraints(); |
||
226 | gridBagConstraints.gridx = 0;
|
||
227 | gridBagConstraints.gridy = 1;
|
||
228 | gridBagConstraints.anchor = GridBagConstraints.EAST;
|
||
229 | gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
||
230 | 13173 | bsanchez | jPanelLimits.add(getJLabelMinimum(), gridBagConstraints); |
231 | 13123 | bsanchez | |
232 | gridBagConstraints = new GridBagConstraints(); |
||
233 | gridBagConstraints.gridx = 0;
|
||
234 | gridBagConstraints.gridy = 2;
|
||
235 | gridBagConstraints.anchor = GridBagConstraints.EAST;
|
||
236 | gridBagConstraints.insets = new Insets(2, 5, 5, 2); |
||
237 | 13403 | bsanchez | gridBagConstraints.weightx = 0.5;
|
238 | 13173 | bsanchez | jPanelLimits.add(getJLabelMaximum(), gridBagConstraints); |
239 | 13123 | bsanchez | |
240 | gridBagConstraints = new GridBagConstraints(); |
||
241 | gridBagConstraints.gridx = 1;
|
||
242 | gridBagConstraints.gridy = 1;
|
||
243 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
244 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
245 | 13403 | bsanchez | gridBagConstraints.weightx = 0.5;
|
246 | 13123 | bsanchez | gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
247 | 13173 | bsanchez | jPanelLimits.add(getJTextFieldMinimum(), gridBagConstraints); |
248 | 13123 | bsanchez | |
249 | gridBagConstraints = new GridBagConstraints(); |
||
250 | gridBagConstraints.gridx = 1;
|
||
251 | gridBagConstraints.gridy = 2;
|
||
252 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
253 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
254 | gridBagConstraints.weightx = 1.0;
|
||
255 | gridBagConstraints.insets = new Insets(2, 2, 5, 5); |
||
256 | 13173 | bsanchez | jPanelLimits.add(getJTextFieldMaximum(), gridBagConstraints); |
257 | 13123 | bsanchez | } |
258 | return jPanelLimits;
|
||
259 | } |
||
260 | |||
261 | 12939 | bsanchez | public ColorSliderEdition getColorSliderEdition() {
|
262 | 12914 | bsanchez | if (colorSliderEdition == null) { |
263 | colorSliderEdition = new ColorSliderEdition();
|
||
264 | 12939 | bsanchez | colorSliderEdition.addValueChangedListener(this);
|
265 | colorSliderEdition.addSelectionChangedListener(this);
|
||
266 | 12914 | bsanchez | } |
267 | return colorSliderEdition;
|
||
268 | } |
||
269 | |||
270 | 12939 | bsanchez | private ColorButton getColorButton() {
|
271 | if (colorButton == null) { |
||
272 | colorButton = new ColorButton();
|
||
273 | colorButton.addValueChangedListener(this);
|
||
274 | 12914 | bsanchez | } |
275 | 12939 | bsanchez | return colorButton;
|
276 | 12914 | bsanchez | } |
277 | 13403 | bsanchez | |
278 | private JTextField getJTextClassName() { |
||
279 | if (jTextClassName == null) { |
||
280 | jTextClassName = new JTextField(); |
||
281 | jTextClassName.setEnabled(false);
|
||
282 | jTextClassName.addKeyListener(this);
|
||
283 | } |
||
284 | return jTextClassName;
|
||
285 | } |
||
286 | 12914 | bsanchez | //[end]
|
287 | |||
288 | 13292 | bsanchez | /**
|
289 | * Define si el componente ColorSliderEdition tiene interpolaci?n o no.
|
||
290 | * @param value
|
||
291 | */
|
||
292 | 12914 | bsanchez | public void setInterpolated(boolean value) { |
293 | getColorSliderEdition().setInterpolated(value); |
||
294 | } |
||
295 | 12939 | bsanchez | |
296 | 13292 | bsanchez | /*
|
297 | * (non-Javadoc)
|
||
298 | * @see org.gvsig.gui.beans.colorslideredition.ColorSliderListener#actionSelectionChanged(org.gvsig.gui.beans.colorslideredition.ColorSliderEvent)
|
||
299 | */
|
||
300 | 12939 | bsanchez | public void actionSelectionChanged(ColorSliderEvent e) { |
301 | 13022 | bsanchez | ItemColorSlider itemColorSlider = getColorSliderEdition().getSelectedItem(); |
302 | 13403 | bsanchez | boolean enabled = false; |
303 | 12939 | bsanchez | if ((itemColorSlider != null) && (itemColorSlider.getSelected() == 1)) { |
304 | getColorButton().setColor(itemColorSlider.getColor()); |
||
305 | 13403 | bsanchez | getJTextClassName().setText(itemColorSlider.getName()); |
306 | enabled = true;
|
||
307 | 12939 | bsanchez | } |
308 | 13403 | bsanchez | setControlsEnabled(enabled); |
309 | 12939 | bsanchez | } |
310 | |||
311 | 13292 | bsanchez | /**
|
312 | * Acci?n que se ejecuta cuando cambia el color el usuario. Este metodo
|
||
313 | * actualiza el color del ItemColorSlider segun la seleccion del usuario.
|
||
314 | */
|
||
315 | 12939 | bsanchez | private void callValueColorChanged() { |
316 | 13022 | bsanchez | ItemColorSlider itemColorSlider = getColorSliderEdition().getSelectedItem(); |
317 | 12939 | bsanchez | if (itemColorSlider != null) { |
318 | itemColorSlider.setColor(getColorButton().getColor()); |
||
319 | 13403 | bsanchez | itemColorSlider.setName(getJTextClassName().getText()); |
320 | 13022 | bsanchez | getColorSliderEdition().repaint(); |
321 | 12939 | bsanchez | } |
322 | } |
||
323 | |||
324 | 13292 | bsanchez | /*
|
325 | * (non-Javadoc)
|
||
326 | * @see org.gvsig.gui.beans.colorbutton.ColorButtonListener#actionValueDragged(org.gvsig.gui.beans.colorbutton.ColorButtonEvent)
|
||
327 | */
|
||
328 | 12939 | bsanchez | public void actionValueDragged(ColorButtonEvent e) { |
329 | callValueColorChanged(); |
||
330 | 13292 | bsanchez | // refreshItems();
|
331 | 12939 | bsanchez | } |
332 | |||
333 | /**
|
||
334 | 13022 | bsanchez | * Convierte el slider de la paleta en un array de objetos para poder crear
|
335 | * con ?l el objeto Palette
|
||
336 | * @return
|
||
337 | */
|
||
338 | public ArrayList getPalette() { |
||
339 | 13173 | bsanchez | double min2 = min;
|
340 | double max2 = max;
|
||
341 | |||
342 | if (getJCheckBoxLimits().isSelected()) {
|
||
343 | 13777 | bsanchez | try {
|
344 | min2 = Double.parseDouble(getJTextFieldMinimum().getText());
|
||
345 | } catch (NumberFormatException exception) { |
||
346 | getJTextFieldMinimum().setText(Double.toString(min));
|
||
347 | } |
||
348 | try {
|
||
349 | max2 = Double.parseDouble(getJTextFieldMaximum().getText());
|
||
350 | } catch (NumberFormatException exception) { |
||
351 | getJTextFieldMaximum().setText(Double.toString(max));
|
||
352 | } |
||
353 | 13173 | bsanchez | } |
354 | 13777 | bsanchez | |
355 | if (min2 > max2) {
|
||
356 | double aux = min2;
|
||
357 | min2 = max2; |
||
358 | max2 = aux; |
||
359 | } |
||
360 | 13173 | bsanchez | |
361 | 13022 | bsanchez | ArrayList arrayList = new ArrayList(); |
362 | ArrayList items = getColorSliderEdition().getItemsShowed();
|
||
363 | |||
364 | // A?adir el minimo
|
||
365 | 13292 | bsanchez | ItemColorSlider item; |
366 | if (items.size() > 0) |
||
367 | item = (ItemColorSlider) items.get(0);
|
||
368 | else
|
||
369 | item = new ItemColorSlider(0, Color.black); |
||
370 | 13022 | bsanchez | ColorItem colorItem = new ColorItem();
|
371 | colorItem.setColor(item.getColor()); |
||
372 | 13219 | bsanchez | colorItem.setInterpolated(50);
|
373 | 13022 | bsanchez | colorItem.setNameClass("");
|
374 | 13173 | bsanchez | colorItem.setValue(min2); |
375 | 13022 | bsanchez | arrayList.add(colorItem); |
376 | |||
377 | for (int i = 0; i < items.size(); i++) { |
||
378 | item = (ItemColorSlider) items.get(i); |
||
379 | colorItem = new ColorItem();
|
||
380 | colorItem.setColor(item.getColor()); |
||
381 | colorItem.setInterpolated((int) item.getInterpolated());
|
||
382 | colorItem.setNameClass(item.getName()); |
||
383 | |||
384 | 13173 | bsanchez | colorItem.setValue(min2 + ((item.getValue() * (max2 - min2)) / 100.0d));
|
385 | 13022 | bsanchez | |
386 | arrayList.add(colorItem); |
||
387 | } |
||
388 | |||
389 | // A?adir el maximo
|
||
390 | 13292 | bsanchez | if (items.size() > 0) |
391 | item = (ItemColorSlider) items.get(items.size() - 1);
|
||
392 | else
|
||
393 | item = new ItemColorSlider(255, Color.white); |
||
394 | 13022 | bsanchez | colorItem = new ColorItem();
|
395 | colorItem.setColor(item.getColor()); |
||
396 | 13219 | bsanchez | colorItem.setInterpolated(50);
|
397 | 13022 | bsanchez | colorItem.setNameClass("");
|
398 | 13173 | bsanchez | colorItem.setValue(max2); |
399 | 13022 | bsanchez | arrayList.add(colorItem); |
400 | |||
401 | |||
402 | return arrayList;
|
||
403 | 13292 | bsanchez | } |
404 | |||
405 | /**
|
||
406 | * Refresco de los items del panel de color
|
||
407 | * @param colorItems
|
||
408 | */
|
||
409 | public void refreshItems() { |
||
410 | 13715 | bsanchez | ListViewItem listViewItem = colorTablePanel.getListViewComponent().getLastSelectedItem(); |
411 | if (listViewItem != null) |
||
412 | ((ColorTableIconPainter) listViewItem.getIcon()).setColorItems(getPalette(), colorTablePanel.getCheckBoxInterpolated().isSelected(), false);
|
||
413 | 13292 | bsanchez | colorTablePanel.tabChanged(); |
414 | 13022 | bsanchez | } |
415 | 13292 | bsanchez | |
416 | /*
|
||
417 | * (non-Javadoc)
|
||
418 | * @see org.gvsig.gui.beans.colorbutton.ColorButtonListener#actionValueChanged(org.gvsig.gui.beans.colorbutton.ColorButtonEvent)
|
||
419 | */
|
||
420 | public void actionValueChanged(ColorButtonEvent e) { |
||
421 | callValueColorChanged(); |
||
422 | refreshItems(); |
||
423 | } |
||
424 | 13173 | bsanchez | |
425 | 13292 | bsanchez | /*
|
426 | * (non-Javadoc)
|
||
427 | * @see org.gvsig.gui.beans.colorslideredition.ColorSliderListener#actionValueChanged(org.gvsig.gui.beans.colorslideredition.ColorSliderEvent)
|
||
428 | */
|
||
429 | public void actionValueChanged(ColorSliderEvent e) { |
||
430 | refreshItems(); |
||
431 | } |
||
432 | |||
433 | public void initialState() { |
||
434 | getColorSliderEdition().repaint(); |
||
435 | 13403 | bsanchez | setControlsEnabled(false);
|
436 | 13292 | bsanchez | } |
437 | 13403 | bsanchez | |
438 | public void setControlsEnabled(boolean value) { |
||
439 | getColorButton().setEnabled(value); |
||
440 | getJLabelColor().setEnabled(value); |
||
441 | getJTextClassName().setEnabled(value); |
||
442 | getJLabelClassName().setEnabled(value); |
||
443 | if (value == false) |
||
444 | getJTextClassName().setText("");
|
||
445 | } |
||
446 | 13292 | bsanchez | |
447 | /**
|
||
448 | * Carga inicial de los items del panel de color
|
||
449 | * @param colorItems
|
||
450 | */
|
||
451 | public void reloadItems(ArrayList colorItems) { |
||
452 | min = Double.POSITIVE_INFINITY;
|
||
453 | max = Double.NEGATIVE_INFINITY;
|
||
454 | for (int i = 0; i < colorItems.size(); i++) { |
||
455 | ColorItem c1 = (ColorItem) colorItems.get(i); |
||
456 | if (c1.getValue() > max)
|
||
457 | max = c1.getValue(); |
||
458 | if (c1.getValue() < min)
|
||
459 | min = c1.getValue(); |
||
460 | } |
||
461 | |||
462 | clearTable(); |
||
463 | for (int i = 0; i < colorItems.size(); i++) { |
||
464 | ColorItem c1 = (ColorItem) colorItems.get(i); |
||
465 | double percent = (((c1.getValue() - min) * 100) / (max - min)); |
||
466 | |||
467 | ItemColorSlider aux = new ItemColorSlider(percent, c1.getColor());
|
||
468 | aux.setInterpolated(c1.getInterpolated()); |
||
469 | aux.setName(c1.getNameClass()); |
||
470 | |||
471 | getColorSliderEdition().addItem(aux, false);
|
||
472 | } |
||
473 | initialState(); |
||
474 | if (min > max) {
|
||
475 | min = 0;
|
||
476 | max = 255;
|
||
477 | } |
||
478 | setInterpolated(colorTablePanel.getCheckBoxInterpolated().isSelected()); |
||
479 | refreshItems(); |
||
480 | } |
||
481 | |||
482 | /**
|
||
483 | * Borra todas las filas de la tabla.
|
||
484 | */
|
||
485 | public void clearTable() { |
||
486 | getColorSliderEdition().removeAllItems(); |
||
487 | } |
||
488 | |||
489 | /*
|
||
490 | * (non-Javadoc)
|
||
491 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
492 | */
|
||
493 | 13173 | bsanchez | public void actionPerformed(ActionEvent e) { |
494 | if (e.getSource() == getJCheckBoxLimits()) {
|
||
495 | getJTextFieldMaximum().setEnabled(getJCheckBoxLimits().isSelected()); |
||
496 | getJTextFieldMinimum().setEnabled(getJCheckBoxLimits().isSelected()); |
||
497 | getJLabelMaximum().setEnabled(getJCheckBoxLimits().isSelected()); |
||
498 | getJLabelMinimum().setEnabled(getJCheckBoxLimits().isSelected()); |
||
499 | callValueColorChanged(); |
||
500 | 13292 | bsanchez | refreshItems(); |
501 | 13173 | bsanchez | } |
502 | } |
||
503 | 13394 | bsanchez | |
504 | /*
|
||
505 | * (non-Javadoc)
|
||
506 | * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
|
||
507 | */
|
||
508 | public void focusLost(FocusEvent e) { |
||
509 | callValueColorChanged(); |
||
510 | refreshItems(); |
||
511 | } |
||
512 | 13403 | bsanchez | |
513 | 13777 | bsanchez | /*
|
514 | * (non-Javadoc)
|
||
515 | * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
|
||
516 | */
|
||
517 | 13403 | bsanchez | public void keyReleased(KeyEvent e) { |
518 | if (e.getSource() == getJTextClassName()) {
|
||
519 | callValueColorChanged(); |
||
520 | refreshItems(); |
||
521 | } |
||
522 | } |
||
523 | |||
524 | 13777 | bsanchez | public void actionValueDragged(ColorSliderEvent e) {} |
525 | public void focusGained(FocusEvent e) {} |
||
526 | public void keyPressed(KeyEvent e) {} |
||
527 | public void keyTyped(KeyEvent e) {} |
||
528 | 12914 | bsanchez | } |