Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / ui / ResolutionPanel.java @ 11463

History | View | Annotate | Download (13.4 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
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
package org.gvsig.rastertools.cutting.ui;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.FlowLayout;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

    
28
import javax.swing.JComboBox;
29
import javax.swing.JPanel;
30
import javax.swing.JRadioButton;
31

    
32
import org.gvsig.gui.beans.datainput.DataInputContainer;
33

    
34
import com.iver.andami.PluginServices;
35
/**
36
 * <code>ResolutionPanel</code> sirve para controlar las redimensiones por
37
 * interpolaci?n
38
 * 
39
 * @version 17/04/2007
40
 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
41
 */
42
public class ResolutionPanel extends JPanel implements ActionListener{
43
        private static final long serialVersionUID = 2570616093263451091L;
44

    
45
        private int                                        MARGIN = 10;
46
        private int                                        wHalf = (int)Math.floor((420 - MARGIN) >> 1) - 4, hHalf = 92;
47
        private int                                        hData = (int)Math.floor(hHalf/3);
48

    
49
        private JPanel                                 pResolution = null;
50
        private JPanel                                 pOption = null;
51
        private JPanel                                 pDataInput = null;
52
        private JPanel                                 pRatio = null;
53
        private JPanel                                 pInterpolation = null;
54
        private JPanel                                 pCellSize = null;
55
        private JPanel                                 pWidth = null;
56
        private JPanel                                 pHeight = null;
57
        private DataInputContainer         cCellSize = null;
58
        private DataInputContainer         cHeight = null;
59
        private DataInputContainer         cWidth = null;
60
        private JPanel                                 pButtons = null;
61
        private JRadioButton                 rSize = null;
62
        private JRadioButton                 rWidthH = null;
63
        private JComboBox                         cInterpolation = null;
64
        
65
        /**
66
         * This is the default constructor
67
         */
68
        public ResolutionPanel() {
69
                super();
70
                initialize();
71
        }
72

    
73
        /**
74
         * This method initializes this
75
         * 
76
         * @return void
77
         */
78
        private void initialize() {
79
                this.setLayout(new BorderLayout());
80
                this.add(getPResolution(), BorderLayout.CENTER);
81
                this.getRSize().addActionListener(this);
82
                this.getRWidthH().addActionListener(this);
83
                this.getRSize().setSelected(true);
84
                this.getCWidth().setControlEnabled(false);
85
                this.getCHeight().setControlEnabled(false);
86
        }
87

    
88
        /**
89
         * This method initializes jPanel        
90
         *         
91
         * @return javax.swing.JPanel        
92
         */
93
        private JPanel getPResolution() {
94
                if (pResolution == null) {
95
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
96
                        gridBagConstraints1.gridx = 1;
97
                        gridBagConstraints1.gridy = 0;
98
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
99
                        gridBagConstraints.gridx = 0;
100
                        gridBagConstraints.gridy = 0;
101
                        pResolution = new JPanel();
102
                        pResolution.setLayout(new GridBagLayout());
103
                        pResolution.add(getPOption(), gridBagConstraints);
104
                        pResolution.add(getPDataInput(), gridBagConstraints1);
105
                }
106
                return pResolution;
107
        }
108

    
109
        /**
110
         * This method initializes jPanel        
111
         *         
112
         * @return javax.swing.JPanel        
113
         */
114
        private JPanel getPOption() {
115
                if (pOption == null) {
116
                        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
117
                        gridBagConstraints6.gridx = 0;
118
                        gridBagConstraints6.gridy = 1;
119
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
120
                        gridBagConstraints2.gridx = 0;
121
                        gridBagConstraints2.gridy = 0;
122
                        pOption = new JPanel();
123
                        pOption.setLayout(new GridBagLayout());
124
                        pOption.setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
125
                        pOption.add(getPRatio(), gridBagConstraints2);
126
                        pOption.add(getPWidth(), gridBagConstraints6);
127
                }
128
                return pOption;
129
        }
130

    
131
        /**
132
         * This method initializes jPanel1        
133
         *         
134
         * @return javax.swing.JPanel        
135
         */
136
        private JPanel getPDataInput() {
137
                if (pDataInput == null) {
138
                        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
139
                        gridBagConstraints5.gridx = 0;
140
                        gridBagConstraints5.gridy = 2;
141
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
142
                        gridBagConstraints4.gridx = 0;
143
                        gridBagConstraints4.gridy = 1;
144
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
145
                        gridBagConstraints3.gridx = 0;
146
                        gridBagConstraints3.gridy = 0;
147
                        pDataInput = new JPanel();
148
                        pDataInput.setLayout(new GridBagLayout());
149
                        pDataInput.setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
150
                        pDataInput.add(getPInterpolation(), gridBagConstraints3);
151
                        pDataInput.add(getPCellSize(), gridBagConstraints4);
152
                        pDataInput.add(getPHeight(), gridBagConstraints5);
153
                }
154
                return pDataInput;
155
        }
156

    
157
        /**
158
         * This method initializes jPanel        
159
         *         
160
         * @return javax.swing.JPanel        
161
         */
162
        private JPanel getPRatio() {
163
                if (pRatio == null) {
164
                        pRatio = new JPanel();
165
                        FlowLayout flowLayout3 = new FlowLayout();
166
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
167
                        flowLayout3.setVgap(0);
168
                        flowLayout3.setHgap(0);
169
                        pRatio.setLayout(flowLayout3);
170
                        pRatio.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, (2 * hData)));
171
                        pRatio.add(getPButtons(), null);
172
                }
173
                return pRatio;
174
        }
175

    
176
        /**
177
         * This method initializes jPanel        
178
         *         
179
         * @return javax.swing.JPanel        
180
         */
181
        private JPanel getPInterpolation() {
182
                if (pInterpolation == null) {
183
                        FlowLayout flowLayout3 = new FlowLayout();
184
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
185
                        flowLayout3.setVgap(0);
186
                        flowLayout3.setHgap(0);
187
                        pInterpolation = new JPanel();
188
                        pInterpolation.setLayout(flowLayout3);
189
                        pInterpolation.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
190
                        pInterpolation.add(getJComboBox(), null);
191
                }
192
                return pInterpolation;
193
        }
194

    
195
        /**
196
         * This method initializes getPCellSize        
197
         *         
198
         * @return javax.swing.JPanel        
199
         */
200
        public JPanel getPCellSize() {
201
                if (pCellSize == null) {
202
                        FlowLayout flowLayout3 = new FlowLayout();
203
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
204
                        flowLayout3.setVgap(0);
205
                        flowLayout3.setHgap(0);
206
                        pCellSize = new JPanel();
207
                        pCellSize.setLayout(flowLayout3);
208
                        pCellSize.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
209
                        pCellSize.add(getCCellSize(), null);
210
                }
211
                return pCellSize;
212
        }
213
        
214
        /**
215
         * This method initializes getPHeight        
216
         *         
217
         * @return javax.swing.JPanel        
218
         */
219
        public JPanel getPHeight() {
220
                if (pHeight == null) {
221
                        FlowLayout flowLayout1 = new FlowLayout();
222
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
223
                        flowLayout1.setHgap(0);
224
                        flowLayout1.setVgap(0);
225
                        pHeight = new JPanel();
226
                        pHeight.setLayout(flowLayout1);
227
                        pHeight.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
228
                        pHeight.add(getCHeight(), null);
229
                }
230
                return pHeight;
231
        }
232
        
233
        /**
234
         * This method initializes getPWidth        
235
         *         
236
         * @return javax.swing.JPanel        
237
         */
238
        public JPanel getPWidth() {
239
                if (pWidth == null) {
240
                        FlowLayout flowLayout2 = new FlowLayout();
241
                        flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
242
                        flowLayout2.setVgap(0);
243
                        flowLayout2.setHgap(0);
244
                        pWidth = new JPanel();
245
                        pWidth.setLayout(flowLayout2);
246
                        pWidth.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
247
                        pWidth.add(getCWidth(), null);
248
                }
249
                return pWidth;
250
        }
251
        
252
        /**
253
         * This method initializes jPanel1        
254
         *         
255
         * @return javax.swing.JPanel        
256
         */
257
        public DataInputContainer getCCellSize() {
258
                if (cCellSize == null) {
259
                        cCellSize = new DataInputContainer(50);
260
                        cCellSize.setComponentSize(180, 0);
261
                        cCellSize.setLabelText(PluginServices.getText(this, "celda"));
262
                        cCellSize.setDecimal(true);
263
                }
264
                return cCellSize;
265
        }
266

    
267
        /**
268
         * This method initializes jPanel2        
269
         *         
270
         * @return javax.swing.JPanel        
271
         */
272
        public DataInputContainer getCHeight() {
273
                if (cHeight == null) {
274
                        cHeight = new DataInputContainer(50);
275
                        cHeight.setComponentSize(180, 0);
276
                        cHeight.setLabelText(PluginServices.getText(this, "alto"));
277
                        cHeight.setDecimal(true);
278
                }
279
                return cHeight;
280
        }
281

    
282
        /**
283
         * This method initializes jPanel        
284
         *         
285
         * @return javax.swing.JPanel        
286
         */
287
        public DataInputContainer getCWidth() {
288
                if (cWidth == null) {
289
                        cWidth = new DataInputContainer(50);
290
                        cWidth.setComponentSize(180, 0);
291
                        cWidth.setLabelText(PluginServices.getText(this, "ancho"));
292
                        cWidth.setDecimal(true);
293
                }
294
                return cWidth;
295
        }
296

    
297
        /**
298
         * This method initializes jPanel        
299
         *         
300
         * @return javax.swing.JPanel        
301
         */
302
        private JPanel getPButtons() {
303
                if (pButtons == null) {
304
                        pButtons = new JPanel();
305
                        FlowLayout flowLayout2 = new FlowLayout();
306
                        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
307
                        flowLayout2.setVgap(2);
308
                        flowLayout2.setHgap(5);
309
                        pButtons.setLayout(flowLayout2);
310
                        pButtons.setPreferredSize(new java.awt.Dimension(wHalf - 10, (2 * hData) - 6));
311
                        pButtons.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
312
                        pButtons.add(getRSize(), null);
313
                        pButtons.add(getRWidthH(), null);;
314
                }
315
                return pButtons;
316
        }
317

    
318
        /**
319
         * This method initializes jRadioButton        
320
         *         
321
         * @return javax.swing.JRadioButton        
322
         */
323
        private JRadioButton getRSize() {
324
                if (rSize == null) {
325
                        rSize = new JRadioButton(PluginServices.getText(this, "tamanyo_celda"));
326
                }
327
                return rSize;
328
        }
329

    
330
        /**
331
         * This method initializes jRadioButton1        
332
         *         
333
         * @return javax.swing.JRadioButton        
334
         */
335
        private JRadioButton getRWidthH() {
336
                if (rWidthH == null) {
337
                        rWidthH = new JRadioButton(PluginServices.getText(this, "ancho_x_alto"));
338
                }
339
                return rWidthH;
340
        }
341

    
342
        /**
343
         * This method initializes jComboBox        
344
         *         
345
         * @return javax.swing.JComboBox        
346
         */
347
        private JComboBox getJComboBox() {
348
                if (cInterpolation == null) {
349
                        cInterpolation = new JComboBox();
350
                        cInterpolation.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN - 2, 22));
351
                        cInterpolation.addItem(PluginServices.getText(this, "vecino_+_proximo"));
352
                        cInterpolation.addItem(PluginServices.getText(this, "bilinear"));
353
                        cInterpolation.addItem(PluginServices.getText(this, "distancia_inversa"));
354
                        cInterpolation.addItem(PluginServices.getText(this, "bicubico"));
355
                        cInterpolation.addItem(PluginServices.getText(this, "b_splines"));
356

    
357
                }
358
                return cInterpolation;
359
        }
360
        
361
        /**
362
         * Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
363
         * y con el n?mero de decimales que se especifica en el par?metro dec
364
         * @param cellSize Tama?o de celda en double
365
         * @param dec N?mero de decimales
366
         */
367
        public void setCellSizeText(double cellSize, int dec) {
368
                int indexPoint = String.valueOf(cellSize).indexOf('.');
369
                try {
370
                        cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec));
371
                } catch (StringIndexOutOfBoundsException ex) {
372
                        cCellSize.setValue(String.valueOf(cellSize));
373
                }
374
        }
375
        
376
        /**
377
         * Asigna el valor del campo "Ancho" a partir del double que lo representa
378
         * y con el n?mero de decimales que se especifica en el par?metro dec
379
         * @param width Ancho
380
         * @param dec N?mero de decimales
381
         */
382
        public void setWidthText(double width, int dec) {
383
                int indexPoint = String.valueOf(width).indexOf('.');
384
                try {
385
                        cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec));
386
                } catch (StringIndexOutOfBoundsException ex) {
387
                        cWidth.setValue(String.valueOf(width));
388
                }
389
        }
390
        
391
        /**
392
         * Asigna el valor del campo "Alto" a partir del double que lo representa
393
         * y con el n?mero de decimales que se especifica en el par?metro dec
394
         * @param height Alto
395
         * @param dec N?mero de decimales
396
         */
397
        public void setHeightText(double height, int dec) {
398
                int indexPoint = String.valueOf(height).indexOf('.');
399
                try {
400
                        cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec));
401
                } catch (StringIndexOutOfBoundsException ex) {
402
                        cHeight.setValue(String.valueOf(height));
403
                }
404
        }
405

    
406
        /**
407
         * Devuelve el valor del campo "tama?o de celda"
408
         * 
409
         * @return
410
         */
411
        public double getCellSizeText(){
412
                return Double.parseDouble(cCellSize.getValue());
413
        }
414
        
415
        /**
416
         * Devuelve el valor del campo "tama?o de celda"
417
         * @return
418
         */
419
        public double getWidthText(){
420
                return Double.parseDouble(cWidth.getValue());
421
        }
422
        
423
        /**
424
         * Devuelve el valor del campo "tama?o de celda"
425
         * @return
426
         */
427
        public double getHeightText(){
428
                return Double.parseDouble(cHeight.getValue());
429
        }
430
        
431
        /**
432
         * Devuelve los valores de Alto x Acho de la resoluci?n espacial
433
         * @return
434
         */
435
        public String[] getWidthHeight(){
436
                String[] text= { this.cWidth.getValue(),
437
                                                this.cHeight.getValue()
438
                                                };
439
                return text;
440
        }
441
        
442
        /**
443
         * Devuelve el metodo de interpolacion.
444
         * @return
445
         */
446
        public String getInterpolation(){
447
                return (String)this.getJComboBox().getSelectedItem();
448
        }
449
        
450
        /**************************************************************/
451
        /********************Listeners*********************************/
452
        /**************************************************************/
453
        
454
        public void actionPerformed(ActionEvent e) {
455
                if (e.getSource() == this.getRSize()) {
456
                        this.getRSize().setSelected(true);
457
                        this.getRWidthH().setSelected(false);
458
                        cCellSize.setControlEnabled(true);
459
                        cHeight.setControlEnabled(false);
460
                        cWidth.setControlEnabled(false);
461
                }
462
                if (e.getSource() == this.getRWidthH()) {
463
                        this.getRWidthH().setSelected(true);
464
                        this.getRSize().setSelected(false);
465
                        cCellSize.setControlEnabled(false);
466
                        cHeight.setControlEnabled(true);
467
                        cWidth.setControlEnabled(true);
468
                }
469
        }
470
}