svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / ui / ResolutionPanel.java @ 11352
History | View | Annotate | Download (13.7 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.BaseComponent; |
33 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
34 |
|
35 |
import com.iver.andami.PluginServices; |
36 |
/**
|
37 |
* Panel para controlar las redimensiones por interpolaci?n
|
38 |
*
|
39 |
* @version 17/04/2007
|
40 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
41 |
*/
|
42 |
public class ResolutionPanel extends BaseComponent 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.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)); |
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, "bicubico")); |
356 |
cInterpolation.addItem(PluginServices.getText(this, "b_splines")); |
357 |
|
358 |
} |
359 |
return cInterpolation;
|
360 |
} |
361 |
|
362 |
/**
|
363 |
* Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
|
364 |
* y con el n?mero de decimales que se especifica en el par?metro dec
|
365 |
* @param cellSize Tama?o de celda en double
|
366 |
* @param dec N?mero de decimales
|
367 |
*/
|
368 |
public void setCellSizeText(double cellSize, int dec) { |
369 |
int indexPoint = String.valueOf(cellSize).indexOf('.'); |
370 |
try {
|
371 |
cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec)); |
372 |
} catch (StringIndexOutOfBoundsException ex) { |
373 |
cCellSize.setValue(String.valueOf(cellSize));
|
374 |
} |
375 |
} |
376 |
|
377 |
/**
|
378 |
* Asigna el valor del campo "Ancho" 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 width Ancho
|
381 |
* @param dec N?mero de decimales
|
382 |
*/
|
383 |
public void setWidthText(double width, int dec) { |
384 |
int indexPoint = String.valueOf(width).indexOf('.'); |
385 |
try {
|
386 |
cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec)); |
387 |
} catch (StringIndexOutOfBoundsException ex) { |
388 |
cWidth.setValue(String.valueOf(width));
|
389 |
} |
390 |
} |
391 |
|
392 |
/**
|
393 |
* Asigna el valor del campo "Alto" 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 height Alto
|
396 |
* @param dec N?mero de decimales
|
397 |
*/
|
398 |
public void setHeightText(double height, int dec) { |
399 |
int indexPoint = String.valueOf(height).indexOf('.'); |
400 |
try {
|
401 |
cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec)); |
402 |
} catch (StringIndexOutOfBoundsException ex) { |
403 |
cHeight.setValue(String.valueOf(height));
|
404 |
} |
405 |
} |
406 |
|
407 |
/**
|
408 |
* Devuelve el valor del campo "tama?o de celda"
|
409 |
*
|
410 |
* @return
|
411 |
*/
|
412 |
public double getCellSizeText(){ |
413 |
return Double.parseDouble(cCellSize.getValue()); |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Devuelve el valor del campo "tama?o de celda"
|
418 |
* @return
|
419 |
*/
|
420 |
public double getWidthText(){ |
421 |
return Double.parseDouble(cWidth.getValue()); |
422 |
} |
423 |
|
424 |
/**
|
425 |
* Devuelve el valor del campo "tama?o de celda"
|
426 |
* @return
|
427 |
*/
|
428 |
public double getHeightText(){ |
429 |
return Double.parseDouble(cHeight.getValue()); |
430 |
} |
431 |
|
432 |
/**
|
433 |
* Devuelve los valores de Alto x Acho de la resoluci?n espacial
|
434 |
* @return
|
435 |
*/
|
436 |
public String[] getWidthHeight(){ |
437 |
String[] text= { this.cWidth.getValue(), |
438 |
this.cHeight.getValue()
|
439 |
}; |
440 |
return text;
|
441 |
} |
442 |
|
443 |
/**
|
444 |
* Devuelve el metodo de interpolacion.
|
445 |
* @return
|
446 |
*/
|
447 |
public String getInterpolation(){ |
448 |
return (String)this.getJComboBox().getSelectedItem(); |
449 |
} |
450 |
|
451 |
/**************************************************************/
|
452 |
/********************Listeners*********************************/
|
453 |
/**************************************************************/
|
454 |
|
455 |
public void actionPerformed(ActionEvent e) { |
456 |
if (e.getSource() == this.getRSize()) { |
457 |
this.getRSize().setSelected(true); |
458 |
this.getRWidthH().setSelected(false); |
459 |
cCellSize.setControlEnabled(true);
|
460 |
cHeight.setControlEnabled(false);
|
461 |
cWidth.setControlEnabled(false);
|
462 |
} |
463 |
if (e.getSource() == this.getRWidthH()) { |
464 |
this.getRWidthH().setSelected(true); |
465 |
this.getRSize().setSelected(false); |
466 |
cCellSize.setControlEnabled(false);
|
467 |
cHeight.setControlEnabled(true);
|
468 |
cWidth.setControlEnabled(true);
|
469 |
} |
470 |
} |
471 |
} |