Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / ui / ResolutionPanel.java @ 11228

History | View | Annotate | Download (15.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.FlowLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26

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

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

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

    
44
        private int                                        MARGIN = 10;
45
        private int                                        wComp = 404, hComp = 120;
46
        private int                                        wHalf = (int)Math.floor((wComp - 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
                FlowLayout flowLayout = new FlowLayout();
80
                flowLayout.setHgap(0);
81
                flowLayout.setVgap(0);
82
                this.setLayout(flowLayout);
83
                this.setSize(wComp, hComp);
84
                this.add(getPResolution(), null);
85
                this.getRSize().addActionListener(this);
86
                this.getRWidthH().addActionListener(this);
87
                this.getRSize().setSelected(true);
88
                this.getCWidth().setControlEnabled(false);
89
                this.getCHeight().setControlEnabled(false);
90
        }
91

    
92
        /**
93
         * This method initializes jPanel        
94
         *         
95
         * @return javax.swing.JPanel        
96
         */
97
        private JPanel getPResolution() {
98
                if (pResolution == null) {
99
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
100
                        gridBagConstraints1.gridx = 1;
101
                        gridBagConstraints1.gridy = 0;
102
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
103
                        gridBagConstraints.gridx = 0;
104
                        gridBagConstraints.gridy = 0;
105
                        pResolution = new JPanel();
106
                        pResolution.setLayout(new GridBagLayout());
107
                        pResolution.setPreferredSize(new java.awt.Dimension(wComp,hComp));
108
                        pResolution.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "resolucion_espacial"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10), null));
109
                        pResolution.add(getPOption(), gridBagConstraints);
110
                        pResolution.add(getPDataInput(), gridBagConstraints1);
111
                }
112
                return pResolution;
113
        }
114

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

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

    
163
        /**
164
         * This method initializes jPanel        
165
         *         
166
         * @return javax.swing.JPanel        
167
         */
168
        private JPanel getPRatio() {
169
                if (pRatio == null) {
170
                        pRatio = new JPanel();
171
                        FlowLayout flowLayout3 = new FlowLayout();
172
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
173
                        flowLayout3.setVgap(0);
174
                        flowLayout3.setHgap(0);
175
                        //pRatio.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
176
                        pRatio.setLayout(flowLayout3);
177
                        pRatio.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, (2 * hData)));
178
                        pRatio.add(getPButtons(), null);
179
                }
180
                return pRatio;
181
        }
182

    
183
        /**
184
         * This method initializes jPanel        
185
         *         
186
         * @return javax.swing.JPanel        
187
         */
188
        private JPanel getPInterpolation() {
189
                if (pInterpolation == null) {
190
                        FlowLayout flowLayout3 = new FlowLayout();
191
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
192
                        flowLayout3.setVgap(0);
193
                        flowLayout3.setHgap(0);
194
                        pInterpolation = new JPanel();
195
                        pInterpolation.setLayout(flowLayout3);
196
                        pInterpolation.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
197
                        //pInterpolation.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
198
                        pInterpolation.add(getJComboBox(), null);
199
                }
200
                return pInterpolation;
201
        }
202

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

    
278
        /**
279
         * This method initializes jPanel2        
280
         *         
281
         * @return javax.swing.JPanel        
282
         */
283
        public DataInputContainer getCHeight() {
284
                if (cHeight == null) {
285
                        cHeight = new DataInputContainer(50);
286
                        cHeight.setComponentSize(180, 0);
287
                        cHeight.setLabelText(PluginServices.getText(this, "alto"));
288
                        cHeight.setDecimal(true);
289
                }
290
                return cHeight;
291
        }
292

    
293
        /**
294
         * This method initializes jPanel        
295
         *         
296
         * @return javax.swing.JPanel        
297
         */
298
        public DataInputContainer getCWidth() {
299
                if (cWidth == null) {
300
                        cWidth = new DataInputContainer(50);
301
                        cWidth.setComponentSize(180, 0);
302
                        cWidth.setLabelText(PluginServices.getText(this, "ancho"));
303
                        cWidth.setDecimal(true);
304
                }
305
                return cWidth;
306
        }
307

    
308
        /**
309
         * This method initializes jPanel        
310
         *         
311
         * @return javax.swing.JPanel        
312
         */
313
        private JPanel getPButtons() {
314
                if (pButtons == null) {
315
                        pButtons = new JPanel();
316
                        FlowLayout flowLayout2 = new FlowLayout();
317
                        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
318
                        flowLayout2.setVgap(2);
319
                        flowLayout2.setHgap(5);
320
                        pButtons.setLayout(flowLayout2);
321
                        pButtons.setPreferredSize(new java.awt.Dimension(wHalf - 10, (2 * hData) - 6));
322
                        pButtons.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
323
                        pButtons.add(getRSize(), null);
324
                        pButtons.add(getRWidthH(), null);;
325
                }
326
                return pButtons;
327
        }
328

    
329
        /**
330
         * This method initializes jRadioButton        
331
         *         
332
         * @return javax.swing.JRadioButton        
333
         */
334
        private JRadioButton getRSize() {
335
                if (rSize == null) {
336
                        rSize = new JRadioButton(PluginServices.getText(this, "tamanyo_celda"));
337
                }
338
                return rSize;
339
        }
340

    
341
        /**
342
         * This method initializes jRadioButton1        
343
         *         
344
         * @return javax.swing.JRadioButton        
345
         */
346
        private JRadioButton getRWidthH() {
347
                if (rWidthH == null) {
348
                        rWidthH = new JRadioButton(PluginServices.getText(this, "ancho_x_alto"));
349
                }
350
                return rWidthH;
351
        }
352

    
353
        /**
354
         * This method initializes jComboBox        
355
         *         
356
         * @return javax.swing.JComboBox        
357
         */
358
        private JComboBox getJComboBox() {
359
                if (cInterpolation == null) {
360
                        cInterpolation = new JComboBox();
361
                        cInterpolation.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN - 2, 22));
362
                        cInterpolation.addItem(PluginServices.getText(this, "vecino_+_proximo"));
363
                        cInterpolation.addItem(PluginServices.getText(this, "bilinear"));
364
                        cInterpolation.addItem(PluginServices.getText(this, "distancia_inversa"));
365
                        cInterpolation.addItem(PluginServices.getText(this, "bicubico"));
366
                        cInterpolation.addItem(PluginServices.getText(this, "b_splines"));
367
                        
368
                }
369
                return cInterpolation;
370
        }
371

    
372
        
373
        public void setComponentSize(int w, int h){
374
                /*wComp = w; hComp = 120;
375
                wHalf = (int)Math.floor((wComp-10)/2); hHalf = 95;
376
                wData = wHalf - 10; hData = (int)Math.floor(hHalf/3);
377
                
378
                this.setPreferredSize(new Dimension(wComp, hComp));
379
                getPResolution().setPreferredSize(new java.awt.Dimension(wComp,hComp));
380
                getPOption().setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
381
                getPWidth().setPreferredSize(new java.awt.Dimension(wHalf,hData));
382
                getPDataInput().setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
383
                getPInterpolation().setPreferredSize(new java.awt.Dimension(wHalf,hData));
384
                getPCellSize().setPreferredSize(new java.awt.Dimension(wHalf,hData));
385
                getCCellSize().setComponentSize(wData,hData);
386
                getCCellSize().setComponentHeight(hData);
387
                getPHeight().setPreferredSize(new java.awt.Dimension(wHalf,hData));
388
                getCHeight().setComponentSize(wData,hData);
389
                getCHeight().setComponentHeight(hData);
390
                getPWidth().setPreferredSize(new java.awt.Dimension(wHalf,hData));
391
                getCWidth().setComponentSize(wData,hData);
392
                getCWidth().setComponentHeight(hData);*/
393
                
394
        }
395
        
396
        /**
397
         * Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
398
         * y con el n?mero de decimales que se especifica en el par?metro dec
399
         * @param cellSize Tama?o de celda en double
400
         * @param dec N?mero de decimales
401
         */
402
        public void setCellSizeText(double cellSize, int dec){
403
                int indexPoint = String.valueOf(cellSize).indexOf('.');
404
                try{
405
                        cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec));
406
                   }catch(StringIndexOutOfBoundsException ex){
407
                           cCellSize.setValue(String.valueOf(cellSize));
408
                   }
409
        }
410
        
411
        /**
412
         * Asigna el valor del campo "Ancho" a partir del double que lo representa
413
         * y con el n?mero de decimales que se especifica en el par?metro dec
414
         * @param width Ancho
415
         * @param dec N?mero de decimales
416
         */
417
        public void setWidthText(double width, int dec){
418
                int indexPoint = String.valueOf(width).indexOf('.');
419
                try{
420
                        cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec));
421
                   }catch(StringIndexOutOfBoundsException ex){
422
                           cWidth.setValue(String.valueOf(width));
423
                   }
424
        }
425
        
426
        /**
427
         * Asigna el valor del campo "Alto" a partir del double que lo representa
428
         * y con el n?mero de decimales que se especifica en el par?metro dec
429
         * @param height Alto
430
         * @param dec N?mero de decimales
431
         */
432
        public void setHeightText(double height, int dec){
433
                int indexPoint = String.valueOf(height).indexOf('.');
434
                try{
435
                        cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec));
436
                   }catch(StringIndexOutOfBoundsException ex){
437
                           cHeight.setValue(String.valueOf(height));
438
                   }
439
        }
440
        
441
        /**
442
         * Devuelve el valor del campo "tama?o de celda"
443
         * @return
444
         */
445
        public double getCellSizeText(){
446
                return Double.parseDouble(cCellSize.getValue());
447
        }
448
        
449
        /**
450
         * Devuelve el valor del campo "tama?o de celda"
451
         * @return
452
         */
453
        public double getWidthText(){
454
                return Double.parseDouble(cWidth.getValue());
455
        }
456
        
457
        /**
458
         * Devuelve el valor del campo "tama?o de celda"
459
         * @return
460
         */
461
        public double getHeightText(){
462
                return Double.parseDouble(cHeight.getValue());
463
        }
464
        
465
        /**
466
         * Devuelve los valores de Alto x Acho de la resoluci?n espacial
467
         * @return
468
         */
469
        public String[] getWidthHeight(){
470
                String[] text= { this.cWidth.getValue(),
471
                                                this.cHeight.getValue()
472
                                                };
473
                return text;
474
        }
475
        
476
        /**
477
         * Devuelve el metodo de interpolacion.
478
         * @return
479
         */
480
        public String getInterpolation(){
481
                return (String)this.getJComboBox().getSelectedItem();
482
        }
483
        
484
        
485
        /**************************************************************/
486
        /********************Listeners*********************************/
487
        /**************************************************************/
488
        
489
        public void actionPerformed(ActionEvent e) {
490
                if (e.getSource() == this.getRSize()){
491
                        this.getRSize().setSelected(true);
492
                        this.getRWidthH().setSelected(false);
493
                        cCellSize.setControlEnabled(true);
494
                        cHeight.setControlEnabled(false);
495
                        cWidth.setControlEnabled(false);
496
                }
497
                if(e.getSource() == this.getRWidthH()){
498
                        this.getRWidthH().setSelected(true);
499
                        this.getRSize().setSelected(false);
500
                        cCellSize.setControlEnabled(false);
501
                        cHeight.setControlEnabled(true);
502
                        cWidth.setControlEnabled(true);
503
                }
504
        }
505
        
506
        
507
}