root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / panels / CuttingResolutionPanel.java @ 14072
History | View | Annotate | Download (11.6 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.panels; |
20 |
|
21 |
import java.awt.GridBagConstraints; |
22 |
import java.awt.Insets; |
23 |
import java.awt.event.ActionEvent; |
24 |
import java.awt.event.ActionListener; |
25 |
|
26 |
import javax.swing.JButton; |
27 |
import javax.swing.JComboBox; |
28 |
import javax.swing.JLabel; |
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 BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
42 |
*/
|
43 |
public class CuttingResolutionPanel extends JPanel implements ActionListener { |
44 |
private static final long serialVersionUID = 2570616093263451091L; |
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 |
private JButton buttonRestore = null; |
53 |
|
54 |
/**
|
55 |
* This is the default constructor
|
56 |
*/
|
57 |
public CuttingResolutionPanel() {
|
58 |
initialize(); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* This method initializes this
|
63 |
* @return void
|
64 |
*/
|
65 |
private void initialize() { |
66 |
GridBagConstraints gridBagConstraints;
|
67 |
|
68 |
setLayout(new java.awt.GridBagLayout());
|
69 |
|
70 |
gridBagConstraints = new GridBagConstraints(); |
71 |
gridBagConstraints.gridwidth = 2;
|
72 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
73 |
gridBagConstraints.ipadx = 200;
|
74 |
gridBagConstraints.ipady = 25;
|
75 |
gridBagConstraints.insets = new Insets(5, 5, 2, 5); |
76 |
add(getPButtons(), gridBagConstraints); |
77 |
|
78 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
79 |
gridBagConstraints.gridx = 1;
|
80 |
gridBagConstraints.gridy = 1;
|
81 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
82 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 5); |
83 |
add(getJComboBox(), gridBagConstraints); |
84 |
|
85 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
86 |
gridBagConstraints.gridx = 0;
|
87 |
gridBagConstraints.gridy = 2;
|
88 |
gridBagConstraints.gridwidth = 2;
|
89 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
90 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
91 |
add(getCCellSize(), gridBagConstraints); |
92 |
|
93 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
94 |
gridBagConstraints.gridx = 0;
|
95 |
gridBagConstraints.gridy = 3;
|
96 |
gridBagConstraints.gridwidth = 2;
|
97 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
98 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
99 |
add(getCWidth(), gridBagConstraints); |
100 |
|
101 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
102 |
gridBagConstraints.gridx = 0;
|
103 |
gridBagConstraints.gridy = 4;
|
104 |
gridBagConstraints.gridwidth = 2;
|
105 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
106 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
107 |
add(getCHeight(), gridBagConstraints); |
108 |
|
109 |
JLabel jLabel = new JLabel(); |
110 |
jLabel.setText(PluginServices.getText(this, "interpolacion") + ":"); |
111 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
112 |
gridBagConstraints.gridx = 0;
|
113 |
gridBagConstraints.gridy = 1;
|
114 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
115 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 2); |
116 |
add(jLabel, gridBagConstraints); |
117 |
|
118 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
119 |
gridBagConstraints.gridx = 0;
|
120 |
gridBagConstraints.gridy = 5;
|
121 |
gridBagConstraints.gridwidth = 2;
|
122 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 5); |
123 |
add(getButtonRestore(), gridBagConstraints); |
124 |
|
125 |
getRSize().addActionListener(this);
|
126 |
getRWidthH().addActionListener(this);
|
127 |
getRSize().setSelected(true);
|
128 |
getCWidth().setControlEnabled(false);
|
129 |
getCHeight().setControlEnabled(false);
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* This method initializes jPanel1
|
134 |
* @return javax.swing.JPanel
|
135 |
*/
|
136 |
public DataInputContainer getCCellSize() {
|
137 |
if (cCellSize == null) { |
138 |
cCellSize = new DataInputContainer();
|
139 |
cCellSize.setLabelText(PluginServices.getText(this, "celda")); |
140 |
} |
141 |
return cCellSize;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method initializes jPanel2
|
146 |
* @return javax.swing.JPanel
|
147 |
*/
|
148 |
public DataInputContainer getCHeight() {
|
149 |
if (cHeight == null) { |
150 |
cHeight = new DataInputContainer();
|
151 |
cHeight.setLabelText(PluginServices.getText(this, "alto")); |
152 |
} |
153 |
return cHeight;
|
154 |
} |
155 |
|
156 |
public JButton getButtonRestore() { |
157 |
if (buttonRestore == null) { |
158 |
buttonRestore = new JButton(PluginServices.getText(this, "restablecer")); |
159 |
} |
160 |
return buttonRestore;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* This method initializes jPanel
|
165 |
* @return javax.swing.JPanel
|
166 |
*/
|
167 |
public DataInputContainer getCWidth() {
|
168 |
if (cWidth == null) { |
169 |
cWidth = new DataInputContainer();
|
170 |
cWidth.setLabelText(PluginServices.getText(this, "ancho")); |
171 |
} |
172 |
return cWidth;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* This method initializes jPanel
|
177 |
* @return javax.swing.JPanel
|
178 |
*/
|
179 |
private JPanel getPButtons() { |
180 |
if (pButtons == null) { |
181 |
pButtons = new JPanel(); |
182 |
pButtons.setLayout(new java.awt.GridBagLayout());
|
183 |
pButtons.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
|
184 |
|
185 |
GridBagConstraints gridBagConstraints;
|
186 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
187 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
188 |
gridBagConstraints.weightx = 1.0;
|
189 |
pButtons.add(getRSize(), gridBagConstraints); |
190 |
|
191 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
192 |
gridBagConstraints.gridx = 0;
|
193 |
gridBagConstraints.gridy = 1;
|
194 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
195 |
pButtons.add(getRWidthH(), gridBagConstraints); |
196 |
; |
197 |
} |
198 |
return pButtons;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* This method initializes jRadioButton
|
203 |
* @return javax.swing.JRadioButton
|
204 |
*/
|
205 |
private JRadioButton getRSize() { |
206 |
if (rSize == null) { |
207 |
rSize = new JRadioButton(PluginServices.getText(this, "tamanyo_celda")); |
208 |
} |
209 |
return rSize;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* This method initializes jRadioButton1
|
214 |
* @return javax.swing.JRadioButton
|
215 |
*/
|
216 |
private JRadioButton getRWidthH() { |
217 |
if (rWidthH == null) { |
218 |
rWidthH = new JRadioButton(PluginServices.getText(this, "ancho_x_alto")); |
219 |
} |
220 |
return rWidthH;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* This method initializes jComboBox
|
225 |
* @return javax.swing.JComboBox
|
226 |
*/
|
227 |
private JComboBox getJComboBox() { |
228 |
if (cInterpolation == null) { |
229 |
cInterpolation = new JComboBox(); |
230 |
cInterpolation.addItem(PluginServices.getText(this, "vecino_+_proximo")); |
231 |
cInterpolation.addItem(PluginServices.getText(this, "bilinear")); |
232 |
cInterpolation.addItem(PluginServices.getText(this, "distancia_inversa")); |
233 |
cInterpolation.addItem(PluginServices.getText(this, "b_splines")); |
234 |
// cInterpolation.addItem(PluginServices.getText(this, "bicubico"));
|
235 |
} |
236 |
return cInterpolation;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
* Obtiene el valor correspondiente al m?todo de interpolaci?n seleccionado en
|
241 |
* el JComboBox
|
242 |
* @return M?todo de interpolaci?n interpretable con las variables definidas
|
243 |
* en BufferInterpolation.
|
244 |
*/
|
245 |
public int getSelectedInterpolationMethod() { |
246 |
switch (getJComboBox().getSelectedIndex()) {
|
247 |
case 0: |
248 |
return BufferInterpolation.INTERPOLATION_NearestNeighbour;
|
249 |
case 1: |
250 |
return BufferInterpolation.INTERPOLATION_Bilinear;
|
251 |
case 2: |
252 |
return BufferInterpolation.INTERPOLATION_InverseDistance;
|
253 |
case 3: |
254 |
return BufferInterpolation.INTERPOLATION_BSpline;
|
255 |
} |
256 |
return BufferInterpolation.INTERPOLATION_Undefined;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* Asigna el valor del campo "tama?o de celda" a partir del double que lo
|
261 |
* representa y con el n?mero de decimales que se especifica en el par?metro
|
262 |
* dec
|
263 |
* @param cellSize Tama?o de celda en double
|
264 |
* @param dec N?mero de decimales
|
265 |
*/
|
266 |
public void setCellSizeText(double cellSize, int dec) { |
267 |
int indexPoint = String.valueOf(cellSize).indexOf('.'); |
268 |
try {
|
269 |
cCellSize.setValue(String.valueOf(cellSize).substring(0, indexPoint + dec)); |
270 |
} catch (StringIndexOutOfBoundsException ex) { |
271 |
cCellSize.setValue(String.valueOf(cellSize));
|
272 |
} |
273 |
} |
274 |
|
275 |
/**
|
276 |
* Asigna el valor del campo "Ancho" a partir del double que lo representa y
|
277 |
* con el n?mero de decimales que se especifica en el par?metro dec
|
278 |
* @param width Ancho
|
279 |
* @param dec N?mero de decimales
|
280 |
*/
|
281 |
public void setWidthText(double width, int dec) { |
282 |
int indexPoint = String.valueOf(width).indexOf('.'); |
283 |
try {
|
284 |
cWidth.setValue(String.valueOf(width).substring(0, indexPoint + dec)); |
285 |
} catch (StringIndexOutOfBoundsException ex) { |
286 |
cWidth.setValue(String.valueOf(width));
|
287 |
} |
288 |
} |
289 |
|
290 |
/**
|
291 |
* Asigna el valor del campo "Alto" a partir del double que lo representa y
|
292 |
* con el n?mero de decimales que se especifica en el par?metro dec
|
293 |
* @param height Alto
|
294 |
* @param dec N?mero de decimales
|
295 |
*/
|
296 |
public void setHeightText(double height, int dec) { |
297 |
int indexPoint = String.valueOf(height).indexOf('.'); |
298 |
try {
|
299 |
cHeight.setValue(String.valueOf(height).substring(0, indexPoint + dec)); |
300 |
} catch (StringIndexOutOfBoundsException ex) { |
301 |
cHeight.setValue(String.valueOf(height));
|
302 |
} |
303 |
} |
304 |
|
305 |
/**
|
306 |
* Devuelve el valor del campo "tama?o de celda"
|
307 |
* @return
|
308 |
*/
|
309 |
public double getCellSizeText() { |
310 |
return Double.parseDouble(cCellSize.getValue()); |
311 |
} |
312 |
|
313 |
/**
|
314 |
* Devuelve el valor del campo "tama?o de celda"
|
315 |
* @return
|
316 |
*/
|
317 |
public double getWidthText() { |
318 |
return Double.parseDouble(cWidth.getValue()); |
319 |
} |
320 |
|
321 |
/**
|
322 |
* Devuelve el valor del campo "tama?o de celda"
|
323 |
* @return
|
324 |
*/
|
325 |
public double getHeightText() { |
326 |
return Double.parseDouble(cHeight.getValue()); |
327 |
} |
328 |
|
329 |
/**
|
330 |
* Devuelve los valores de Alto x Acho de la resoluci?n espacial
|
331 |
* @return
|
332 |
*/
|
333 |
public String[] getWidthHeight() { |
334 |
String[] text = { cWidth.getValue(), cHeight.getValue() }; |
335 |
return text;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* Devuelve el metodo de interpolacion.
|
340 |
* @return
|
341 |
*/
|
342 |
public String getInterpolation() { |
343 |
return (String) getJComboBox().getSelectedItem(); |
344 |
} |
345 |
|
346 |
/*
|
347 |
* (non-Javadoc)
|
348 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
349 |
*/
|
350 |
public void actionPerformed(ActionEvent e) { |
351 |
if (e.getSource() == getRSize()) {
|
352 |
getRSize().setSelected(true);
|
353 |
getRWidthH().setSelected(false);
|
354 |
cCellSize.setControlEnabled(true);
|
355 |
cHeight.setControlEnabled(false);
|
356 |
cWidth.setControlEnabled(false);
|
357 |
} |
358 |
if (e.getSource() == getRWidthH()) {
|
359 |
getRWidthH().setSelected(true);
|
360 |
getRSize().setSelected(false);
|
361 |
cCellSize.setControlEnabled(false);
|
362 |
cHeight.setControlEnabled(true);
|
363 |
cWidth.setControlEnabled(true);
|
364 |
} |
365 |
} |
366 |
} |