gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / gui / panels / Raster3DPanel.java @ 318
History | View | Annotate | Download (7.73 KB)
1 |
package org.gvsig.gvsig3d.app.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.Insets; |
8 |
import java.awt.event.ActionEvent; |
9 |
import java.awt.event.ActionListener; |
10 |
|
11 |
import javax.swing.BorderFactory; |
12 |
import javax.swing.JCheckBox; |
13 |
import javax.swing.JComboBox; |
14 |
import javax.swing.JPanel; |
15 |
import javax.swing.border.EtchedBorder; |
16 |
import javax.swing.border.TitledBorder; |
17 |
|
18 |
import org.gvsig.andami.PluginServices; |
19 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
20 |
import org.gvsig.gui.beans.checkslidertext.CheckSliderTextContainer; |
21 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
22 |
import org.gvsig.gui.beans.slidertext.listeners.SliderEvent; |
23 |
import org.gvsig.gui.beans.slidertext.listeners.SliderListener; |
24 |
import org.gvsig.gvsig3d.map3d.Layer3DProps; |
25 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
26 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
27 |
|
28 |
public class Raster3DPanel extends AbstractPanel implements ActionListener, |
29 |
SliderListener { |
30 |
|
31 |
private static final long serialVersionUID = 8767956294176805437L; |
32 |
|
33 |
private FLyrRaster lyr = null; |
34 |
|
35 |
public int nBands = 3; |
36 |
private JCheckBox cbElevation = null; |
37 |
private CheckSliderTextContainer elevation = null; |
38 |
private JComboBox bandsCombo = null; |
39 |
private JPanel panelRaster3D; |
40 |
|
41 |
/**
|
42 |
* Constructor.
|
43 |
*/
|
44 |
public Raster3DPanel() {
|
45 |
setLabel(PluginServices.getText(this, "Raster_3D_properties")); |
46 |
initialize(); |
47 |
} |
48 |
|
49 |
/**
|
50 |
* This method initializes this
|
51 |
*
|
52 |
* @return void
|
53 |
*/
|
54 |
protected void initialize() { |
55 |
|
56 |
setPreferredSize(new Dimension(500, 400)); |
57 |
|
58 |
panelRaster3D = new JPanel(); |
59 |
panelRaster3D.setLayout(new GridBagLayout()); |
60 |
|
61 |
GridBagConstraints gbc = new GridBagConstraints(); |
62 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
63 |
gbc.weightx = 1.0;
|
64 |
gbc.insets = new Insets(0, 0, 0, 0); |
65 |
panelRaster3D.add(getElevationPanel(), gbc); |
66 |
|
67 |
gbc.fill = GridBagConstraints.NONE;
|
68 |
gbc.weightx = 1.0;
|
69 |
gbc.insets = new Insets(0, 0, 0, 0); |
70 |
panelRaster3D.add(getNumBandSelectorCombo(), gbc); |
71 |
|
72 |
this.setLayout(new BorderLayout()); |
73 |
this.add(panelRaster3D, BorderLayout.NORTH); |
74 |
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* Asigna el n?mero de bandas de la imagen
|
79 |
*
|
80 |
* @param nBands
|
81 |
*/
|
82 |
public void setBands(int nBands) { |
83 |
this.nBands = nBands;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* Inicializa controles a sus valores por defecto
|
88 |
*/
|
89 |
public void initControls() { |
90 |
this.setActiveElevationControl(isLayerElevation());
|
91 |
this.getNumBandSelectorCombo().setEnabled(true); |
92 |
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* This method initializes jCheckBox
|
97 |
*
|
98 |
* @return javax.swing.JCheckBox
|
99 |
*/
|
100 |
public JCheckBox getElevationCheck() { |
101 |
if (cbElevation == null) { |
102 |
cbElevation = new JCheckBox(); |
103 |
cbElevation.setText("Vertical_Exageration");
|
104 |
cbElevation.addActionListener(this);
|
105 |
} |
106 |
|
107 |
return cbElevation;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* This method initializes TranspOpacitySliderPanel
|
112 |
*
|
113 |
* @return javax.swing.JPanel
|
114 |
*/
|
115 |
public CheckSliderTextContainer getElevationPanel() {
|
116 |
if (elevation == null) { |
117 |
elevation = new CheckSliderTextContainer(1, 100, 100, false, |
118 |
PluginServices.getText(this, "Vertical_Exageration"), |
119 |
false, false, true); |
120 |
elevation.setDecimal(true);
|
121 |
elevation.setBorder(PluginServices.getText(this, "Elevation")); |
122 |
elevation.addValueChangedListener(this);
|
123 |
|
124 |
} |
125 |
|
126 |
return elevation;
|
127 |
} |
128 |
|
129 |
private boolean isLayerElevation() { |
130 |
|
131 |
int i = ((MapContext3D) lyr.getMapContext()).getLayer3DProps(lyr)
|
132 |
.getType(); |
133 |
|
134 |
if (i == Layer3DProps.layer3DElevation)
|
135 |
return true; |
136 |
else
|
137 |
return false; |
138 |
} |
139 |
|
140 |
/**
|
141 |
* Activa/Desactiva los controles de transparencia
|
142 |
*
|
143 |
* @param active
|
144 |
*/
|
145 |
public void setActiveElevationControl(boolean active) { |
146 |
this.getElevationCheck().setSelected(active);
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Eventos sobre TextField y CheckBox. Controla eventos de checkbox de
|
151 |
* opacidad, transparencia, recorte de colas y los textfield de opacidad,
|
152 |
* valores de transparencia por banda y porcentaje de recorte.
|
153 |
*/
|
154 |
public void actionPerformed(ActionEvent e) { |
155 |
// Evento sobre el checkbox de transparencia
|
156 |
if (e.getSource().equals(getElevationCheck())) {
|
157 |
// Check de opacidad activado -> Activar controles de opacidad
|
158 |
if (getElevationCheck().isSelected()) {
|
159 |
getNumBandSelectorCombo().setEnabled(true);
|
160 |
|
161 |
} else
|
162 |
getNumBandSelectorCombo().setEnabled(false);
|
163 |
} |
164 |
} |
165 |
|
166 |
/**
|
167 |
* Obtiene la capa si existe esta.
|
168 |
*
|
169 |
* @return FLayer si existe una capa o null si no existe.
|
170 |
*/
|
171 |
public FLayer getLayer() {
|
172 |
if (lyr instanceof FLayer) |
173 |
return (FLayer) lyr;
|
174 |
return null; |
175 |
} |
176 |
|
177 |
public void setReference(Object ref) { |
178 |
super.setReference(ref);
|
179 |
|
180 |
if (!(ref instanceof FLyrRaster)) |
181 |
return;
|
182 |
|
183 |
this.lyr = (FLyrRaster) ref;
|
184 |
|
185 |
actionEnabled(); |
186 |
|
187 |
boolean enabled = isLayerElevation();
|
188 |
|
189 |
elevation.check.setSelected(enabled); |
190 |
elevation.getSlider().setEnabled(enabled); |
191 |
elevation.getTextField().setEnabled(enabled); |
192 |
elevation.getSlider().setValue( |
193 |
(int) ((MapContext3D) lyr.getMapContext()).getLayer3DProps(lyr)
|
194 |
.getVerticalEx()-1);
|
195 |
|
196 |
int numBands = lyr.getDataStore().getBandCount();
|
197 |
String[] list = new String[numBands]; |
198 |
|
199 |
for (int i = 1; i < numBands; i++) |
200 |
bandsCombo.addItem(Integer.toString(i));
|
201 |
|
202 |
bandsCombo.setSelectedIndex(getActiveBandElevation()); |
203 |
|
204 |
} |
205 |
|
206 |
private int getActiveBandElevation() { |
207 |
return ((MapContext3D) lyr.getMapContext()).getLayer3DProps(lyr)
|
208 |
.getElevationBand(); |
209 |
|
210 |
} |
211 |
|
212 |
private void actionEnabled() { |
213 |
if (lyr == null) { |
214 |
setVisible(false);
|
215 |
return;
|
216 |
} |
217 |
|
218 |
} |
219 |
|
220 |
/*
|
221 |
* (non-Javadoc)
|
222 |
*
|
223 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
|
224 |
*/
|
225 |
public void accept() { |
226 |
|
227 |
if (elevation.check.isSelected() /*&& !isLayerElevation()*/) { |
228 |
|
229 |
MapContext3D mc = ((MapContext3D) getLayer().getMapContext()); |
230 |
Layer3DProps props = mc.getLayer3DProps(getLayer()); |
231 |
mc.removeLayerToTerrain(getLayer()); |
232 |
float value = elevation.getSlider().getValue();
|
233 |
props.setType(Layer3DProps.layer3DElevation); |
234 |
props.setVerticalEx(value+1);
|
235 |
props.setElevationBand(Integer.parseInt((String) bandsCombo |
236 |
.getSelectedItem())); |
237 |
mc.addLayerToTerrain(getLayer(), true);
|
238 |
} |
239 |
|
240 |
// Elevation check and layer is elevation
|
241 |
else if (!elevation.check.isSelected() && isLayerElevation()) { |
242 |
|
243 |
MapContext3D mc = ((MapContext3D) getLayer().getMapContext()); |
244 |
Layer3DProps props = mc.getLayer3DProps(getLayer()); |
245 |
mc.removeLayerToTerrain(getLayer()); |
246 |
props.setType(Layer3DProps.layer3DImage); |
247 |
props.setElevationBand(Integer.parseInt((String) bandsCombo |
248 |
.getSelectedItem())); |
249 |
mc.addLayerToTerrain(getLayer(), true);
|
250 |
|
251 |
} |
252 |
|
253 |
} |
254 |
|
255 |
/*
|
256 |
* (non-Javadoc)
|
257 |
*
|
258 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
|
259 |
*/
|
260 |
public void apply() { |
261 |
accept(); |
262 |
} |
263 |
|
264 |
/*
|
265 |
* (non-Javadoc)
|
266 |
*
|
267 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
|
268 |
*/
|
269 |
public void cancel() { |
270 |
// getTransparencyListener().cancel();
|
271 |
} |
272 |
|
273 |
/*
|
274 |
* (non-Javadoc)
|
275 |
*
|
276 |
* @see
|
277 |
* org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueChanged
|
278 |
* (org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
|
279 |
*/
|
280 |
public void actionValueChanged(SliderEvent e) { |
281 |
|
282 |
if (e.getSource().equals(getElevationCheck())) {
|
283 |
|
284 |
if (getElevationCheck().isSelected()) {
|
285 |
getNumBandSelectorCombo().setEnabled(true);
|
286 |
|
287 |
} else
|
288 |
getNumBandSelectorCombo().setEnabled(false);
|
289 |
|
290 |
} |
291 |
|
292 |
} |
293 |
|
294 |
public void actionValueDragged(SliderEvent e) { |
295 |
} |
296 |
|
297 |
public void selected() { |
298 |
} |
299 |
|
300 |
public JComboBox getNumBandSelectorCombo() { |
301 |
if (bandsCombo == null) { |
302 |
|
303 |
String[] list = { "0" }; |
304 |
|
305 |
bandsCombo = new JComboBox(list); |
306 |
bandsCombo.setSelectedIndex(0);
|
307 |
bandsCombo.setPreferredSize(new java.awt.Dimension(70, 60)); |
308 |
bandsCombo.setBorder(BorderFactory.createTitledBorder(
|
309 |
BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), |
310 |
PluginServices.getText(this, "Banda_elevacion"), |
311 |
TitledBorder.DEFAULT_JUSTIFICATION,
|
312 |
TitledBorder.DEFAULT_POSITION, null, null)); |
313 |
} |
314 |
|
315 |
return bandsCombo;
|
316 |
} |
317 |
|
318 |
} |