Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / raw / ui / main / GeometryPropertiesLeftPanel.java @ 2480

History | View | Annotate | Download (11.6 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.basic.tool.raw.ui.main;
23

    
24
import java.awt.Dimension;
25
import java.awt.FlowLayout;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.text.NumberFormat;
29

    
30
import javax.swing.JFormattedTextField;
31
import javax.swing.JLabel;
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.utils.StringUtilities;
36

    
37
/**
38
 * This panel contains the left panel of the "Set Geometry" panel. It is the
39
 * imput to write the image width, the heigth, the number of bands and the image
40
 * header size.
41
 * 
42
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
43
 */
44
public class GeometryPropertiesLeftPanel extends JPanel {
45
  private static final long serialVersionUID = 1254390565246946002L;
46
        private JPanel              bandsLabelPanel      = null;
47
        private JPanel              headerSizeLabelPanel = null;
48
        private JPanel              heigthLabelPanel     = null;
49
        private JLabel              heigthLabel          = null;
50
        private JPanel              labelsPanel          = null;
51
        private JPanel              fieldsPanel          = null;
52
        private JPanel              widthTextPanel       = null;
53
        private JPanel              heigthTextPanel      = null;
54
        private JPanel              widthLabelPanel      = null;
55
        private JLabel              widthLabel           = null;
56
        private JLabel              bandsLabel           = null;
57
        private JPanel              bandsTextPanel       = null;
58
        private JPanel              headerSizeTextPanel  = null;
59
        private JFormattedTextField widthText            = null;
60
        private JLabel              headerSizeLabel      = null;
61
        private JFormattedTextField heigthText           = null;
62
        private JFormattedTextField bandsText            = null;
63
        private JFormattedTextField headerSizeText       = null;
64

    
65
        private final int           WIDTH                = 245;
66
        private final int           HEIGHT               = 110;
67
        private final int           LABELS_PANEL_WIDTH   = 120;
68
        private final int           TEXTS_PANEL_WIDTH    = 125;
69
        private final int           LABELS_WIDTH         = 120;
70
        private final int           LABELS_HEIGHT        = 19;
71
        private final int           TEXTS_WIDTH          = 120;
72
        private final int           TEXTS_HEIGHT         = 19;
73
        
74
        /**
75
         * This is the default constructor
76
         */
77
        public GeometryPropertiesLeftPanel() {
78
                super();
79
                initialize();
80
        }
81

    
82
        /**
83
         * This method initializes this
84
         * @return void
85
         */
86
        private void initialize() {
87
                this.setLayout(new GridBagLayout());
88
                this.setPreferredSize(new java.awt.Dimension(WIDTH, HEIGHT));
89
                this.add(getLabelsPanel(), new GridBagConstraints());
90
                this.add(getFieldsPanel(), new GridBagConstraints());
91
        }
92

    
93
        /**
94
         * This method initializes pX
95
         * @return javax.swing.JPanel
96
         */
97
        private JPanel getBandsLabelPanel() {
98
                if (bandsLabelPanel == null) {
99
                        bandsLabel = new JLabel();
100
                        bandsLabel.setText(PluginServices.getText(this, "bands_number"));
101
                        FlowLayout flowLayout2 = new FlowLayout();
102
                        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
103
                        bandsLabelPanel = new JPanel();
104
                        bandsLabelPanel.setLayout(flowLayout2);
105
                        bandsLabelPanel.setPreferredSize(new java.awt.Dimension(LABELS_WIDTH, LABELS_HEIGHT));
106
                        bandsLabelPanel.add(bandsLabel, null);
107
                        flowLayout2.setVgap(1);
108
                        flowLayout2.setHgap(0);
109
                }
110
                return bandsLabelPanel;
111
        }
112

    
113
        /**
114
         * This method initializes pY
115
         * @return javax.swing.JPanel
116
         */
117
        private JPanel getHeaderSizeLabelPanel() {
118
                if (headerSizeLabelPanel == null) {
119
                        headerSizeLabel = new JLabel();
120
                        headerSizeLabel.setText(PluginServices.getText(this, "header_Size"));
121
                        FlowLayout flowLayout1 = new FlowLayout();
122
                        flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
123
                        headerSizeLabelPanel = new JPanel();
124
                        headerSizeLabelPanel.setLayout(flowLayout1);
125
                        headerSizeLabelPanel.setPreferredSize(new java.awt.Dimension(LABELS_WIDTH, LABELS_HEIGHT));
126
                        headerSizeLabelPanel.add(headerSizeLabel, null);
127
                        flowLayout1.setHgap(0);
128
                        flowLayout1.setVgap(1);
129
                }
130
                return headerSizeLabelPanel;
131
        }
132

    
133
        /**
134
         * This method initializes pLatitud
135
         * @return javax.swing.JPanel
136
         */
137
        private JPanel getHeigthLabelPanel() {
138
                if (heigthLabelPanel == null) {
139
                        heigthLabel = new JLabel();
140
                        heigthLabel.setText(PluginServices.getText(this, "alto"));
141
                        FlowLayout flowLayout3 = new FlowLayout();
142
                        flowLayout3.setAlignment(java.awt.FlowLayout.LEFT);
143
                        heigthLabelPanel = new JPanel();
144
                        heigthLabelPanel.setLayout(flowLayout3);
145
                        heigthLabelPanel.setPreferredSize(new java.awt.Dimension(LABELS_WIDTH, LABELS_HEIGHT));
146
                        flowLayout3.setHgap(0);
147
                        flowLayout3.setVgap(1);
148
                        heigthLabelPanel.add(heigthLabel, null);
149
                }
150
                return heigthLabelPanel;
151
        }
152

    
153
        /**
154
         * This method initializes jPanel3
155
         * @return javax.swing.JPanel
156
         */
157
        private JPanel getWidthLabelPanel() {
158
                if (widthLabelPanel == null) {
159
                        widthLabel = new JLabel();
160
                        widthLabel.setText(PluginServices.getText(this, "ancho"));
161
                        FlowLayout flowLayout4 = new FlowLayout();
162
                        flowLayout4.setHgap(0);
163
                        flowLayout4.setAlignment(java.awt.FlowLayout.LEFT);
164
                        flowLayout4.setVgap(1);
165
                        widthLabelPanel = new JPanel();
166
                        widthLabelPanel.setPreferredSize(new java.awt.Dimension(LABELS_WIDTH, LABELS_HEIGHT));
167
                        widthLabelPanel.setLayout(flowLayout4);
168
                        widthLabelPanel.add(widthLabel, null);
169
                }
170
                return widthLabelPanel;
171
        }
172

    
173
        /**
174
         * This method initializes jPanel
175
         * @return javax.swing.JPanel
176
         */
177
        private JPanel getLabelsPanel() {
178
                if (labelsPanel == null) {
179
                        labelsPanel = new JPanel();
180
                        labelsPanel.setPreferredSize(new java.awt.Dimension(LABELS_PANEL_WIDTH, HEIGHT));
181
                        labelsPanel.add(getWidthLabelPanel(), null);
182
                        labelsPanel.add(getHeigthLabelPanel(), null);
183
                        labelsPanel.add(getBandsLabelPanel(), null);
184
                        labelsPanel.add(getHeaderSizeLabelPanel(), null);
185
                }
186
                return labelsPanel;
187
        }
188

    
189
        /**
190
         * This method initializes jPanel
191
         * @return javax.swing.JPanel
192
         */
193
        private JPanel getFieldsPanel() {
194
                if (fieldsPanel == null) {
195
                        fieldsPanel = new JPanel();
196
                        fieldsPanel.setPreferredSize(new java.awt.Dimension(TEXTS_PANEL_WIDTH, HEIGHT));
197
                        fieldsPanel.add(getWidthTextPanel(), null);
198
                        fieldsPanel.add(getHeigthTextPanel(), null);
199
                        fieldsPanel.add(getBandsTextPanel(), null);
200
                        fieldsPanel.add(getHeaderSizeTextPanel(), null);
201
                }
202
                return fieldsPanel;
203
        }
204

    
205
        /**
206
         * This method initializes jPanel
207
         * @return javax.swing.JPanel
208
         */
209
        private JPanel getWidthTextPanel() {
210
                if (widthTextPanel == null) {
211
                        FlowLayout flowLayout = new FlowLayout();
212
                        flowLayout.setHgap(0);
213
                        flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
214
                        flowLayout.setVgap(1);
215
                        widthTextPanel = new JPanel();
216
                        widthTextPanel.setPreferredSize(new java.awt.Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
217
                        widthTextPanel.setLayout(flowLayout);
218
                        widthTextPanel.add(getWidthText(), null);
219
                }
220
                return widthTextPanel;
221
        }
222

    
223
        /**
224
         * This method initializes jPanel1
225
         * @return javax.swing.JPanel
226
         */
227
        private JPanel getHeigthTextPanel() {
228
                if (heigthTextPanel == null) {
229
                        FlowLayout flowLayout5 = new FlowLayout();
230
                        flowLayout5.setHgap(0);
231
                        flowLayout5.setAlignment(java.awt.FlowLayout.LEFT);
232
                        flowLayout5.setVgap(1);
233
                        heigthTextPanel = new JPanel();
234
                        heigthTextPanel.setPreferredSize(new java.awt.Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
235
                        heigthTextPanel.setLayout(flowLayout5);
236
                        heigthTextPanel.add(getHeigthText(), null);
237
                }
238
                return heigthTextPanel;
239
        }
240

    
241
        /**
242
         * This method initializes jPanel2
243
         * @return javax.swing.JPanel
244
         */
245
        private JPanel getHeaderSizeTextPanel() {
246
                if (headerSizeTextPanel == null) {
247
                        FlowLayout flowLayout8 = new FlowLayout();
248
                        flowLayout8.setHgap(0);
249
                        flowLayout8.setAlignment(FlowLayout.LEFT);
250
                        flowLayout8.setVgap(1);
251
                        headerSizeTextPanel = new JPanel();
252
                        headerSizeTextPanel.setPreferredSize(new java.awt.Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
253
                        headerSizeTextPanel.setLayout(flowLayout8);
254
                        headerSizeTextPanel.add(getHeaderSizeText(), null);
255
                }
256
                return headerSizeTextPanel;
257
        }
258

    
259
        /**
260
         * This method initializes oficialTextPanel
261
         * @return javax.swing.JPanel
262
         */
263
        private JPanel getBandsTextPanel() {
264
                if (bandsTextPanel == null) {
265
                        FlowLayout flowLayout9 = new FlowLayout();
266
                        flowLayout9.setHgap(0);
267
                        flowLayout9.setAlignment(FlowLayout.LEFT);
268
                        flowLayout9.setVgap(1);
269
                        bandsTextPanel = new JPanel();
270
                        bandsTextPanel.setPreferredSize(new java.awt.Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
271
                        bandsTextPanel.setLayout(flowLayout9);
272
                        bandsTextPanel.add(getBandsText(), null);
273
                }
274
                return bandsTextPanel;
275
        }
276

    
277
        /**
278
         * This method initializes pronunciacionText
279
         * @return javax.swing.JTextField
280
         */
281
        private JFormattedTextField getWidthText() {
282
                if (widthText == null) {
283
                        widthText = new JFormattedTextField(NumberFormat.getIntegerInstance());
284
                        widthText.setPreferredSize(new Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
285
                        widthText.setText("0");
286
                }
287
                return widthText;
288
        }
289

    
290
        /**
291
         * This method initializes etimologyText
292
         * @return javax.swing.JTextField
293
         */
294
        private JFormattedTextField getHeigthText() {
295
                if (heigthText == null) {
296
                        heigthText = new JFormattedTextField(NumberFormat.getIntegerInstance());
297
                        heigthText.setPreferredSize(new Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
298
                        heigthText.setText("0");
299
                }
300
                return heigthText;
301
        }
302

    
303
        /**
304
         * This method initializes bandsText
305
         * @return javax.swing.JTextField
306
         */
307
        private JFormattedTextField getBandsText() {
308
                if (bandsText == null) {
309
                        bandsText = new JFormattedTextField(NumberFormat.getIntegerInstance());
310
                        bandsText.setPreferredSize(new Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
311
                        bandsText.setText("0");
312
                }
313
                return bandsText;
314
        }
315

    
316
        /**
317
         * This method initializes headerSizeText
318
         * @return javax.swing.JTextField
319
         */
320
        private JFormattedTextField getHeaderSizeText() {
321
                if (headerSizeText == null) {
322
                        headerSizeText = new JFormattedTextField(NumberFormat.getIntegerInstance());
323
                        headerSizeText.setPreferredSize(new Dimension(TEXTS_WIDTH, TEXTS_HEIGHT));
324
                        headerSizeText.setText("0");
325
                }
326
                return headerSizeText;
327
        }
328

    
329
        /**
330
         * gets the image width
331
         * @return
332
         */
333
        public int getImageWidth() {
334
                try {
335
                        String buffer = StringUtilities.replace(getWidthText().getText(), ".", "");
336
                        buffer = StringUtilities.replace(buffer, ",", "");
337
                        return Integer.parseInt(buffer);
338
                } catch (NumberFormatException e) {
339
                        return 0;
340
                }
341
        }
342

    
343
        /**
344
         * gets the image height
345
         * @return
346
         */
347
        public int getImageHeight() {
348
                try {
349
                        String buffer = StringUtilities.replace(getHeigthText().getText(), ".", "");
350
                        buffer = StringUtilities.replace(buffer, ",", "");
351
                        return Integer.parseInt(buffer);
352
                } catch (NumberFormatException e) {
353
                        return 0;
354
                }
355
        }
356

    
357
        /**
358
         * gets the number of bands
359
         * @return
360
         */
361
        public int getNumberOfBands() {
362
                try {
363
                        return Integer.valueOf(getBandsText().getText()).intValue();
364
                } catch (NumberFormatException e) {
365
                        return 0;
366
                }
367
        }
368

    
369
        /**
370
         * gets the header size
371
         * @return
372
         */
373
        public int getHeaderSize() {
374
                try {
375
                        return Integer.valueOf(getHeaderSizeText().getText()).intValue();
376
                } catch (NumberFormatException e) {
377
                        return 0;
378
                }
379
        }
380
}