Revision 13022 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/panels/TabInterpolated.java
TabInterpolated.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
import java.awt.GridBagConstraints; |
22 | 22 |
import java.awt.GridBagLayout; |
23 |
import java.awt.Insets; |
|
24 |
import java.util.ArrayList; |
|
23 | 25 |
|
26 |
import javax.swing.JLabel; |
|
24 | 27 |
import javax.swing.JPanel; |
25 | 28 |
|
26 | 29 |
import org.gvsig.gui.beans.colorbutton.ColorButton; |
... | ... | |
30 | 33 |
import org.gvsig.gui.beans.colorslideredition.ColorSliderEvent; |
31 | 34 |
import org.gvsig.gui.beans.colorslideredition.ColorSliderListener; |
32 | 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; |
|
33 | 39 |
/** |
34 | 40 |
* |
35 | 41 |
* @version 27/06/2007 |
... | ... | |
38 | 44 |
public class TabInterpolated extends JPanel implements ColorSliderListener, ColorButtonListener { |
39 | 45 |
private static final long serialVersionUID = -5208861410196059899L; |
40 | 46 |
|
47 |
private double min = Double.POSITIVE_INFINITY; |
|
48 |
private double max = Double.NEGATIVE_INFINITY; |
|
49 |
private ColorTablePanel colorTablePanel = null; |
|
50 |
|
|
41 | 51 |
//[start]Variables UI |
42 |
private ColorSliderEdition colorSliderEdition = null; |
|
43 |
private ColorButton colorButton = null; |
|
52 |
private ColorSliderEdition colorSliderEdition = null; |
|
53 |
private ColorButton colorButton = null; |
|
54 |
private JLabel jLabelColor = null; |
|
44 | 55 |
//[end] |
45 | 56 |
|
46 | 57 |
//[start] Code UI |
47 |
public TabInterpolated() { |
|
58 |
public TabInterpolated(ColorTablePanel colorTablePanel) { |
|
59 |
this.colorTablePanel = colorTablePanel; |
|
48 | 60 |
initialize(); |
49 | 61 |
} |
50 | 62 |
|
... | ... | |
52 | 64 |
setLayout(new GridBagLayout()); |
53 | 65 |
|
54 | 66 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
67 |
gridBagConstraints.gridwidth = 2; |
|
55 | 68 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; |
56 | 69 |
gridBagConstraints.weightx = 1.0; |
57 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 5);
|
|
70 |
gridBagConstraints.insets = new Insets(5, 5, 2, 5); |
|
58 | 71 |
|
59 | 72 |
add(getColorSliderEdition(), gridBagConstraints); |
60 | 73 |
|
61 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
|
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(); |
|
62 | 85 |
gridBagConstraints.gridx = 0; |
63 | 86 |
gridBagConstraints.gridy = 1; |
64 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 5); |
|
65 |
add(getColorButton(), gridBagConstraints); |
|
87 |
gridBagConstraints.anchor = GridBagConstraints.EAST; |
|
88 |
gridBagConstraints.weightx = 0.5; |
|
89 |
gridBagConstraints.insets = new Insets(2, 5, 5, 2); |
|
90 |
add(jLabelColor, gridBagConstraints); |
|
66 | 91 |
} |
67 | 92 |
|
68 | 93 |
public ColorSliderEdition getColorSliderEdition() { |
... | ... | |
88 | 113 |
} |
89 | 114 |
|
90 | 115 |
public void actionSelectionChanged(ColorSliderEvent e) { |
91 |
ItemColorSlider itemColorSlider = colorSliderEdition.getSelectedItem();
|
|
116 |
ItemColorSlider itemColorSlider = getColorSliderEdition().getSelectedItem();
|
|
92 | 117 |
if ((itemColorSlider != null) && (itemColorSlider.getSelected() == 1)) { |
93 | 118 |
getColorButton().setColor(itemColorSlider.getColor()); |
94 | 119 |
getColorButton().setEnabled(true); |
120 |
jLabelColor.setEnabled(true); |
|
95 | 121 |
} else { |
96 | 122 |
getColorButton().setEnabled(false); |
123 |
jLabelColor.setEnabled(false); |
|
97 | 124 |
} |
98 | 125 |
} |
99 | 126 |
|
100 | 127 |
public void actionValueChanged(ColorSliderEvent e) { |
101 |
System.out.println("actionValueChanged(ColorSliderEvent e)");
|
|
128 |
colorTablePanel.tabInterpolatedChanged();
|
|
102 | 129 |
} |
103 | 130 |
|
104 | 131 |
public void actionValueDragged(ColorSliderEvent e) { |
132 |
colorTablePanel.tabInterpolatedChanged(); |
|
105 | 133 |
} |
106 | 134 |
|
107 | 135 |
private void callValueColorChanged() { |
108 |
ItemColorSlider itemColorSlider = colorSliderEdition.getSelectedItem();
|
|
136 |
ItemColorSlider itemColorSlider = getColorSliderEdition().getSelectedItem();
|
|
109 | 137 |
if (itemColorSlider != null) { |
110 | 138 |
itemColorSlider.setColor(getColorButton().getColor()); |
111 |
colorSliderEdition.repaint();
|
|
139 |
getColorSliderEdition().repaint();
|
|
112 | 140 |
} |
113 | 141 |
} |
114 | 142 |
|
115 | 143 |
public void actionValueDragged(ColorButtonEvent e) { |
116 | 144 |
callValueColorChanged(); |
145 |
//colorTablePanel.tabInterpolatedChanged(); |
|
117 | 146 |
} |
118 | 147 |
|
119 | 148 |
public void actionValueChanged(ColorButtonEvent e) { |
120 | 149 |
callValueColorChanged(); |
121 |
System.out.println("actionValueChanged(ColorButtonEvent e)");
|
|
150 |
colorTablePanel.tabInterpolatedChanged();
|
|
122 | 151 |
} |
123 | 152 |
|
124 | 153 |
public void initialState() { |
125 |
colorSliderEdition.repaint();
|
|
154 |
getColorSliderEdition().repaint();
|
|
126 | 155 |
getColorButton().setEnabled(false); |
127 | 156 |
} |
128 | 157 |
|
158 |
public void setLimits(double min, double max) { |
|
159 |
this.min = min; |
|
160 |
this.max = max; |
|
161 |
} |
|
162 |
|
|
129 | 163 |
/** |
130 | 164 |
* Borra todas las filas de la tabla. |
131 | 165 |
*/ |
132 | 166 |
public void clearTable() { |
133 |
colorSliderEdition.removeAllItems();
|
|
167 |
getColorSliderEdition().removeAllItems();
|
|
134 | 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 |
} |
|
135 | 213 |
} |
Also available in: Unified diff