Statistics
| Revision:

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

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

    
25
import javax.swing.JComboBox;
26
import javax.swing.JPanel;
27
import javax.swing.JRadioButton;
28

    
29
import org.gvsig.gui.beans.datainput.DataInputContainer;
30
import org.gvsig.raster.buffer.BufferInterpolation;
31

    
32
import com.iver.andami.PluginServices;
33
/**
34
 * <code>ResolutionPanel</code> sirve para controlar las redimensiones por
35
 * interpolaci?n
36
 *
37
 * @version 17/04/2007
38
 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
39
 */
40
public class ResolutionPanel extends JPanel implements ActionListener{
41
        private static final long serialVersionUID = 2570616093263451091L;
42
        private int                MARGIN           = 10;
43
        private int                wHalf            = (int) Math.floor((420 - MARGIN) >> 1) - 4, hHalf = 92;
44
        private int                hData            = (int) Math.floor(hHalf / 3);
45
        private JPanel             pButtons         = null;
46
        private DataInputContainer cCellSize        = null;
47
        private DataInputContainer cHeight          = null;
48
        private DataInputContainer cWidth           = null;
49
        private JRadioButton       rSize            = null;
50
        private JRadioButton       rWidthH          = null;
51
        private JComboBox          cInterpolation   = null;
52

    
53
        /**
54
         * This is the default constructor
55
         */
56
        public ResolutionPanel() {
57
                super();
58
                initialize();
59
        }
60

    
61
        /**
62
         * This method initializes this
63
         *
64
         * @return void
65
         */
66
        private void initialize() {
67
                GridBagConstraints gridBagConstraints;
68

    
69
                setLayout(new java.awt.GridBagLayout());
70

    
71
                gridBagConstraints = new java.awt.GridBagConstraints();
72
                gridBagConstraints.gridheight = 2;
73
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
74
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
75
                gridBagConstraints.weightx = 1.0;
76
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2);
77
                add(getPButtons(), gridBagConstraints);
78

    
79
                gridBagConstraints = new java.awt.GridBagConstraints();
80
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
81
                gridBagConstraints.weightx = 1.0;
82
                gridBagConstraints.insets = new java.awt.Insets(5, 2, 2, 5);
83
                add(getJComboBox(), gridBagConstraints);
84

    
85

    
86
                gridBagConstraints = new java.awt.GridBagConstraints();
87
                gridBagConstraints.gridx = 1;
88
                gridBagConstraints.gridy = 1;
89
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
90
                gridBagConstraints.weightx = 1.0;
91
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 5);
92
                add(getCCellSize(), gridBagConstraints);
93

    
94
                gridBagConstraints = new java.awt.GridBagConstraints();
95
                gridBagConstraints.gridx = 0;
96
                gridBagConstraints.gridy = 2;
97
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
98
                gridBagConstraints.weightx = 1.0;
99
                gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 2);
100
                add(getCWidth(), gridBagConstraints);
101

    
102
                gridBagConstraints = new java.awt.GridBagConstraints();
103
                gridBagConstraints.gridx = 1;
104
                gridBagConstraints.gridy = 2;
105
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
106
                gridBagConstraints.weightx = 1.0;
107
                gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 5);
108
                add(getCHeight(), gridBagConstraints);
109

    
110
                getRSize().addActionListener(this);
111
                getRWidthH().addActionListener(this);
112
                getRSize().setSelected(true);
113
                getCWidth().setControlEnabled(false);
114
                getCHeight().setControlEnabled(false);
115
        }
116

    
117
        /**
118
         * This method initializes jPanel1
119
         *
120
         * @return javax.swing.JPanel
121
         */
122
        public DataInputContainer getCCellSize() {
123
                if (cCellSize == null) {
124
                        cCellSize = new DataInputContainer();
125
                        cCellSize.setLabelText(PluginServices.getText(this, "celda"));
126
                        cCellSize.setDecimal(true);
127
                }
128
                return cCellSize;
129
        }
130

    
131
        /**
132
         * This method initializes jPanel2
133
         *
134
         * @return javax.swing.JPanel
135
         */
136
        public DataInputContainer getCHeight() {
137
                if (cHeight == null) {
138
                        cHeight = new DataInputContainer();
139
                        cHeight.setLabelText(PluginServices.getText(this, "alto"));
140
                        cHeight.setDecimal(true);
141
                }
142
                return cHeight;
143
        }
144

    
145
        /**
146
         * This method initializes jPanel
147
         *
148
         * @return javax.swing.JPanel
149
         */
150
        public DataInputContainer getCWidth() {
151
                if (cWidth == null) {
152
                        cWidth = new DataInputContainer();
153
                        cWidth.setLabelText(PluginServices.getText(this, "ancho"));
154
                        cWidth.setDecimal(true);
155
                }
156
                return cWidth;
157
        }
158

    
159
        /**
160
         * This method initializes jPanel
161
         *
162
         * @return javax.swing.JPanel
163
         */
164
        private JPanel getPButtons() {
165
                if (pButtons == null) {
166
                        pButtons = new JPanel();
167
                        pButtons.setLayout(new java.awt.GridBagLayout());
168
                        pButtons.setPreferredSize(new java.awt.Dimension(wHalf - 10, (2 * hData) - 6));
169
                        pButtons.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
170

    
171
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
172
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
173
                        gridBagConstraints.weightx = 1.0;
174
                        gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 0);
175
                        pButtons.add(getRSize(), gridBagConstraints);
176

    
177
                        gridBagConstraints = new java.awt.GridBagConstraints();
178
                        gridBagConstraints.gridx = 0;
179
                        gridBagConstraints.gridy = 1;
180
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
181
                        gridBagConstraints.weightx = 1.0;
182
                        gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 0);
183
                        pButtons.add(getRWidthH(), gridBagConstraints);;
184
                }
185
                return pButtons;
186
        }
187

    
188
        /**
189
         * This method initializes jRadioButton
190
         *
191
         * @return javax.swing.JRadioButton
192
         */
193
        private JRadioButton getRSize() {
194
                if (rSize == null) {
195
                        rSize = new JRadioButton(PluginServices.getText(this, "tamanyo_celda"));
196
                }
197
                return rSize;
198
        }
199

    
200
        /**
201
         * This method initializes jRadioButton1
202
         *
203
         * @return javax.swing.JRadioButton
204
         */
205
        private JRadioButton getRWidthH() {
206
                if (rWidthH == null) {
207
                        rWidthH = new JRadioButton(PluginServices.getText(this, "ancho_x_alto"));
208
                }
209
                return rWidthH;
210
        }
211

    
212
        /**
213
         * This method initializes jComboBox
214
         *
215
         * @return javax.swing.JComboBox
216
         */
217
        private JComboBox getJComboBox() {
218
                if (cInterpolation == null) {
219
                        cInterpolation = new JComboBox();
220
                        cInterpolation.setPreferredSize(new java.awt.Dimension(wHalf - MARGIN - 2, 22));
221
                        cInterpolation.addItem(PluginServices.getText(this, "vecino_+_proximo"));
222
                        cInterpolation.addItem(PluginServices.getText(this, "bilinear"));
223
                        cInterpolation.addItem(PluginServices.getText(this, "distancia_inversa"));
224
                        cInterpolation.addItem(PluginServices.getText(this, "b_splines"));
225
                        //cInterpolation.addItem(PluginServices.getText(this, "bicubico"));
226

    
227
                }
228
                return cInterpolation;
229
        }
230

    
231
        /**
232
         * Obtiene el valor correspondiente al m?todo de interpolaci?n seleccionado en
233
         * el JComboBox
234
         * @return M?todo de interpolaci?n interpretable con las variables definidas en BufferInterpolation.
235
         */
236
        public int getSelectedInterpolationMethod() {
237
                switch(getJComboBox().getSelectedIndex()) {
238
                case 0: return BufferInterpolation.INTERPOLATION_NearestNeighbour;
239
                case 1: return BufferInterpolation.INTERPOLATION_Bilinear;
240
                case 2: return BufferInterpolation.INTERPOLATION_InverseDistance;
241
                case 3: return BufferInterpolation.INTERPOLATION_BSpline;
242
                }
243
                return BufferInterpolation.INTERPOLATION_Undefined;
244
        }
245

    
246
        /**
247
         * Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
248
         * y con el n?mero de decimales que se especifica en el par?metro dec
249
         * @param cellSize Tama?o de celda en double
250
         * @param dec N?mero de decimales
251
         */
252
        public void setCellSizeText(double cellSize, int dec) {
253
                int indexPoint = String.valueOf(cellSize).indexOf('.');
254
                try {
255
                        cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec));
256
                } catch (StringIndexOutOfBoundsException ex) {
257
                        cCellSize.setValue(String.valueOf(cellSize));
258
                }
259
        }
260

    
261
        /**
262
         * Asigna el valor del campo "Ancho" a partir del double que lo representa
263
         * y con el n?mero de decimales que se especifica en el par?metro dec
264
         * @param width Ancho
265
         * @param dec N?mero de decimales
266
         */
267
        public void setWidthText(double width, int dec) {
268
                int indexPoint = String.valueOf(width).indexOf('.');
269
                try {
270
                        cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec));
271
                } catch (StringIndexOutOfBoundsException ex) {
272
                        cWidth.setValue(String.valueOf(width));
273
                }
274
        }
275

    
276
        /**
277
         * Asigna el valor del campo "Alto" a partir del double que lo representa
278
         * y con el n?mero de decimales que se especifica en el par?metro dec
279
         * @param height Alto
280
         * @param dec N?mero de decimales
281
         */
282
        public void setHeightText(double height, int dec) {
283
                int indexPoint = String.valueOf(height).indexOf('.');
284
                try {
285
                        cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec));
286
                } catch (StringIndexOutOfBoundsException ex) {
287
                        cHeight.setValue(String.valueOf(height));
288
                }
289
        }
290

    
291
        /**
292
         * Devuelve el valor del campo "tama?o de celda"
293
         *
294
         * @return
295
         */
296
        public double getCellSizeText(){
297
                return Double.parseDouble(cCellSize.getValue());
298
        }
299

    
300
        /**
301
         * Devuelve el valor del campo "tama?o de celda"
302
         * @return
303
         */
304
        public double getWidthText(){
305
                return Double.parseDouble(cWidth.getValue());
306
        }
307

    
308
        /**
309
         * Devuelve el valor del campo "tama?o de celda"
310
         * @return
311
         */
312
        public double getHeightText(){
313
                return Double.parseDouble(cHeight.getValue());
314
        }
315

    
316
        /**
317
         * Devuelve los valores de Alto x Acho de la resoluci?n espacial
318
         * @return
319
         */
320
        public String[] getWidthHeight(){
321
                String[] text= { this.cWidth.getValue(),
322
                                                this.cHeight.getValue()
323
                                                };
324
                return text;
325
        }
326

    
327
        /**
328
         * Devuelve el metodo de interpolacion.
329
         * @return
330
         */
331
        public String getInterpolation(){
332
                return (String)this.getJComboBox().getSelectedItem();
333
        }
334

    
335
        /**************************************************************/
336
        /********************Listeners*********************************/
337
        /**************************************************************/
338

    
339
        public void actionPerformed(ActionEvent e) {
340
                if (e.getSource() == this.getRSize()) {
341
                        this.getRSize().setSelected(true);
342
                        this.getRWidthH().setSelected(false);
343
                        cCellSize.setControlEnabled(true);
344
                        cHeight.setControlEnabled(false);
345
                        cWidth.setControlEnabled(false);
346
                }
347
                if (e.getSource() == this.getRWidthH()) {
348
                        this.getRWidthH().setSelected(true);
349
                        this.getRSize().setSelected(false);
350
                        cCellSize.setControlEnabled(false);
351
                        cHeight.setControlEnabled(true);
352
                        cWidth.setControlEnabled(true);
353
                }
354
        }
355
}