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