Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / properties / layer / AbstractLayerProperties3DPanel.java @ 487

History | View | Annotate | Download (13.2 KB)

1
package org.gvsig.view3d.swing.impl.properties.layer;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Container;
6
import java.awt.Dimension;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
9
import java.awt.GridLayout;
10
import java.awt.Insets;
11
import java.util.Hashtable;
12

    
13
import javax.swing.BorderFactory;
14
import javax.swing.JComboBox;
15
import javax.swing.JComponent;
16
import javax.swing.JLabel;
17
import javax.swing.JPanel;
18
import javax.swing.JSlider;
19
import javax.swing.JTextField;
20

    
21
import org.gvsig.tools.ToolsLocator;
22
import org.gvsig.tools.i18n.I18nManager;
23
import org.gvsig.view3d.swing.api.LayerProperties3DPanel;
24

    
25
public abstract class AbstractLayerProperties3DPanel extends JPanel implements
26
    LayerProperties3DPanel {
27

    
28
    private static final long serialVersionUID = -7539636081774210233L;
29

    
30
    private Insets insets = new Insets(5, 5, 5, 5);
31

    
32
    private JPanel northPanel;
33
    private JLabel loadModeText;
34
    private JComboBox<String> loadModes;
35

    
36
    private JPanel tileConfigurationPanel;
37

    
38
    private JPanel minMaxPanel;
39
    private JLabel minimumText;
40
    private JTextField minimumField;
41
    private JLabel maximumText;
42
    private JTextField maximumField;
43

    
44
    private JPanel detailPanel;
45
    private JSlider levelDetailSlider;
46

    
47
    private JPanel tileSizePanel;
48
    private JLabel tileWidthText;
49
    private JTextField tileWidthField;
50
    private JLabel tileHeightText;
51
    private JTextField tileHeightField;
52

    
53
    private JPanel elevationPanel;
54

    
55
    private JPanel elevationConfPanel;
56
    private JLabel fieldElevationText;
57
    private JComboBox<String> fieldElevationCombo;
58
    private JLabel unitsElevationText;
59
    private JComboBox<String> unitsElevationCombo;
60
    private JLabel noDataElevationText;
61
    private JTextField noDataElevationField;
62

    
63
    public AbstractLayerProperties3DPanel() {
64
        this.setLayout(new BorderLayout());
65

    
66
        initialize();
67
    }
68

    
69
    protected void initialize() {
70
        this.add(getNorthPanel(), BorderLayout.NORTH);
71
        this.add(getTileConfigurationPanel(), BorderLayout.CENTER);
72
        this.add(getElevationPanel(), BorderLayout.SOUTH);
73
        this.setPreferredSize(new Dimension(100, 80));
74
    }
75

    
76
    protected JPanel getElevationPanel() {
77
        if (elevationPanel == null) {
78
            elevationPanel = new JPanel(new BorderLayout());
79
            I18nManager i18nManager = ToolsLocator.getI18nManager();
80
            elevationPanel.setBorder(BorderFactory.createTitledBorder(
81
                BorderFactory.createLineBorder(Color.GRAY),
82
                i18nManager.getTranslation("elevation")));
83
            elevationPanel.add(getElevationConfPanel(), BorderLayout.CENTER);
84
        }
85
        return elevationPanel;
86
    }
87

    
88
    private JPanel getElevationConfPanel() {
89
        if (elevationConfPanel == null) {
90
            elevationConfPanel = new JPanel(new GridBagLayout());
91

    
92
            GridBagConstraints cons = createGbcForm(0, 0);
93
            elevationConfPanel.add(getFieldLabel(), cons);
94
            cons = createGbcForm(1, 0);
95
            elevationConfPanel.add(getFieldComboBox(), cons);
96

    
97
            cons = createGbcForm(0, 1);
98
            elevationConfPanel.add(getUnitsLabel(), cons);
99
            cons = createGbcForm(1, 1);
100
            elevationConfPanel.add(getUnitsComboBox(), cons);
101

    
102
            cons = createGbcForm(0, 2);
103
            elevationConfPanel.add(getNoDataLabel(), cons);
104
            cons = createGbcForm(1, 2);
105
            elevationConfPanel.add(getNoDataField(), cons);
106

    
107
        }
108
        return elevationConfPanel;
109
    }
110

    
111
    protected JTextField getNoDataField() {
112
        if (noDataElevationField == null) {
113
            noDataElevationField = new JTextField();
114
        }
115
        return noDataElevationField;
116
    }
117

    
118
    private JLabel getNoDataLabel() {
119
        if (noDataElevationText == null) {
120
            I18nManager i18nManager = ToolsLocator.getI18nManager();
121
            noDataElevationText =
122
                new JLabel(i18nManager.getTranslation("nodata"));
123
        }
124
        return noDataElevationText;
125
    }
126

    
127
    protected JComboBox<String> getUnitsComboBox() {
128
        if (unitsElevationCombo == null) {
129
            I18nManager i18nManager = ToolsLocator.getI18nManager();
130
            String meters = i18nManager.getTranslation("meters");
131
            String foots = i18nManager.getTranslation("Pies");
132
            unitsElevationCombo = new JComboBox<String>();
133
            unitsElevationCombo.addItem(meters);
134
            unitsElevationCombo.addItem(foots);
135
        }
136
        return unitsElevationCombo;
137
    }
138

    
139
    private JLabel getUnitsLabel() {
140
        if (unitsElevationText == null) {
141
            I18nManager i18nManager = ToolsLocator.getI18nManager();
142
            unitsElevationText =
143
                new JLabel(i18nManager.getTranslation("units"));
144
        }
145
        return unitsElevationText;
146
    }
147

    
148
    protected JComboBox<String> getFieldComboBox() {
149
        if (fieldElevationCombo == null) {
150
            fieldElevationCombo = new JComboBox<String>();
151
        }
152
        return fieldElevationCombo;
153
    }
154

    
155
    protected JLabel getFieldLabel() {
156
        if (fieldElevationText == null) {
157
            I18nManager i18nManager = ToolsLocator.getI18nManager();
158
            fieldElevationText =
159
                new JLabel(i18nManager.getTranslation("elevation_field"));
160
        }
161
        return fieldElevationText;
162
    }
163

    
164
    private GridBagConstraints createGbcForm(int x, int y) {
165
        GridBagConstraints gbc = new GridBagConstraints();
166
        gbc.gridx = x;
167
        gbc.gridy = y;
168
        gbc.gridwidth = 1;
169
        gbc.gridheight = 1;
170

    
171
        gbc.anchor =
172
            (x == 0) ? GridBagConstraints.WEST : GridBagConstraints.EAST;
173
        gbc.fill =
174
            (x == 0) ? GridBagConstraints.BOTH : GridBagConstraints.HORIZONTAL;
175

    
176
        // gbc.insets = (x == 0) ? new Insets(top, left, bottom, right) :
177
        // EAST_INSETS;
178
        gbc.insets = insets;
179
        gbc.weightx = (x == 0) ? 0.1 : 1.0;
180
        gbc.weighty = 1.0;
181
        return gbc;
182
    }
183

    
184
    private JPanel getNorthPanel() {
185
        if (northPanel == null) {
186
            northPanel = new JPanel(new GridBagLayout());
187

    
188
            GridBagConstraints cons = new GridBagConstraints();
189
            cons.gridx = 0;
190
            cons.gridy = 0;
191
            cons.weightx = 0;
192
            cons.weighty = 1;
193
            cons.gridwidth = 1;
194
            cons.gridheight = 1;
195
            cons.fill = GridBagConstraints.NONE;
196
            cons.anchor = GridBagConstraints.WEST;
197
            cons.insets = insets;
198

    
199
            northPanel.add(getLoadModeLabel(), cons);
200

    
201
            cons = new GridBagConstraints();
202
            cons.gridx = 1;
203
            cons.gridy = 0;
204
            cons.weightx = 1;
205
            cons.weighty = 1;
206
            cons.gridwidth = 3;
207
            cons.gridheight = 1;
208
            cons.insets = insets;
209
            cons.fill = GridBagConstraints.NONE;
210
            cons.anchor = GridBagConstraints.WEST;
211

    
212
            northPanel.add(getLoadModesComboBox(), cons);
213
        }
214
        return northPanel;
215
    }
216

    
217
    private JPanel getTileConfigurationPanel() {
218
        if (tileConfigurationPanel == null) {
219

    
220
            I18nManager i18nManager = ToolsLocator.getI18nManager();
221

    
222
            tileConfigurationPanel = new JPanel(new GridLayout(3, 1));
223
            tileConfigurationPanel.setBorder(BorderFactory.createTitledBorder(
224
                BorderFactory.createLineBorder(Color.GRAY),
225
                i18nManager.getTranslation("tile_configuration")));
226

    
227
            tileConfigurationPanel.add(getMinMaxPanel());
228

    
229
            tileConfigurationPanel.add(getDetailPanel());
230

    
231
            tileConfigurationPanel.add(getTileSizePanel());
232

    
233
        }
234
        return tileConfigurationPanel;
235
    }
236

    
237
    private JPanel getMinMaxPanel() {
238
        if (minMaxPanel == null) {
239
            minMaxPanel = new JPanel(new GridBagLayout());
240
            I18nManager i18nManager = ToolsLocator.getI18nManager();
241
            minMaxPanel.setBorder(BorderFactory.createTitledBorder(
242
                BorderFactory.createLineBorder(Color.GRAY),
243
                i18nManager.getTranslation("level_details")));
244

    
245
            minMaxPanel.add(getMinLabel(), createGbcForm(0, 0));
246
            minMaxPanel.add(getMinTextField(), createGbcForm(1, 0));
247
            minMaxPanel.add(getMaxLabel(), createGbcForm(0, 1));
248
            minMaxPanel.add(getMaxTextField(), createGbcForm(1, 1));
249
        }
250
        return minMaxPanel;
251
    }
252

    
253
    protected JTextField getMaxTextField() {
254
        if (maximumField == null) {
255
            maximumField = new JTextField();
256
        }
257
        return maximumField;
258
    }
259

    
260
    private JLabel getMaxLabel() {
261
        if (maximumText == null) {
262
            I18nManager i18nManager = ToolsLocator.getI18nManager();
263
            maximumText = new JLabel(i18nManager.getTranslation("Maximum"));
264
        }
265
        return maximumText;
266
    }
267

    
268
    protected JTextField getMinTextField() {
269
        if (minimumField == null) {
270
            minimumField = new JTextField();
271
        }
272
        return minimumField;
273
    }
274

    
275
    private JLabel getMinLabel() {
276
        if (minimumText == null) {
277
            I18nManager i18nManager = ToolsLocator.getI18nManager();
278
            minimumText = new JLabel(i18nManager.getTranslation("Minimum"));
279
        }
280
        return minimumText;
281
    }
282

    
283
    private JPanel getDetailPanel() {
284
        if (detailPanel == null) {
285
            I18nManager i18nManager = ToolsLocator.getI18nManager();
286
            detailPanel = new JPanel(new GridBagLayout());
287
            detailPanel.setBorder(BorderFactory.createTitledBorder(
288
                BorderFactory.createLineBorder(Color.GRAY),
289
                i18nManager.getTranslation("zero_level_resolution")));
290

    
291
            GridBagConstraints cons = new GridBagConstraints();
292
            cons.gridx = 0;
293
            cons.gridy = 0;
294
            cons.weightx = 1;
295
            cons.weighty = 1;
296
            cons.gridwidth = 1;
297
            cons.gridheight = 1;
298
            cons.fill = GridBagConstraints.BOTH;
299
            cons.anchor = GridBagConstraints.CENTER;
300
            cons.insets = insets;
301
            detailPanel.add(getLevelZeroSlider(), cons);
302
        }
303
        return detailPanel;
304
    }
305

    
306
    @SuppressWarnings({ "unchecked", "rawtypes" })
307
    protected JSlider getLevelZeroSlider() {
308
        if (levelDetailSlider == null) {
309
            levelDetailSlider = new JSlider(JSlider.HORIZONTAL, 0, 10, 5);
310

    
311
            // Create the label table
312
            Hashtable labelTable = new Hashtable();
313
            I18nManager i18nManager = ToolsLocator.getI18nManager();
314
            labelTable.put(new Integer(0),
315
                new JLabel(i18nManager.getTranslation("low")));
316
            labelTable.put(new Integer(10),
317
                new JLabel(i18nManager.getTranslation("high")));
318
            levelDetailSlider.setLabelTable(labelTable);
319
            levelDetailSlider.setPaintLabels(true);
320
            levelDetailSlider.setMajorTickSpacing(1);
321
            levelDetailSlider.setPaintTicks(true);
322
        }
323
        return levelDetailSlider;
324
    }
325

    
326
    private JPanel getTileSizePanel() {
327
        if (tileSizePanel == null) {
328
            tileSizePanel = new JPanel(new GridBagLayout());
329
            I18nManager i18nManager = ToolsLocator.getI18nManager();
330
            tileSizePanel.setBorder(BorderFactory.createTitledBorder(
331
                BorderFactory.createLineBorder(Color.GRAY),
332
                i18nManager.getTranslation("tilesize")));
333

    
334
            tileSizePanel.add(getHeightLabel(), createGbcForm(0, 0));
335
            tileSizePanel.add(getHeightField(), createGbcForm(1, 0));
336
            tileSizePanel.add(getWidthLabel(), createGbcForm(0, 1));
337
            tileSizePanel.add(getWidthField(), createGbcForm(1, 1));
338
        }
339
        return tileSizePanel;
340
    }
341

    
342
    protected JTextField getWidthField() {
343
        if (tileWidthField == null) {
344
            tileWidthField = new JTextField();
345
        }
346
        return tileWidthField;
347
    }
348

    
349
    private JLabel getWidthLabel() {
350
        if (tileWidthText == null) {
351
            I18nManager i18nManager = ToolsLocator.getI18nManager();
352
            tileWidthText = new JLabel(i18nManager.getTranslation("width"));
353
        }
354
        return tileWidthText;
355
    }
356

    
357
    protected JTextField getHeightField() {
358
        if (tileHeightField == null) {
359
            tileHeightField = new JTextField();
360
        }
361
        return tileHeightField;
362
    }
363

    
364
    private JLabel getHeightLabel() {
365
        if (tileHeightText == null) {
366
            I18nManager i18nManager = ToolsLocator.getI18nManager();
367
            tileHeightText = new JLabel(i18nManager.getTranslation("height"));
368
        }
369
        return tileHeightText;
370
    }
371

    
372
    private JLabel getLoadModeLabel() {
373
        if (loadModeText == null) {
374
            I18nManager i18nManager = ToolsLocator.getI18nManager();
375
            loadModeText = new JLabel(i18nManager.getTranslation("load_mode"));
376
        }
377
        return loadModeText;
378
    }
379

    
380
    protected JComboBox<String> getLoadModesComboBox() {
381
        if (loadModes == null) {
382
            loadModes = new JComboBox<String>();
383
        }
384
        return loadModes;
385
    }
386

    
387
    public void enableComponents(Container container, boolean enable) {
388
        java.awt.Component[] components = container.getComponents();
389
        for (java.awt.Component component : components) {
390
            component.setEnabled(enable);
391
            if (component instanceof Container) {
392
                enableComponents((Container) component, enable);
393
            }
394
        }
395
    }
396

    
397
    public JComponent asJComponent() {
398
        return this;
399
    }
400
}