Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1013 / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / ResolutionPanel.java @ 13521

History | View | Annotate | Download (14.3 KB)

1
package org.cresques.ui.raster;
2

    
3
import java.awt.Dimension;
4
import java.awt.FlowLayout;
5
import java.awt.GridBagConstraints;
6
import java.awt.GridBagLayout;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9

    
10
import javax.swing.JComboBox;
11
import javax.swing.JLabel;
12
import javax.swing.JPanel;
13
import javax.swing.JRadioButton;
14

    
15
import org.gvsig.gui.beans.dataInput.DataInputContainer;
16
import org.gvsig.i18n.Messages;
17

    
18
public class ResolutionPanel extends BaseComponent implements ActionListener{
19

    
20
        private int                                        MARGIN = 10;
21
        private int                                        wComp = 550, hComp = 140;
22
        private int                                        wHalf = (int)Math.floor((wComp - MARGIN) >> 1) - 4, hHalf = 92;
23
        private int                                        wData = wHalf - MARGIN, hData = (int)Math.floor(hHalf/3);
24

    
25
        private JPanel                                 pResolution = null;
26
        private JPanel                                 pOption = null;
27
        private JPanel                                 pDataInput = null;
28
        private JPanel                                 pRatio = null;
29
        private JPanel                                 pInterpolation = null;
30
        private JPanel                                 pCellSize = null;
31
        private JPanel                                 pWidth = null;
32
        private JPanel                                 pHeight = null;
33
        private DataInputContainer         cCellSize = null;
34
        private DataInputContainer         cHeight = null;
35
        private DataInputContainer         cWidth = null;
36
        private JPanel                                 pButtons = null;
37
        private JRadioButton                 rSize = null;
38
        private JRadioButton                 rWidthH = null;
39
        private JLabel                                 lSize = null;
40
        private JLabel                                 lWidthH = null;
41
        private JLabel                                 lInterpolation = null;
42
        private JComboBox                         cInterpolation = null;
43

    
44
        /**
45
         * This is the default constructor
46
         */
47
        public ResolutionPanel() {
48
                super();
49
                initialize();
50
        }
51

    
52
        /**
53
         * This method initializes this
54
         *
55
         * @return void
56
         */
57
        private void initialize() {
58
                FlowLayout flowLayout = new FlowLayout();
59
                flowLayout.setHgap(0);
60
                flowLayout.setVgap(0);
61
                this.setLayout(flowLayout);
62
                this.setSize(wComp, hComp);
63
                this.add(getPResolution(), null);
64
                this.getRSize().addActionListener(this);
65
                this.getRWidthH().addActionListener(this);
66
                this.getRSize().setSelected(true);
67
                this.getCWidth().setControlEnabled(false);
68
                this.getCHeight().setControlEnabled(false);
69
        }
70

    
71
        /**
72
         * This method initializes jPanel
73
         *
74
         * @return javax.swing.JPanel
75
         */
76
        private JPanel getPResolution() {
77
                if (pResolution == null) {
78
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
79
                        gridBagConstraints1.gridx = 1;
80
                        gridBagConstraints1.gridy = 0;
81
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
82
                        gridBagConstraints.gridx = 0;
83
                        gridBagConstraints.gridy = 0;
84
                        pResolution = new JPanel();
85
                        pResolution.setLayout(new GridBagLayout());
86
                        pResolution.setPreferredSize(new java.awt.Dimension(wComp,hComp));
87
                        pResolution.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("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));
88
                        pResolution.add(getPOption(), gridBagConstraints);
89
                        pResolution.add(getPDataInput(), gridBagConstraints1);
90
                }
91
                return pResolution;
92
        }
93

    
94
        /**
95
         * This method initializes jPanel
96
         *
97
         * @return javax.swing.JPanel
98
         */
99
        private JPanel getPOption() {
100
                if (pOption == null) {
101
                        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
102
                        gridBagConstraints6.gridx = 0;
103
                        gridBagConstraints6.gridy = 1;
104
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
105
                        gridBagConstraints2.gridx = 0;
106
                        gridBagConstraints2.gridy = 0;
107
                        pOption = new JPanel();
108
                        pOption.setLayout(new GridBagLayout());
109
                        pOption.setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
110
                        pOption.add(getPRatio(), gridBagConstraints2);
111
                        pOption.add(getPWidth(), gridBagConstraints6);
112
                }
113
                return pOption;
114
        }
115

    
116
        /**
117
         * This method initializes jPanel1
118
         *
119
         * @return javax.swing.JPanel
120
         */
121
        private JPanel getPDataInput() {
122
                if (pDataInput == null) {
123
                        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
124
                        gridBagConstraints5.gridx = 0;
125
                        gridBagConstraints5.gridy = 2;
126
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
127
                        gridBagConstraints4.gridx = 0;
128
                        gridBagConstraints4.gridy = 1;
129
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
130
                        gridBagConstraints3.gridx = 0;
131
                        gridBagConstraints3.gridy = 0;
132
                        pDataInput = new JPanel();
133
                        pDataInput.setLayout(new GridBagLayout());
134
                        pDataInput.setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
135
                        pDataInput.add(getPInterpolation(), gridBagConstraints3);
136
                        pDataInput.add(getPCellSize(), gridBagConstraints4);
137
                        pDataInput.add(getPHeight(), gridBagConstraints5);
138
                }
139
                return pDataInput;
140
        }
141

    
142
        /**
143
         * This method initializes jPanel
144
         *
145
         * @return javax.swing.JPanel
146
         */
147
        private JPanel getPRatio() {
148
                if (pRatio == null) {
149
                        pRatio = new JPanel();
150
                        FlowLayout flowLayout3 = new FlowLayout();
151
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
152
                        flowLayout3.setVgap(0);
153
                        flowLayout3.setHgap(0);
154
                        //pRatio.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
155
                        pRatio.setLayout(flowLayout3);
156
                        pRatio.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, (2 * hData)));
157
                        pRatio.add(getPButtons(), null);
158
                }
159
                return pRatio;
160
        }
161

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

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

    
202
        /**
203
         * This method initializes getPHeight
204
         *
205
         * @return javax.swing.JPanel
206
         */
207
        public JPanel getPHeight() {
208
                if (pHeight == null) {
209
                        FlowLayout flowLayout1 = new FlowLayout();
210
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
211
                        flowLayout1.setHgap(0);
212
                        flowLayout1.setVgap(0);
213
                        pHeight = new JPanel();
214
                        //pHeight.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
215
                        pHeight.setLayout(flowLayout1);
216
                        pHeight.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
217
                        pHeight.add(getCHeight(), null);
218
                }
219
                return pHeight;
220
        }
221

    
222
        /**
223
         * This method initializes getPWidth
224
         *
225
         * @return javax.swing.JPanel
226
         */
227
        public JPanel getPWidth() {
228
                if (pWidth == null) {
229
                        FlowLayout flowLayout2 = new FlowLayout();
230
                        flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
231
                        flowLayout2.setVgap(0);
232
                        flowLayout2.setHgap(0);
233
                        pWidth = new JPanel();
234
                        //pWidth.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
235
                        pWidth.setLayout(flowLayout2);
236
                        pWidth.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN, hData));
237
                        pWidth.add(getCWidth(), null);
238
                }
239
                return pWidth;
240
        }
241

    
242
        /**
243
         * This method initializes jPanel1
244
         *
245
         * @return javax.swing.JPanel
246
         */
247
        public DataInputContainer getCCellSize() {
248
                if (cCellSize == null) {
249
                        cCellSize = new DataInputContainer();
250
                        //cCellSize.setComponentSize(180, 0);
251
                        cCellSize.setLabelText(Messages.getText("celda"));
252
                        cCellSize.setDecimal(true);
253
                }
254
                return cCellSize;
255
        }
256

    
257
        /**
258
         * This method initializes jPanel2
259
         *
260
         * @return javax.swing.JPanel
261
         */
262
        public DataInputContainer getCHeight() {
263
                if (cHeight == null) {
264
                        cHeight = new DataInputContainer();
265
                        //cHeight.setComponentSize(180, 0);
266
                        cHeight.setLabelText(Messages.getText("alto"));
267
                        cHeight.setDecimal(true);
268
                }
269
                return cHeight;
270
        }
271

    
272
        /**
273
         * This method initializes jPanel
274
         *
275
         * @return javax.swing.JPanel
276
         */
277
        public DataInputContainer getCWidth() {
278
                if (cWidth == null) {
279
                        cWidth = new DataInputContainer();
280
                        //cWidth.setComponentSize(180, 0);
281
                        cWidth.setLabelText(Messages.getText("ancho"));
282
                        cWidth.setDecimal(true);
283
                }
284
                return cWidth;
285
        }
286

    
287
        /**
288
         * This method initializes jPanel
289
         *
290
         * @return javax.swing.JPanel
291
         */
292
        private JPanel getPButtons() {
293
                if (pButtons == null) {
294
                        pButtons = new JPanel();
295
                        FlowLayout flowLayout2 = new FlowLayout();
296
                        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
297
                        flowLayout2.setVgap(2);
298
                        flowLayout2.setHgap(5);
299
                        pButtons.setLayout(flowLayout2);
300
                        pButtons.setPreferredSize(new java.awt.Dimension(wHalf - 10, (2 * hData) - 6));
301
                        pButtons.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
302
                        pButtons.add(getRSize(), null);
303
                        pButtons.add(getRWidthH(), null);;
304
                }
305
                return pButtons;
306
        }
307

    
308
        /**
309
         * This method initializes jRadioButton
310
         *
311
         * @return javax.swing.JRadioButton
312
         */
313
        private JRadioButton getRSize() {
314
                if (rSize == null) {
315
                        rSize = new JRadioButton(Messages.getText("tamanyo_celda"));
316
                }
317
                return rSize;
318
        }
319

    
320
        /**
321
         * This method initializes jRadioButton1
322
         *
323
         * @return javax.swing.JRadioButton
324
         */
325
        private JRadioButton getRWidthH() {
326
                if (rWidthH == null) {
327
                        rWidthH = new JRadioButton(Messages.getText("ancho_x_alto"));
328
                }
329
                return rWidthH;
330
        }
331

    
332
        /**
333
         * This method initializes jComboBox
334
         *
335
         * @return javax.swing.JComboBox
336
         */
337
        private JComboBox getJComboBox() {
338
                if (cInterpolation == null) {
339
                        cInterpolation = new JComboBox();
340
                        cInterpolation.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN - 2, 22));
341
                        cInterpolation.addItem(Messages.getText("vecino_+_proximo"));
342
                        cInterpolation.addItem(Messages.getText("bilinear"));
343
                        cInterpolation.addItem(Messages.getText("distancia_inversa"));
344
                        cInterpolation.addItem(Messages.getText("bicubico"));
345
                        cInterpolation.addItem(Messages.getText("b_splines"));
346

    
347
                }
348
                return cInterpolation;
349
        }
350

    
351

    
352
        public void setComponentSize(int w, int h){
353
                /*wComp = w; hComp = 120;
354
                wHalf = (int)Math.floor((wComp-10)/2); hHalf = 95;
355
                wData = wHalf - 10; hData = (int)Math.floor(hHalf/3);
356

357
                this.setPreferredSize(new Dimension(wComp, hComp));
358
                getPResolution().setPreferredSize(new java.awt.Dimension(wComp,hComp));
359
                getPOption().setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
360
                getPWidth().setPreferredSize(new java.awt.Dimension(wHalf,hData));
361
                getPDataInput().setPreferredSize(new java.awt.Dimension(wHalf,hHalf));
362
                getPInterpolation().setPreferredSize(new java.awt.Dimension(wHalf,hData));
363
                getPCellSize().setPreferredSize(new java.awt.Dimension(wHalf,hData));
364
                getCCellSize().setComponentSize(wData,hData);
365
                getCCellSize().setComponentHeight(hData);
366
                getPHeight().setPreferredSize(new java.awt.Dimension(wHalf,hData));
367
                getCHeight().setComponentSize(wData,hData);
368
                getCHeight().setComponentHeight(hData);
369
                getPWidth().setPreferredSize(new java.awt.Dimension(wHalf,hData));
370
                getCWidth().setComponentSize(wData,hData);
371
                getCWidth().setComponentHeight(hData);*/
372

    
373
        }
374

    
375
        /**
376
         * Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
377
         * y con el n?mero de decimales que se especifica en el par?metro dec
378
         * @param cellSize Tama?o de celda en double
379
         * @param dec N?mero de decimales
380
         */
381
        public void setCellSizeText(double cellSize, int dec){
382
                int indexPoint = String.valueOf(cellSize).indexOf('.');
383
                try{
384
                        cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec));
385
                   }catch(StringIndexOutOfBoundsException ex){
386
                           cCellSize.setValue(String.valueOf(cellSize));
387
                   }
388
        }
389

    
390
        /**
391
         * Asigna el valor del campo "Ancho" a partir del double que lo representa
392
         * y con el n?mero de decimales que se especifica en el par?metro dec
393
         * @param width Ancho
394
         * @param dec N?mero de decimales
395
         */
396
        public void setWidthText(double width, int dec){
397
                int indexPoint = String.valueOf(width).indexOf('.');
398
                try{
399
                        cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec));
400
                   }catch(StringIndexOutOfBoundsException ex){
401
                           cWidth.setValue(String.valueOf(width));
402
                   }
403
        }
404

    
405
        /**
406
         * Asigna el valor del campo "Alto" a partir del double que lo representa
407
         * y con el n?mero de decimales que se especifica en el par?metro dec
408
         * @param height Alto
409
         * @param dec N?mero de decimales
410
         */
411
        public void setHeightText(double height, int dec){
412
                int indexPoint = String.valueOf(height).indexOf('.');
413
                try{
414
                        cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec));
415
                   }catch(StringIndexOutOfBoundsException ex){
416
                           cHeight.setValue(String.valueOf(height));
417
                   }
418
        }
419

    
420
        /**
421
         * Devuelve el valor del campo "tama?o de celda"
422
         * @return
423
         */
424
        public double getCellSizeText(){
425
                return Double.parseDouble(cCellSize.getValue());
426
        }
427

    
428
        /**
429
         * Devuelve el valor del campo "tama?o de celda"
430
         * @return
431
         */
432
        public double getWidthText(){
433
                return Double.parseDouble(cWidth.getValue());
434
        }
435

    
436
        /**
437
         * Devuelve el valor del campo "tama?o de celda"
438
         * @return
439
         */
440
        public double getHeightText(){
441
                return Double.parseDouble(cHeight.getValue());
442
        }
443

    
444
        /**
445
         * Devuelve los valores de Alto x Acho de la resoluci?n espacial
446
         * @return
447
         */
448
        public String[] getWidthHeight(){
449
                String[] text= { this.cWidth.getValue(),
450
                                                this.cHeight.getValue()
451
                                                };
452
                return text;
453
        }
454

    
455
        /**
456
         * Devuelve el metodo de interpolacion.
457
         * @return
458
         */
459
        public String getInterpolation(){
460
                return (String)this.getJComboBox().getSelectedItem();
461
        }
462

    
463

    
464
        /**************************************************************/
465
        /********************Listeners*********************************/
466
        /**************************************************************/
467

    
468
        public void actionPerformed(ActionEvent e) {
469
                if (e.getSource() == this.getRSize()){
470
                        this.getRSize().setSelected(true);
471
                        this.getRWidthH().setSelected(false);
472
                        cCellSize.setControlEnabled(true);
473
                        cHeight.setControlEnabled(false);
474
                        cWidth.setControlEnabled(false);
475
                }
476
                if(e.getSource() == this.getRWidthH()){
477
                        this.getRWidthH().setSelected(true);
478
                        this.getRSize().setSelected(false);
479
                        cCellSize.setControlEnabled(false);
480
                        cHeight.setControlEnabled(true);
481
                        cWidth.setControlEnabled(true);
482
                }
483
        }
484

    
485

    
486
}