root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / panels / TabInterpolated.java @ 13022
History | View | Annotate | Download (6.66 KB)
1 |
/* 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 |
import java.awt.GridBagConstraints; |
22 |
import java.awt.GridBagLayout; |
23 |
import java.awt.Insets; |
24 |
import java.util.ArrayList; |
25 |
|
26 |
import javax.swing.JLabel; |
27 |
import javax.swing.JPanel; |
28 |
|
29 |
import org.gvsig.gui.beans.colorbutton.ColorButton; |
30 |
import org.gvsig.gui.beans.colorbutton.ColorButtonEvent; |
31 |
import org.gvsig.gui.beans.colorbutton.ColorButtonListener; |
32 |
import org.gvsig.gui.beans.colorslideredition.ColorSliderEdition; |
33 |
import org.gvsig.gui.beans.colorslideredition.ColorSliderEvent; |
34 |
import org.gvsig.gui.beans.colorslideredition.ColorSliderListener; |
35 |
import org.gvsig.gui.beans.colorslideredition.ItemColorSlider; |
36 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
37 |
import org.gvsig.raster.datastruct.ColorItem; |
38 |
import org.gvsig.rastertools.colortable.ui.ColorTablePanel; |
39 |
/**
|
40 |
*
|
41 |
* @version 27/06/2007
|
42 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
43 |
*/
|
44 |
public class TabInterpolated extends JPanel implements ColorSliderListener, ColorButtonListener { |
45 |
private static final long serialVersionUID = -5208861410196059899L; |
46 |
|
47 |
private double min = Double.POSITIVE_INFINITY; |
48 |
private double max = Double.NEGATIVE_INFINITY; |
49 |
private ColorTablePanel colorTablePanel = null; |
50 |
|
51 |
//[start]Variables UI
|
52 |
private ColorSliderEdition colorSliderEdition = null; |
53 |
private ColorButton colorButton = null; |
54 |
private JLabel jLabelColor = null; |
55 |
//[end]
|
56 |
|
57 |
//[start] Code UI
|
58 |
public TabInterpolated(ColorTablePanel colorTablePanel) {
|
59 |
this.colorTablePanel = colorTablePanel;
|
60 |
initialize(); |
61 |
} |
62 |
|
63 |
public void initialize() { |
64 |
setLayout(new GridBagLayout()); |
65 |
|
66 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
67 |
gridBagConstraints.gridwidth = 2;
|
68 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
69 |
gridBagConstraints.weightx = 1.0;
|
70 |
gridBagConstraints.insets = new Insets(5, 5, 2, 5); |
71 |
|
72 |
add(getColorSliderEdition(), gridBagConstraints); |
73 |
|
74 |
gridBagConstraints = new GridBagConstraints(); |
75 |
gridBagConstraints.gridx = 1;
|
76 |
gridBagConstraints.gridy = 1;
|
77 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
78 |
gridBagConstraints.weightx = 0.5;
|
79 |
gridBagConstraints.insets = new Insets(2, 2, 5, 5); |
80 |
add(getColorButton(), gridBagConstraints); |
81 |
|
82 |
jLabelColor = new JLabel("Color: "); |
83 |
jLabelColor.setEnabled(false);
|
84 |
gridBagConstraints = new GridBagConstraints(); |
85 |
gridBagConstraints.gridx = 0;
|
86 |
gridBagConstraints.gridy = 1;
|
87 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
88 |
gridBagConstraints.weightx = 0.5;
|
89 |
gridBagConstraints.insets = new Insets(2, 5, 5, 2); |
90 |
add(jLabelColor, gridBagConstraints); |
91 |
} |
92 |
|
93 |
public ColorSliderEdition getColorSliderEdition() {
|
94 |
if (colorSliderEdition == null) { |
95 |
colorSliderEdition = new ColorSliderEdition();
|
96 |
colorSliderEdition.addValueChangedListener(this);
|
97 |
colorSliderEdition.addSelectionChangedListener(this);
|
98 |
} |
99 |
return colorSliderEdition;
|
100 |
} |
101 |
|
102 |
private ColorButton getColorButton() {
|
103 |
if (colorButton == null) { |
104 |
colorButton = new ColorButton();
|
105 |
colorButton.addValueChangedListener(this);
|
106 |
} |
107 |
return colorButton;
|
108 |
} |
109 |
//[end]
|
110 |
|
111 |
public void setInterpolated(boolean value) { |
112 |
getColorSliderEdition().setInterpolated(value); |
113 |
} |
114 |
|
115 |
public void actionSelectionChanged(ColorSliderEvent e) { |
116 |
ItemColorSlider itemColorSlider = getColorSliderEdition().getSelectedItem(); |
117 |
if ((itemColorSlider != null) && (itemColorSlider.getSelected() == 1)) { |
118 |
getColorButton().setColor(itemColorSlider.getColor()); |
119 |
getColorButton().setEnabled(true);
|
120 |
jLabelColor.setEnabled(true);
|
121 |
} else {
|
122 |
getColorButton().setEnabled(false);
|
123 |
jLabelColor.setEnabled(false);
|
124 |
} |
125 |
} |
126 |
|
127 |
public void actionValueChanged(ColorSliderEvent e) { |
128 |
colorTablePanel.tabInterpolatedChanged(); |
129 |
} |
130 |
|
131 |
public void actionValueDragged(ColorSliderEvent e) { |
132 |
colorTablePanel.tabInterpolatedChanged(); |
133 |
} |
134 |
|
135 |
private void callValueColorChanged() { |
136 |
ItemColorSlider itemColorSlider = getColorSliderEdition().getSelectedItem(); |
137 |
if (itemColorSlider != null) { |
138 |
itemColorSlider.setColor(getColorButton().getColor()); |
139 |
getColorSliderEdition().repaint(); |
140 |
} |
141 |
} |
142 |
|
143 |
public void actionValueDragged(ColorButtonEvent e) { |
144 |
callValueColorChanged(); |
145 |
//colorTablePanel.tabInterpolatedChanged();
|
146 |
} |
147 |
|
148 |
public void actionValueChanged(ColorButtonEvent e) { |
149 |
callValueColorChanged(); |
150 |
colorTablePanel.tabInterpolatedChanged(); |
151 |
} |
152 |
|
153 |
public void initialState() { |
154 |
getColorSliderEdition().repaint(); |
155 |
getColorButton().setEnabled(false);
|
156 |
} |
157 |
|
158 |
public void setLimits(double min, double max) { |
159 |
this.min = min;
|
160 |
this.max = max;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Borra todas las filas de la tabla.
|
165 |
*/
|
166 |
public void clearTable() { |
167 |
getColorSliderEdition().removeAllItems(); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Convierte el slider de la paleta en un array de objetos para poder crear
|
172 |
* con ?l el objeto Palette
|
173 |
* @return
|
174 |
* @throws NotInitializeException
|
175 |
*/
|
176 |
public ArrayList getPalette() { |
177 |
ArrayList arrayList = new ArrayList(); |
178 |
ArrayList items = getColorSliderEdition().getItemsShowed();
|
179 |
|
180 |
// A?adir el minimo
|
181 |
ItemColorSlider item = (ItemColorSlider) items.get(0);
|
182 |
ColorItem colorItem = new ColorItem();
|
183 |
colorItem.setColor(item.getColor()); |
184 |
colorItem.setInterpolated(item.getInterpolated()); |
185 |
colorItem.setNameClass("");
|
186 |
colorItem.setValue(min); |
187 |
arrayList.add(colorItem); |
188 |
|
189 |
for (int i = 0; i < items.size(); i++) { |
190 |
item = (ItemColorSlider) items.get(i); |
191 |
colorItem = new ColorItem();
|
192 |
colorItem.setColor(item.getColor()); |
193 |
colorItem.setInterpolated((int) item.getInterpolated());
|
194 |
colorItem.setNameClass(item.getName()); |
195 |
|
196 |
colorItem.setValue(min + ((item.getValue() * (max - min)) / 100.0d));
|
197 |
|
198 |
arrayList.add(colorItem); |
199 |
} |
200 |
|
201 |
// A?adir el maximo
|
202 |
item = (ItemColorSlider) items.get(items.size() - 1);
|
203 |
colorItem = new ColorItem();
|
204 |
colorItem.setColor(item.getColor()); |
205 |
colorItem.setInterpolated(item.getInterpolated()); |
206 |
colorItem.setNameClass("");
|
207 |
colorItem.setValue(max); |
208 |
arrayList.add(colorItem); |
209 |
|
210 |
|
211 |
return arrayList;
|
212 |
} |
213 |
} |