Statistics
| Revision:

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 @ 360

History | View | Annotate | Download (7.91 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
/**
29
 * @author AI2
30
 * @version $Id$
31
 * 
32
 */
33
public class Raster3DPanel extends AbstractPanel implements ActionListener,
34
                SliderListener {
35

    
36
        private static final long serialVersionUID = 8767956294176805437L;
37

    
38
        private FLyrRaster lyr = null;
39

    
40
        public int nBands = 3;
41
        private JCheckBox cbElevation = null;
42
        private CheckSliderTextContainer elevation = null;
43
        private JComboBox bandsCombo = null;
44
        private JPanel panelRaster3D;
45

    
46
        /**
47
         * Constructor.
48
         */
49
        public Raster3DPanel() {
50
                setLabel(PluginServices.getText(this, "Raster_3D_properties"));
51
                initialize();
52
        }
53

    
54
        /**
55
         * This method initializes this
56
         * 
57
         * @return void
58
         */
59
        protected void initialize() {
60

    
61
                setPreferredSize(new Dimension(500, 400));
62

    
63
                panelRaster3D = new JPanel();
64
                panelRaster3D.setLayout(new GridBagLayout());
65

    
66
                GridBagConstraints gbc = new GridBagConstraints();
67
                gbc.fill = GridBagConstraints.HORIZONTAL;
68
                gbc.weightx = 1.0;
69
                gbc.insets = new Insets(0, 0, 0, 0);
70
                panelRaster3D.add(getElevationPanel(), gbc);
71

    
72
                gbc.fill = GridBagConstraints.NONE;
73
                gbc.weightx = 1.0;
74
                gbc.insets = new Insets(0, 0, 0, 0);
75
                panelRaster3D.add(getNumBandSelectorCombo(), gbc);
76

    
77
                this.setLayout(new BorderLayout());
78
                this.add(panelRaster3D, BorderLayout.NORTH);
79

    
80
        }
81

    
82
        /**
83
         * Asigna el n?mero de bandas de la imagen
84
         * 
85
         * @param nBands
86
         */
87
        public void setBands(int nBands) {
88
                this.nBands = nBands;
89
        }
90

    
91
        /**
92
         * Inicializa controles a sus valores por defecto
93
         */
94
        public void initControls() {
95
                this.setActiveElevationControl(isLayerElevation());
96
                this.getNumBandSelectorCombo().setEnabled(true);
97

    
98
        }
99

    
100
        /**
101
         * This method initializes jCheckBox
102
         * 
103
         * @return javax.swing.JCheckBox
104
         */
105
        public JCheckBox getElevationCheck() {
106
                if (cbElevation == null) {
107
                        cbElevation = new JCheckBox();
108
                        cbElevation.setText("Vertical_Exageration");
109
                        cbElevation.addActionListener(this);
110
                }
111

    
112
                return cbElevation;
113
        }
114

    
115
        /**
116
         * This method initializes TranspOpacitySliderPanel
117
         * 
118
         * @return javax.swing.JPanel
119
         */
120
        public CheckSliderTextContainer getElevationPanel() {
121
                if (elevation == null) {
122
                        elevation = new CheckSliderTextContainer(1, 100, 100, false,
123
                                        PluginServices.getText(this, "Vertical_Exageration"),
124
                                        false, false, true);
125
                        elevation.setDecimal(true);
126
                        elevation.setBorder(PluginServices.getText(this, "Elevation"));
127
                        elevation.addValueChangedListener(this);
128

    
129
                }
130

    
131
                return elevation;
132
        }
133

    
134
        private boolean isLayerElevation() {
135

    
136
                int i = ((MapContext3D) lyr.getMapContext()).getLayer3DProps(lyr)
137
                                .getType();
138

    
139
                if (i == Layer3DProps.layer3DElevation)
140
                        return true;
141
                else
142
                        return false;
143
        }
144

    
145
        /**
146
         * Activa/Desactiva los controles de transparencia
147
         * 
148
         * @param active
149
         */
150
        public void setActiveElevationControl(boolean active) {
151
                this.getElevationCheck().setSelected(active);
152
        }
153

    
154
        /**
155
         * Eventos sobre TextField y CheckBox. Controla eventos de checkbox de
156
         * opacidad, transparencia, recorte de colas y los textfield de opacidad,
157
         * valores de transparencia por banda y porcentaje de recorte.
158
         */
159
        public void actionPerformed(ActionEvent e) {
160
                // Evento sobre el checkbox de transparencia
161
                if (e.getSource().equals(getElevationCheck())) {
162
                        // Check de opacidad activado -> Activar controles de opacidad
163
                        if (getElevationCheck().isSelected()) {
164
                                getNumBandSelectorCombo().setEnabled(true);
165

    
166
                        } else
167
                                getNumBandSelectorCombo().setEnabled(false);
168
                }
169
        }
170

    
171
        /**
172
         * Obtiene la capa si existe esta.
173
         * 
174
         * @return FLayer si existe una capa o null si no existe.
175
         */
176
        public FLayer getLayer() {
177
                if (lyr instanceof FLayer)
178
                        return (FLayer) lyr;
179
                return null;
180
        }
181

    
182
        public void setReference(Object ref) {
183
                super.setReference(ref);
184

    
185
                if (!(ref instanceof FLyrRaster))
186
                        return;
187

    
188
                this.lyr = (FLyrRaster) ref;
189
                
190
                if(!((lyr.getMapContext()) instanceof MapContext3D)){
191
                        this.setVisible(false);
192
                        this.repaint();
193
                        return;
194
                        
195
                }
196

    
197
                actionEnabled();
198

    
199
                boolean enabled = isLayerElevation();
200
                
201
                elevation.check.setSelected(enabled);
202
                elevation.getSlider().setEnabled(enabled);
203
                elevation.getTextField().setEnabled(enabled);
204
                elevation.getSlider().setValue(
205
                                (int) ((MapContext3D) lyr.getMapContext()).getLayer3DProps(lyr)
206
                                                .getVerticalEx()-1);
207

    
208
                int numBands = lyr.getDataStore().getBandCount();
209
                String[] list = new String[numBands];
210

    
211
                for (int i = 1; i < numBands; i++)
212
                        bandsCombo.addItem(Integer.toString(i));
213
                
214
                bandsCombo.setSelectedIndex(getActiveBandElevation());
215
                
216

    
217
                
218

    
219
        }
220

    
221
        private int getActiveBandElevation() {
222
                return ((MapContext3D) lyr.getMapContext()).getLayer3DProps(lyr)
223
                                .getElevationBand();
224

    
225
        }
226

    
227
        private void actionEnabled() {
228
                if (lyr == null) {
229
                        setVisible(false);
230
                        return;
231
                }
232

    
233
        }
234

    
235
        /*
236
         * (non-Javadoc)
237
         * 
238
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
239
         */
240
        public void accept() {
241

    
242
                if (elevation.check.isSelected() /*&& !isLayerElevation()*/) {
243

    
244
                        MapContext3D mc = ((MapContext3D) getLayer().getMapContext());
245
                        Layer3DProps props = mc.getLayer3DProps(getLayer());
246
                        mc.removeLayerToTerrain(getLayer());
247
                        float value = elevation.getSlider().getValue();
248
                        props.setType(Layer3DProps.layer3DElevation);
249
                        props.setVerticalEx(value+1);
250
                        props.setElevationBand(Integer.parseInt((String) bandsCombo
251
                                        .getSelectedItem()));
252
                        mc.addLayerToTerrain(getLayer(), true);
253
                }
254

    
255
                // Elevation check and layer is elevation
256
                else if (!elevation.check.isSelected() && isLayerElevation()) {
257

    
258
                        MapContext3D mc = ((MapContext3D) getLayer().getMapContext());
259
                        Layer3DProps props = mc.getLayer3DProps(getLayer());
260
                        mc.removeLayerToTerrain(getLayer());
261
                        props.setType(Layer3DProps.layer3DImage);
262
                        props.setElevationBand(Integer.parseInt((String) bandsCombo
263
                                        .getSelectedItem()));
264
                        mc.addLayerToTerrain(getLayer(), true);
265

    
266
                }
267

    
268
        }
269

    
270
        /*
271
         * (non-Javadoc)
272
         * 
273
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
274
         */
275
        public void apply() {
276
                accept();
277
        }
278

    
279
        /*
280
         * (non-Javadoc)
281
         * 
282
         * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
283
         */
284
        public void cancel() {
285
                // getTransparencyListener().cancel();
286
        }
287

    
288
        /*
289
         * (non-Javadoc)
290
         * 
291
         * @see
292
         * org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueChanged
293
         * (org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
294
         */
295
        public void actionValueChanged(SliderEvent e) {
296

    
297
                if (e.getSource().equals(getElevationCheck())) {
298

    
299
                        if (getElevationCheck().isSelected()) {
300
                                getNumBandSelectorCombo().setEnabled(true);
301

    
302
                        } else
303
                                getNumBandSelectorCombo().setEnabled(false);
304

    
305
                }
306

    
307
        }
308

    
309
        public void actionValueDragged(SliderEvent e) {
310
        }
311

    
312
        public void selected() {
313
        }
314

    
315
        public JComboBox getNumBandSelectorCombo() {
316
                if (bandsCombo == null) {
317

    
318
                        String[] list = { "0" };
319

    
320
                        bandsCombo = new JComboBox(list);
321
                        bandsCombo.setSelectedIndex(0);
322
                        bandsCombo.setPreferredSize(new java.awt.Dimension(70, 60));
323
                        bandsCombo.setBorder(BorderFactory.createTitledBorder(
324
                                        BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
325
                                        PluginServices.getText(this, "Banda_elevacion"),
326
                                        TitledBorder.DEFAULT_JUSTIFICATION,
327
                                        TitledBorder.DEFAULT_POSITION, null, null));
328
                }
329

    
330
                return bandsCombo;
331
        }
332

    
333
}