Statistics
| Revision:

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

History | View | Annotate | Download (14 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
import org.gvsig.raster.buffer.BufferInterpolation;
34

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
358
                }
359
                return cInterpolation;
360
        }
361
        
362
        /**
363
         * Obtiene el valor correspondiente al m?todo de interpolaci?n seleccionado en 
364
         * el JComboBox
365
         * @return M?todo de interpolaci?n interpretable con las variables definidas en BufferInterpolation.
366
         */
367
        public int getSelectedInterpolationMethod() {
368
                switch(getJComboBox().getSelectedIndex()) {
369
                case 0: return BufferInterpolation.INTERPOLATION_NearestNeighbour;
370
                case 1: return BufferInterpolation.INTERPOLATION_Bilinear;
371
                case 2: return BufferInterpolation.INTERPOLATION_InverseDistance;
372
                case 3: return BufferInterpolation.INTERPOLATION_BSpline;
373
                }
374
                return BufferInterpolation.INTERPOLATION_Undefined;
375
        }
376
        
377
        /**
378
         * Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
379
         * y con el n?mero de decimales que se especifica en el par?metro dec
380
         * @param cellSize Tama?o de celda en double
381
         * @param dec N?mero de decimales
382
         */
383
        public void setCellSizeText(double cellSize, int dec) {
384
                int indexPoint = String.valueOf(cellSize).indexOf('.');
385
                try {
386
                        cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec));
387
                } catch (StringIndexOutOfBoundsException ex) {
388
                        cCellSize.setValue(String.valueOf(cellSize));
389
                }
390
        }
391
        
392
        /**
393
         * Asigna el valor del campo "Ancho" a partir del double que lo representa
394
         * y con el n?mero de decimales que se especifica en el par?metro dec
395
         * @param width Ancho
396
         * @param dec N?mero de decimales
397
         */
398
        public void setWidthText(double width, int dec) {
399
                int indexPoint = String.valueOf(width).indexOf('.');
400
                try {
401
                        cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec));
402
                } catch (StringIndexOutOfBoundsException ex) {
403
                        cWidth.setValue(String.valueOf(width));
404
                }
405
        }
406
        
407
        /**
408
         * Asigna el valor del campo "Alto" a partir del double que lo representa
409
         * y con el n?mero de decimales que se especifica en el par?metro dec
410
         * @param height Alto
411
         * @param dec N?mero de decimales
412
         */
413
        public void setHeightText(double height, int dec) {
414
                int indexPoint = String.valueOf(height).indexOf('.');
415
                try {
416
                        cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec));
417
                } catch (StringIndexOutOfBoundsException ex) {
418
                        cHeight.setValue(String.valueOf(height));
419
                }
420
        }
421

    
422
        /**
423
         * Devuelve el valor del campo "tama?o de celda"
424
         * 
425
         * @return
426
         */
427
        public double getCellSizeText(){
428
                return Double.parseDouble(cCellSize.getValue());
429
        }
430
        
431
        /**
432
         * Devuelve el valor del campo "tama?o de celda"
433
         * @return
434
         */
435
        public double getWidthText(){
436
                return Double.parseDouble(cWidth.getValue());
437
        }
438
        
439
        /**
440
         * Devuelve el valor del campo "tama?o de celda"
441
         * @return
442
         */
443
        public double getHeightText(){
444
                return Double.parseDouble(cHeight.getValue());
445
        }
446
        
447
        /**
448
         * Devuelve los valores de Alto x Acho de la resoluci?n espacial
449
         * @return
450
         */
451
        public String[] getWidthHeight(){
452
                String[] text= { this.cWidth.getValue(),
453
                                                this.cHeight.getValue()
454
                                                };
455
                return text;
456
        }
457
        
458
        /**
459
         * Devuelve el metodo de interpolacion.
460
         * @return
461
         */
462
        public String getInterpolation(){
463
                return (String)this.getJComboBox().getSelectedItem();
464
        }
465
        
466
        /**************************************************************/
467
        /********************Listeners*********************************/
468
        /**************************************************************/
469
        
470
        public void actionPerformed(ActionEvent e) {
471
                if (e.getSource() == this.getRSize()) {
472
                        this.getRSize().setSelected(true);
473
                        this.getRWidthH().setSelected(false);
474
                        cCellSize.setControlEnabled(true);
475
                        cHeight.setControlEnabled(false);
476
                        cWidth.setControlEnabled(false);
477
                }
478
                if (e.getSource() == this.getRWidthH()) {
479
                        this.getRWidthH().setSelected(true);
480
                        this.getRSize().setSelected(false);
481
                        cCellSize.setControlEnabled(false);
482
                        cHeight.setControlEnabled(true);
483
                        cWidth.setControlEnabled(true);
484
                }
485
        }
486
}