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 / Vectorial3DPanel.java @ 311

History | View | Annotate | Download (6.26 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.ItemEvent;
9
import java.awt.event.ItemListener;
10

    
11
import javax.media.jai.widget.ViewportListener;
12
import javax.swing.JCheckBox;
13
import javax.swing.JPanel;
14
import javax.swing.border.TitledBorder;
15

    
16
import org.gvsig.andami.PluginServices;
17
import org.gvsig.fmap.mapcontext.layers.FLayer;
18
import org.gvsig.gui.beans.datainput.DataInputContainer;
19
import org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel;
20
import org.gvsig.gvsig3d.app.listener.Vectorial3DListener;
21
import org.gvsig.gvsig3d.map3d.Layer3DProps;
22
import org.gvsig.gvsig3d.map3d.MapContext3D;
23
import org.slf4j.LoggerFactory;
24

    
25
/**
26
 * 
27
 * @author AI2
28
 * 
29
 */
30
public class Vectorial3DPanel extends TabbedPanel implements ItemListener {
31

    
32
        private static final long serialVersionUID = -7534090067774408100L;
33

    
34
        private JPanel panelOptionsGlob;
35
        private JPanel panelOptionsRast;
36
        private JCheckBox rasterOption;
37
        private JCheckBox zOption;
38
        private Layer3DProps props3D;
39
        private TitledBorder borderOptionsRast;
40
        private DataInputContainer textFieldHeigth;
41
        private Vectorial3DListener vListener3D;
42

    
43
        final static private org.slf4j.Logger logger = LoggerFactory
44
                        .getLogger(Vectorial3DPanel.class);
45

    
46
        final int defaultElevation = 100; // default layer elevation
47

    
48
        public Vectorial3DPanel(Object reference) {
49
                super(reference);
50
                initialize();
51
                setLayer3DProps((FLayer) reference);
52
                updatePanel();
53
        }
54

    
55
        private void setLayer3DProps(FLayer layer) {
56

    
57
                props3D = ((MapContext3D) layer.getMapContext()).getLayer3DProps(layer);
58

    
59
        }
60

    
61
        protected void initialize() {
62
                super.initialize();
63
                setName(PluginServices.getText(this,
64
                                PluginServices.getText(this, "Capa_Vectorial")));
65

    
66
                setPreferredSize(new Dimension(500, 400));
67

    
68
                panelOptionsGlob = new JPanel();
69
                panelOptionsGlob.setLayout(new GridBagLayout());
70

    
71
                GridBagConstraints gbc = new GridBagConstraints();
72
                gbc.fill = GridBagConstraints.HORIZONTAL;
73
                gbc.weightx = 1.0;
74
                gbc.insets = new Insets(0, 0, 0, 0);
75
                panelOptionsGlob.add(panelVector(), gbc);
76

    
77
                this.setLayout(new BorderLayout());
78
                this.add(panelOptionsGlob, BorderLayout.NORTH);
79
                
80
                getVectorialLayerListener3D();
81
        }
82

    
83
        private JPanel panelVector() {
84

    
85
                if (panelOptionsRast == null) {
86
                        panelOptionsRast = new JPanel();
87
                        borderOptionsRast = new TitledBorder(PluginServices.getText(this,
88
                                        "Opciones_dibujado"));
89
                        panelOptionsRast.setLayout(new GridBagLayout());
90
                        panelOptionsRast.setBorder(this.borderOptionsRast);
91

    
92
                        GridBagConstraints gbc = new GridBagConstraints();
93
                        gbc.fill = GridBagConstraints.HORIZONTAL;
94
                        gbc.weightx = 1;
95
                        gbc.insets = new Insets(0, 0, 10, 0);
96
                        panelOptionsRast.add(getJCheckBoxRaster(), gbc);
97

    
98
                        gbc = new GridBagConstraints();
99
                        gbc.fill = GridBagConstraints.HORIZONTAL;
100
                        gbc.gridy = 1;
101
                        gbc.insets = new Insets(0, 0, 10, 0);
102
                        panelOptionsRast.add(getJCheckBoxValueZ(), gbc);
103

    
104
                        gbc = new GridBagConstraints();
105
                        gbc.fill = GridBagConstraints.NONE;
106
                        gbc.anchor = GridBagConstraints.WEST;
107
                        gbc.gridy = 2;
108
                        panelOptionsRast.add(getLabelText(), gbc);
109

    
110
                        gbc = new GridBagConstraints();
111
                        gbc.weighty = 1.0;
112
                        gbc.gridy = 3;
113
                        panelOptionsRast.add(new JPanel(), gbc);
114
                }
115
                return panelOptionsRast;
116
        }
117

    
118
        private DataInputContainer getLabelText() {
119
                if (textFieldHeigth == null) {
120
                        textFieldHeigth = new DataInputContainer();
121
                        textFieldHeigth.setLabelText(PluginServices.getText(this,
122
                                        "Altura_en_metros"));
123
                        textFieldHeigth.setValue(this.getMyHeight());
124
                }
125

    
126
                return textFieldHeigth;
127
        }
128

    
129
        private JCheckBox getJCheckBoxRaster() {
130
                if (rasterOption == null) {
131
                        rasterOption = new JCheckBox(PluginServices.getText(this,
132
                                        "Raster_layer"), false);
133
                        rasterOption.addItemListener(this);
134
                }
135
                return rasterOption;
136
        }
137

    
138
        private JCheckBox getJCheckBoxValueZ() {
139
                if (zOption == null) {
140
                        zOption = new JCheckBox(PluginServices.getText(this, "Heigth_Z"),
141
                                        false);
142
                        zOption.addItemListener(this);
143
                }
144
                return zOption;
145
        }
146

    
147
        public void selected() {
148

    
149
        }
150

    
151
        public void itemStateChanged(ItemEvent e) {
152

    
153
                zOption.setEnabled(!rasterOption.isSelected());
154
                rasterOption.setEnabled(!zOption.isSelected());
155
                textFieldHeigth.setControlEnabled(!(zOption.isSelected())
156
                                && !(rasterOption.isSelected()));
157

    
158
        }
159

    
160
        private Vectorial3DListener getVectorialLayerListener3D() {
161
                if (vListener3D == null) {
162
                        vListener3D = new Vectorial3DListener(this);
163
                        
164
                }
165
                return vListener3D;
166
        }
167

    
168
        public void accept() {
169
                getVectorialLayerListener3D().accept();
170
        }
171

    
172
        public void apply() {
173
                getVectorialLayerListener3D().apply();
174
        }
175

    
176
        public void cancel() {
177
                getVectorialLayerListener3D().cancel();
178
        }
179

    
180
        public boolean isRasterOptionSelected() {
181
                return getJCheckBoxRaster().isSelected();
182
        }
183

    
184
        public boolean isZValueSelected() {
185
                return getJCheckBoxValueZ().isSelected();
186
        }
187

    
188
        public String getJTextFieldHeight() {
189
                return textFieldHeigth.getValue();
190
        }
191

    
192
        public Layer3DProps getLayer3DProps() {
193
                return props3D;
194
        }
195

    
196
        public MapContext3D getMapContext() {
197
                FLayer fl = (FLayer) this.getReference();
198
                MapContext3D mc = (MapContext3D) fl.getMapContext();
199
                return mc;
200
        }
201

    
202
        public FLayer getLayer() {
203
                return (FLayer) this.getReference();
204
        }
205

    
206
        public String getMyHeight() {
207
                String elevation = "0";// default value
208

    
209
                if (props3D != null)
210
                        try {
211
                                float alt = props3D.getHeight();
212
                                elevation = Float.toString(alt);
213
                        } catch (Exception e) {
214
                                logger.error("Command: "
215
                                                + "Error getting layer elevation value.", e);
216
                        }
217
                return elevation;
218
        }
219

    
220
        public double getHeightLayer() {
221
                return props3D.getHeight();
222
        }
223

    
224
        public int getDefaultElevation() {
225
                return defaultElevation;
226
        }
227

    
228
        protected void updatePanel() {
229
                textFieldHeigth.setValue(this.getMyHeight());
230
                configureControls();
231
        }
232

    
233
        /*
234
         * Enabled options depending the Layer3DProps, and the context MapContext
235
         */
236
        private void configureControls() {
237
                if (props3D.getType() == Layer3DProps.layer3DImage) {
238

    
239
                        textFieldHeigth.setControlEnabled(false);
240
                        rasterOption.setSelected(true);
241
                        rasterOption.setEnabled(true);
242
                        zOption.setEnabled(false);
243

    
244
                }
245
                else if (props3D.getType() == Layer3DProps.layer3DVector){
246
                        
247
                        textFieldHeigth.setControlEnabled(true);
248
                        rasterOption.setSelected(false);
249
                        rasterOption.setEnabled(true);
250
                        zOption.setEnabled(true);
251
                        
252
                }
253

    
254
        }
255

    
256
}