Revision 153 org.gvsig.toolbox/trunk/org.gvsig.toolbox/org.gvsig.toolbox.gui/src/main/java/es/unex/sextante/gui/algorithm/AnalysisExtentPanel.java
AnalysisExtentPanel.java | ||
---|---|---|
1 |
|
|
2 |
|
|
3 | 1 |
package es.unex.sextante.gui.algorithm; |
4 | 2 |
|
5 | 3 |
import info.clearthought.layout.TableLayout; |
... | ... | |
38 | 36 |
import es.unex.sextante.outputs.Output; |
39 | 37 |
import es.unex.sextante.outputs.OutputRasterLayer; |
40 | 38 |
|
41 |
|
|
42 | 39 |
/** |
43 |
* A panel to select a extent to be used for generating output layers from a given algorithm |
|
40 |
* A panel to select a extent to be used for generating output layers from a |
|
41 |
* given algorithm |
|
44 | 42 |
* |
45 | 43 |
* @author volaya |
46 |
* |
|
47 | 44 |
*/ |
48 |
public class AnalysisExtentPanel |
|
49 |
extends |
|
50 |
javax.swing.JPanel { |
|
45 |
public class AnalysisExtentPanel extends javax.swing.JPanel { |
|
51 | 46 |
|
52 |
protected static final int BIG_SIZE = 10000000;
|
|
47 |
protected static final int BIG_SIZE = 10000000;
|
|
53 | 48 |
|
54 |
private JTextField jTextFieldCols; |
|
55 |
private JTextField jTextFieldRows; |
|
56 |
protected JTextField jTextFieldCellSize; |
|
57 |
protected JTextField jTextFieldXMax; |
|
58 |
protected JTextField jTextFieldXMin; |
|
59 |
protected JTextField jTextFieldYMax; |
|
60 |
protected JTextField jTextFieldYMin; |
|
61 |
private JLabel jLabelRowsCols; |
|
62 |
private JLabel jLabelCellSize; |
|
63 |
private JLabel jLabelRangeY; |
|
64 |
private JLabel jLabelRangeX; |
|
65 |
protected JComboBox jComboBoxLayers; |
|
66 |
private JComboBox jComboBoxViews; |
|
67 |
protected JPanel jPanelAnalysisExtentValues; |
|
68 |
private JPanel jPanelAnalysisExtentOptions; |
|
69 |
private JRadioButton jRadioButtonAdjustToInputDataExtent; |
|
70 |
private JRadioButton jRadioButtonViewExtent; |
|
71 |
private JRadioButton jRadioButtonUserDefinedExtent; |
|
72 |
private JRadioButton jRadioButtonExtentFromLayer; |
|
73 |
private ButtonGroup jButtonGroup; |
|
49 |
private JTextField jTextFieldCols; |
|
74 | 50 |
|
75 |
protected final GeoAlgorithm m_Algorithm; |
|
76 |
protected final ILayer[] m_Layers; |
|
51 |
private JTextField jTextFieldRows; |
|
77 | 52 |
|
53 |
protected JTextField jTextFieldCellSize; |
|
78 | 54 |
|
79 |
/** |
|
80 |
* Creates a new panel |
|
81 |
* |
|
82 |
* @param algorithm |
|
83 |
* the algorithm |
|
84 |
*/ |
|
85 |
public AnalysisExtentPanel(final GeoAlgorithm algorithm) { |
|
55 |
protected JTextField jTextFieldXMax; |
|
86 | 56 |
|
87 |
super();
|
|
57 |
protected JTextField jTextFieldXMin;
|
|
88 | 58 |
|
89 |
m_Layers = SextanteGUI.getInputFactory().getLayers(); |
|
90 |
m_Algorithm = algorithm; |
|
59 |
protected JTextField jTextFieldYMax; |
|
91 | 60 |
|
92 |
initGUI();
|
|
61 |
protected JTextField jTextFieldYMin;
|
|
93 | 62 |
|
94 |
}
|
|
63 |
private JLabel jLabelRowsCols;
|
|
95 | 64 |
|
65 |
private JLabel jLabelCellSize; |
|
96 | 66 |
|
97 |
private void initGUI() {
|
|
67 |
private JLabel jLabelRangeY;
|
|
98 | 68 |
|
99 |
final TableLayout jPanelParametersRasterLayout = new TableLayout(new double[][] { { 1.0, TableLayoutConstants.FILL, 1.0 }, |
|
100 |
{ 1.0, TableLayoutConstants.MINIMUM, TableLayoutConstants.FILL, 1.0 } }); |
|
101 |
jPanelParametersRasterLayout.setHGap(5); |
|
102 |
jPanelParametersRasterLayout.setVGap(5); |
|
103 |
this.setLayout(jPanelParametersRasterLayout); |
|
69 |
private JLabel jLabelRangeX; |
|
104 | 70 |
|
105 |
this.add(getJPanelAnalysisExtentOptions(), "1, 1"); |
|
106 |
this.add(getJPanelAnalysisExtentValues(), "1, 2"); |
|
107 |
if (m_Algorithm.canDefineOutputExtentFromInput()) { |
|
108 |
getJPanelAnalysisExtentValues().setVisible(false); |
|
109 |
} |
|
110 |
else { |
|
111 |
getJPanelAnalysisExtentValues().setVisible(true); |
|
112 |
} |
|
71 |
protected JComboBox jComboBoxLayers; |
|
113 | 72 |
|
114 |
}
|
|
73 |
private JComboBox jComboBoxViews;
|
|
115 | 74 |
|
75 |
protected JPanel jPanelAnalysisExtentValues; |
|
116 | 76 |
|
117 |
/** |
|
118 |
* Assigns the selected extent to the algorithm |
|
119 |
* |
|
120 |
* @throws TooLargeGridExtentException |
|
121 |
* if the dimensions of the extent are too large (too many cells) and the user should be queried to make sure |
|
122 |
* that the input values are correct |
|
123 |
* @throws WrongAnalysisExtentException |
|
124 |
* if the input values are not correct |
|
125 |
*/ |
|
126 |
public void assignExtent() throws TooLargeGridExtentException, WrongAnalysisExtentException { |
|
77 |
private JPanel jPanelAnalysisExtentOptions; |
|
127 | 78 |
|
128 |
m_Algorithm.setAnalysisExtent((AnalysisExtent) null);
|
|
79 |
private JRadioButton jRadioButtonAdjustToInputDataExtent;
|
|
129 | 80 |
|
130 |
if (getJRadioButtonAdjustToInputDataExtent().isSelected()) { |
|
131 |
if (!m_Algorithm.adjustOutputExtent()) { |
|
132 |
throw new WrongAnalysisExtentException(Sextante.getText("Wrong_or_missing_region")); |
|
133 |
} |
|
134 |
else { |
|
135 |
return; |
|
136 |
} |
|
81 |
private JRadioButton jRadioButtonViewExtent; |
|
137 | 82 |
|
138 |
}
|
|
83 |
private JRadioButton jRadioButtonUserDefinedExtent;
|
|
139 | 84 |
|
140 |
final AnalysisExtent outputExtent = new AnalysisExtent(); |
|
141 |
try { |
|
142 |
outputExtent.setCellSize(Double.parseDouble(jTextFieldCellSize.getText())); |
|
143 |
outputExtent.setXRange(Double.parseDouble(jTextFieldXMin.getText()), Double.parseDouble(jTextFieldXMax.getText()), true); |
|
144 |
outputExtent.setYRange(Double.parseDouble(jTextFieldYMin.getText()), Double.parseDouble(jTextFieldYMax.getText()), true); |
|
145 |
m_Algorithm.setAnalysisExtent(outputExtent); |
|
146 |
} |
|
147 |
catch (final NumberFormatException e) { |
|
148 |
//Sextante.addErrorToLog(e); |
|
149 |
if (m_Algorithm instanceof GrassAlgorithm) { |
|
150 |
//GRASS vector output modules can always fall back to a default extent |
|
151 |
outputExtent.setXRange(0.0, 1.0, true); |
|
152 |
outputExtent.setYRange(0.0, 1.0, true); |
|
153 |
m_Algorithm.setAnalysisExtent(outputExtent); |
|
154 |
if (m_Algorithm.getName().contains("v.in.region")) { |
|
155 |
//we absolutely need a region for these commands! |
|
156 |
throw new WrongAnalysisExtentException(Sextante.getText("Wrong_or_missing_region")); |
|
157 |
} |
|
158 |
for (int i = 0; i < m_Algorithm.getNumberOfOutputObjects(); i++) { |
|
159 |
final Output out = m_Algorithm.getOutputObjects().getOutput(i); |
|
160 |
//Raster import modules also do not need an extent setting |
|
161 |
if ((out instanceof OutputRasterLayer) && !m_Algorithm.getName().contains("r.in.")) { |
|
162 |
//But if we have another raster output, then we need an extent! |
|
163 |
throw new WrongAnalysisExtentException(Sextante.getText("Wrong_or_missing_region")); |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
else { |
|
168 |
throw new WrongAnalysisExtentException(Sextante.getText("Wrong_or_missing_raster_extent_definition")); |
|
169 |
} |
|
170 |
} |
|
85 |
private JRadioButton jRadioButtonExtentFromLayer; |
|
171 | 86 |
|
172 |
final int numCells = outputExtent.getNX() * outputExtent.getNY(); |
|
173 |
/* benducke: let's just assume the other knows what (s)he is doing... |
|
174 |
if ((numCells > BIG_SIZE) || (Integer.MAX_VALUE / outputExtent.getNY() < outputExtent.getNX())) { |
|
175 |
throw new TooLargeGridExtentException(Sextante.getText("The_selected_grid_extent_seems_too_large") + "(" |
|
176 |
+ Integer.toString(outputExtent.getNX()) + " X " |
|
177 |
+ Integer.toString(outputExtent.getNY()) + ")\n" |
|
178 |
+ Sextante.getText("Are_you_sure_you_want_to_use_it?")); |
|
179 |
} |
|
180 |
*/ |
|
181 |
} |
|
87 |
private ButtonGroup jButtonGroup; |
|
182 | 88 |
|
89 |
protected final GeoAlgorithm m_Algorithm; |
|
183 | 90 |
|
184 |
private ButtonGroup getJButtonGroup() {
|
|
91 |
protected final ILayer[] m_Layers;
|
|
185 | 92 |
|
186 |
if (jButtonGroup == null) { |
|
187 |
jButtonGroup = new ButtonGroup(); |
|
188 |
} |
|
189 |
return jButtonGroup; |
|
93 |
/** |
|
94 |
* Creates a new panel |
|
95 |
* |
|
96 |
* @param algorithm the algorithm |
|
97 |
*/ |
|
98 |
public AnalysisExtentPanel(final GeoAlgorithm algorithm) { |
|
190 | 99 |
|
191 |
}
|
|
100 |
super();
|
|
192 | 101 |
|
102 |
m_Layers = SextanteGUI.getInputFactory().getLayers(); |
|
103 |
m_Algorithm = algorithm; |
|
193 | 104 |
|
194 |
protected JRadioButton getJRadioButtonUserDefinedExtent() {
|
|
105 |
initGUI();
|
|
195 | 106 |
|
196 |
if (jRadioButtonUserDefinedExtent == null) { |
|
197 |
jRadioButtonUserDefinedExtent = new JRadioButton(); |
|
198 |
jRadioButtonUserDefinedExtent.setText(Sextante.getText("User_defined")); |
|
199 |
jRadioButtonUserDefinedExtent.addActionListener(new java.awt.event.ActionListener() { |
|
200 |
public void actionPerformed(final java.awt.event.ActionEvent e) { |
|
201 |
setTextFieldsEnabled(true); |
|
202 |
extentHasChanged(); |
|
203 |
} |
|
204 |
}); |
|
205 |
} |
|
107 |
} |
|
206 | 108 |
|
109 |
private void initGUI() { |
|
207 | 110 |
|
208 |
return jRadioButtonUserDefinedExtent; |
|
209 |
} |
|
111 |
final TableLayout jPanelParametersRasterLayout = new TableLayout( |
|
112 |
new double[][] { |
|
113 |
{ 1.0, TableLayoutConstants.FILL, 1.0 }, |
|
114 |
{ 1.0, TableLayoutConstants.MINIMUM, TableLayoutConstants.FILL, 1.0 } }); |
|
115 |
jPanelParametersRasterLayout.setHGap(5); |
|
116 |
jPanelParametersRasterLayout.setVGap(5); |
|
117 |
this.setLayout(jPanelParametersRasterLayout); |
|
210 | 118 |
|
119 |
this.add(getJPanelAnalysisExtentOptions(), "1, 1"); |
|
120 |
this.add(getJPanelAnalysisExtentValues(), "1, 2"); |
|
121 |
if (m_Algorithm.canDefineOutputExtentFromInput()) { |
|
122 |
getJPanelAnalysisExtentValues().setVisible(false); |
|
123 |
} |
|
124 |
else { |
|
125 |
getJPanelAnalysisExtentValues().setVisible(true); |
|
126 |
} |
|
211 | 127 |
|
212 |
protected JRadioButton getJRadioButtonAdjustToInputDataExtent() {
|
|
128 |
}
|
|
213 | 129 |
|
214 |
if (jRadioButtonAdjustToInputDataExtent == null) { |
|
215 |
jRadioButtonAdjustToInputDataExtent = new JRadioButton(); |
|
216 |
jRadioButtonAdjustToInputDataExtent.setText(Sextante.getText("Fit_to_input_layers")); |
|
217 |
jRadioButtonAdjustToInputDataExtent.addActionListener(new java.awt.event.ActionListener() { |
|
218 |
public void actionPerformed(final java.awt.event.ActionEvent e) { |
|
219 |
getJPanelAnalysisExtentValues().setVisible(false); |
|
220 |
} |
|
221 |
}); |
|
222 |
} |
|
130 |
/** |
|
131 |
* Assigns the selected extent to the algorithm |
|
132 |
* |
|
133 |
* @throws TooLargeGridExtentException if the dimensions of the extent are too |
|
134 |
* large (too many cells) and the user should be queried to make |
|
135 |
* sure that the input values are correct |
|
136 |
* @throws WrongAnalysisExtentException if the input values are not correct |
|
137 |
*/ |
|
138 |
public void assignExtent() throws TooLargeGridExtentException, |
|
139 |
WrongAnalysisExtentException { |
|
223 | 140 |
|
141 |
m_Algorithm.setAnalysisExtent((AnalysisExtent) null); |
|
224 | 142 |
|
225 |
return jRadioButtonAdjustToInputDataExtent; |
|
226 |
} |
|
143 |
if (getJRadioButtonAdjustToInputDataExtent().isSelected()) { |
|
144 |
if (!m_Algorithm.adjustOutputExtent()) { |
|
145 |
throw new WrongAnalysisExtentException( |
|
146 |
Sextante.getText("Wrong_or_missing_region")); |
|
147 |
} |
|
148 |
else { |
|
149 |
return; |
|
150 |
} |
|
227 | 151 |
|
152 |
} |
|
228 | 153 |
|
229 |
private JRadioButton getJRadioButtonViewExtent() { |
|
230 |
if (jRadioButtonViewExtent == null) { |
|
231 |
jRadioButtonViewExtent = new JRadioButton(); |
|
232 |
jRadioButtonViewExtent.setText(Sextante.getText("Use_extent_from_view")); |
|
233 |
jRadioButtonViewExtent.addActionListener(new java.awt.event.ActionListener() { |
|
234 |
public void actionPerformed(final java.awt.event.ActionEvent evt) { |
|
235 |
try { |
|
236 |
getJComboBoxViews().setSelectedIndex(getJComboBoxViews().getSelectedIndex()); |
|
237 |
setTextFieldsEnabled(false); |
|
238 |
} |
|
239 |
catch (final Exception e) { |
|
240 |
} |
|
241 |
} |
|
242 |
}); |
|
154 |
final AnalysisExtent outputExtent = new AnalysisExtent(); |
|
155 |
try { |
|
156 |
outputExtent |
|
157 |
.setCellSize(Double.parseDouble(jTextFieldCellSize.getText())); |
|
158 |
outputExtent.setXRange(Double.parseDouble(jTextFieldXMin.getText()), |
|
159 |
Double.parseDouble(jTextFieldXMax.getText()), true); |
|
160 |
outputExtent.setYRange(Double.parseDouble(jTextFieldYMin.getText()), |
|
161 |
Double.parseDouble(jTextFieldYMax.getText()), true); |
|
162 |
m_Algorithm.setAnalysisExtent(outputExtent); |
|
163 |
} |
|
164 |
catch (final NumberFormatException e) { |
|
165 |
// Sextante.addErrorToLog(e); |
|
166 |
if (m_Algorithm instanceof GrassAlgorithm) { |
|
167 |
// GRASS vector output modules can always fall back to a default extent |
|
168 |
outputExtent.setXRange(0.0, 1.0, true); |
|
169 |
outputExtent.setYRange(0.0, 1.0, true); |
|
170 |
m_Algorithm.setAnalysisExtent(outputExtent); |
|
171 |
if (m_Algorithm.getName().contains("v.in.region")) { |
|
172 |
// we absolutely need a region for these commands! |
|
173 |
throw new WrongAnalysisExtentException( |
|
174 |
Sextante.getText("Wrong_or_missing_region")); |
|
175 |
} |
|
176 |
for (int i = 0; i < m_Algorithm.getNumberOfOutputObjects(); i++) { |
|
177 |
final Output out = m_Algorithm.getOutputObjects().getOutput(i); |
|
178 |
// Raster import modules also do not need an extent setting |
|
179 |
if ((out instanceof OutputRasterLayer) |
|
180 |
&& !m_Algorithm.getName().contains("r.in.")) { |
|
181 |
// But if we have another raster output, then we need an extent! |
|
182 |
throw new WrongAnalysisExtentException( |
|
183 |
Sextante.getText("Wrong_or_missing_region")); |
|
184 |
} |
|
185 |
} |
|
243 | 186 |
} |
244 |
return jRadioButtonViewExtent; |
|
245 |
} |
|
187 |
else { |
|
188 |
throw new WrongAnalysisExtentException( |
|
189 |
Sextante.getText("Wrong_or_missing_raster_extent_definition")); |
|
190 |
} |
|
191 |
} |
|
246 | 192 |
|
193 |
final int numCells = outputExtent.getNX() * outputExtent.getNY(); |
|
194 |
/* |
|
195 |
* benducke: let's just assume the other knows what (s)he is doing... if |
|
196 |
* ((numCells > BIG_SIZE) || (Integer.MAX_VALUE / outputExtent.getNY() < |
|
197 |
* outputExtent.getNX())) { throw new |
|
198 |
* TooLargeGridExtentException(Sextante.getText |
|
199 |
* ("The_selected_grid_extent_seems_too_large") + "(" + |
|
200 |
* Integer.toString(outputExtent.getNX()) + " X " + |
|
201 |
* Integer.toString(outputExtent.getNY()) + ")\n" + |
|
202 |
* Sextante.getText("Are_you_sure_you_want_to_use_it?")); } |
|
203 |
*/ |
|
204 |
} |
|
247 | 205 |
|
248 |
JRadioButton getJRadioButtonExtentFromLayer() { |
|
249 |
if (jRadioButtonExtentFromLayer == null) { |
|
250 |
jRadioButtonExtentFromLayer = new JRadioButton(); |
|
251 |
jRadioButtonExtentFromLayer.setText(Sextante.getText("Use_extent_from_layer")); |
|
252 |
jRadioButtonExtentFromLayer.addActionListener(new java.awt.event.ActionListener() { |
|
253 |
public void actionPerformed(final java.awt.event.ActionEvent e) { |
|
254 |
getJComboBoxLayers().setSelectedIndex(getJComboBoxLayers().getSelectedIndex()); |
|
255 |
setTextFieldsEnabled(false); |
|
256 |
} |
|
257 |
}); |
|
258 |
} |
|
259 |
return jRadioButtonExtentFromLayer; |
|
260 |
} |
|
206 |
private ButtonGroup getJButtonGroup() { |
|
261 | 207 |
|
208 |
if (jButtonGroup == null) { |
|
209 |
jButtonGroup = new ButtonGroup(); |
|
210 |
} |
|
211 |
return jButtonGroup; |
|
262 | 212 |
|
263 |
protected JPanel getJPanelAnalysisExtentOptions() { |
|
264 |
if (jPanelAnalysisExtentOptions == null) { |
|
265 |
jPanelAnalysisExtentOptions = new JPanel(); |
|
266 |
final TableLayout jPanelRasterExtentOptionsLayout = new TableLayout(new double[][] { |
|
267 |
{ 253.0, TableLayoutConstants.FILL }, |
|
268 |
{ TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, |
|
269 |
TableLayoutConstants.MINIMUM } }); |
|
270 |
jPanelRasterExtentOptionsLayout.setHGap(5); |
|
271 |
jPanelRasterExtentOptionsLayout.setVGap(5); |
|
272 |
jPanelAnalysisExtentOptions.setLayout(jPanelRasterExtentOptionsLayout); |
|
273 |
jPanelAnalysisExtentOptions.setPreferredSize(new java.awt.Dimension(660, 200)); |
|
274 |
jPanelAnalysisExtentOptions.setBorder(BorderFactory.createTitledBorder(Sextante.getText("Extent_from"))); |
|
275 |
jPanelAnalysisExtentOptions.add(getJRadioButtonUserDefinedExtent(), "0, 1"); |
|
276 |
jPanelAnalysisExtentOptions.add(getJRadioButtonViewExtent(), "0, 2"); |
|
277 |
jPanelAnalysisExtentOptions.add(getJRadioButtonExtentFromLayer(), "0, 3"); |
|
278 |
getJButtonGroup().add(getJRadioButtonUserDefinedExtent()); |
|
279 |
getJButtonGroup().add(getJRadioButtonViewExtent()); |
|
280 |
getJButtonGroup().add(getJRadioButtonExtentFromLayer()); |
|
281 |
if (m_Algorithm.canDefineOutputExtentFromInput()) { |
|
282 |
jPanelAnalysisExtentOptions.add(getJRadioButtonAdjustToInputDataExtent(), "0, 0"); |
|
283 |
getJButtonGroup().add(getJRadioButtonAdjustToInputDataExtent()); |
|
284 |
getJRadioButtonAdjustToInputDataExtent().setSelected(true); |
|
285 |
} |
|
286 |
else { |
|
287 |
getJRadioButtonUserDefinedExtent().setSelected(true); |
|
288 |
} |
|
289 |
jPanelAnalysisExtentOptions.add(getJComboBoxViews(), "1, 2"); |
|
290 |
jPanelAnalysisExtentOptions.add(getJComboBoxLayers(), "1, 3"); |
|
213 |
} |
|
291 | 214 |
|
292 |
} |
|
293 |
return jPanelAnalysisExtentOptions; |
|
294 |
} |
|
215 |
protected JRadioButton getJRadioButtonUserDefinedExtent() { |
|
295 | 216 |
|
217 |
if (jRadioButtonUserDefinedExtent == null) { |
|
218 |
jRadioButtonUserDefinedExtent = new JRadioButton(); |
|
219 |
jRadioButtonUserDefinedExtent.setText(Sextante.getText("User_defined")); |
|
220 |
jRadioButtonUserDefinedExtent |
|
221 |
.addActionListener(new java.awt.event.ActionListener() { |
|
296 | 222 |
|
297 |
protected JPanel getJPanelAnalysisExtentValues() { |
|
223 |
public void actionPerformed(final java.awt.event.ActionEvent e) { |
|
224 |
setTextFieldsEnabled(true); |
|
225 |
extentHasChanged(); |
|
226 |
} |
|
227 |
}); |
|
228 |
} |
|
298 | 229 |
|
299 |
if (jPanelAnalysisExtentValues == null) { |
|
300 |
jPanelAnalysisExtentValues = new JPanel(); |
|
301 |
final TableLayout jPanelRasterExtentValuesLayout = new TableLayout(new double[][] { |
|
302 |
{ 255.0, TableLayoutConstants.FILL, TableLayoutConstants.FILL }, |
|
303 |
{ TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, |
|
304 |
TableLayoutConstants.MINIMUM, TableLayoutConstants.FILL } }); |
|
305 |
jPanelRasterExtentValuesLayout.setHGap(5); |
|
306 |
jPanelRasterExtentValuesLayout.setVGap(5); |
|
307 |
jPanelAnalysisExtentValues.setLayout(jPanelRasterExtentValuesLayout); |
|
308 |
jPanelAnalysisExtentValues.setBorder(BorderFactory.createTitledBorder(Sextante.getText("Extent__values"))); |
|
309 |
jPanelAnalysisExtentValues.setPreferredSize(new java.awt.Dimension(660, 145)); |
|
310 |
jPanelAnalysisExtentValues.add(getJLabelRangeX(), "0, 0"); |
|
311 |
jPanelAnalysisExtentValues.add(getJLabelCellSize(), "0, 2"); |
|
312 |
jPanelAnalysisExtentValues.add(getJTextFieldCellSize(), "1, 2"); |
|
313 |
jPanelAnalysisExtentValues.add(getJTextFieldXMin(), "1, 0"); |
|
314 |
jPanelAnalysisExtentValues.add(getJTextFieldXMax(), "2, 0"); |
|
315 |
jPanelAnalysisExtentValues.add(getJTextFieldYMin(), "1, 1"); |
|
316 |
jPanelAnalysisExtentValues.add(getJTextFieldYMax(), "2, 1"); |
|
317 |
jPanelAnalysisExtentValues.add(getJLabelRangeY(), "0, 1"); |
|
318 |
jPanelAnalysisExtentValues.add(getJLabelRowsCols(), "0, 3"); |
|
319 |
jPanelAnalysisExtentValues.add(getJTextFieldRows(), "1, 3"); |
|
320 |
jPanelAnalysisExtentValues.add(getJTextFieldCols(), "2, 3"); |
|
321 |
jPanelAnalysisExtentValues.add(getJButtonExtentFromPoints(), "2,2"); |
|
322 |
} |
|
323 |
return jPanelAnalysisExtentValues; |
|
324 |
} |
|
230 |
return jRadioButtonUserDefinedExtent; |
|
231 |
} |
|
325 | 232 |
|
233 |
protected JRadioButton getJRadioButtonAdjustToInputDataExtent() { |
|
326 | 234 |
|
327 |
private JButton getJButtonExtentFromPoints() { |
|
235 |
if (jRadioButtonAdjustToInputDataExtent == null) { |
|
236 |
jRadioButtonAdjustToInputDataExtent = new JRadioButton(); |
|
237 |
jRadioButtonAdjustToInputDataExtent.setText(Sextante |
|
238 |
.getText("Fit_to_input_layers")); |
|
239 |
jRadioButtonAdjustToInputDataExtent |
|
240 |
.addActionListener(new java.awt.event.ActionListener() { |
|
328 | 241 |
|
329 |
final JButton button = new JButton("..."); |
|
330 |
button.setSize(new Dimension(30, 30)); |
|
331 |
button.addActionListener(new ActionListener() { |
|
332 |
public void actionPerformed(final ActionEvent arg0) { |
|
333 |
final ExtentFromSavedPointsDialog dialog = new ExtentFromSavedPointsDialog(); |
|
334 |
dialog.pack(); |
|
335 |
dialog.setVisible(true); |
|
336 |
final double[] ret = dialog.getPoints(); |
|
337 |
if (ret != null) { |
|
338 |
getJTextFieldXMin().setText(Double.toString(ret[0])); |
|
339 |
getJTextFieldYMin().setText(Double.toString(ret[1])); |
|
340 |
getJTextFieldXMax().setText(Double.toString(ret[2])); |
|
341 |
getJTextFieldYMax().setText(Double.toString(ret[3])); |
|
242 |
public void actionPerformed(final java.awt.event.ActionEvent e) { |
|
243 |
getJPanelAnalysisExtentValues().setVisible(false); |
|
342 | 244 |
} |
343 |
} |
|
344 |
}); |
|
345 |
return button; |
|
346 |
} |
|
245 |
}); |
|
246 |
} |
|
347 | 247 |
|
248 |
return jRadioButtonAdjustToInputDataExtent; |
|
249 |
} |
|
348 | 250 |
|
349 |
protected JComboBox getJComboBoxLayers() { |
|
251 |
private JRadioButton getJRadioButtonViewExtent() { |
|
252 |
if (jRadioButtonViewExtent == null) { |
|
253 |
jRadioButtonViewExtent = new JRadioButton(); |
|
254 |
jRadioButtonViewExtent.setText(Sextante.getText("Use_extent_from_view")); |
|
255 |
jRadioButtonViewExtent |
|
256 |
.addActionListener(new java.awt.event.ActionListener() { |
|
350 | 257 |
|
351 |
if (jComboBoxLayers == null) { |
|
352 |
final ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel(m_Layers); |
|
353 |
jComboBoxLayers = new JComboBox(); |
|
354 |
jComboBoxLayers.setModel(jComboBoxLayersModel); |
|
355 |
jComboBoxLayers.addActionListener(new java.awt.event.ActionListener() { |
|
356 | 258 |
public void actionPerformed(final java.awt.event.ActionEvent evt) { |
357 |
double dCoord; |
|
358 |
if (getJRadioButtonExtentFromLayer().isSelected()) { |
|
359 |
try { |
|
360 |
final ILayer layer = (ILayer) jComboBoxLayers.getSelectedItem(); |
|
361 |
Rectangle2D fullExtent = layer.getFullExtent(); |
|
362 |
dCoord = fullExtent.getMinX(); |
|
363 |
getJTextFieldXMin().setText(new Double(dCoord).toString()); |
|
364 |
dCoord = fullExtent.getMaxX(); |
|
365 |
getJTextFieldXMax().setText(new Double(dCoord).toString()); |
|
366 |
dCoord = fullExtent.getMinY(); |
|
367 |
getJTextFieldYMin().setText(new Double(dCoord).toString()); |
|
368 |
dCoord = fullExtent.getMaxY(); |
|
369 |
getJTextFieldYMax().setText(new Double(dCoord).toString()); |
|
370 |
if (layer instanceof IRasterLayer) { |
|
371 |
getJTextFieldCellSize().setText(new Double(((IRasterLayer) layer).getLayerCellSize()).toString()); |
|
372 |
} |
|
373 |
extentHasChanged(); |
|
374 |
} |
|
375 |
catch (final Exception e) { |
|
376 |
} |
|
377 |
} |
|
259 |
try { |
|
260 |
getJComboBoxViews().setSelectedIndex( |
|
261 |
getJComboBoxViews().getSelectedIndex()); |
|
262 |
setTextFieldsEnabled(false); |
|
263 |
} |
|
264 |
catch (final Exception e) {} |
|
378 | 265 |
} |
379 |
}); |
|
380 |
}
|
|
381 |
return jComboBoxLayers;
|
|
382 |
}
|
|
266 |
});
|
|
267 |
} |
|
268 |
return jRadioButtonViewExtent;
|
|
269 |
} |
|
383 | 270 |
|
271 |
JRadioButton getJRadioButtonExtentFromLayer() { |
|
272 |
if (jRadioButtonExtentFromLayer == null) { |
|
273 |
jRadioButtonExtentFromLayer = new JRadioButton(); |
|
274 |
jRadioButtonExtentFromLayer.setText(Sextante |
|
275 |
.getText("Use_extent_from_layer")); |
|
276 |
jRadioButtonExtentFromLayer |
|
277 |
.addActionListener(new java.awt.event.ActionListener() { |
|
384 | 278 |
|
385 |
private JComboBox getJComboBoxViews() { |
|
279 |
public void actionPerformed(final java.awt.event.ActionEvent e) { |
|
280 |
getJComboBoxLayers().setSelectedIndex( |
|
281 |
getJComboBoxLayers().getSelectedIndex()); |
|
282 |
setTextFieldsEnabled(false); |
|
283 |
} |
|
284 |
}); |
|
285 |
} |
|
286 |
return jRadioButtonExtentFromLayer; |
|
287 |
} |
|
386 | 288 |
|
387 |
if (jComboBoxViews == null) { |
|
388 |
final ComboBoxModel jComboBoxViewsModel = new DefaultComboBoxModel(SextanteGUI.getInputFactory().getPredefinedExtents()); |
|
389 |
jComboBoxViews = new JComboBox(); |
|
390 |
jComboBoxViews.setModel(jComboBoxViewsModel); |
|
391 |
jComboBoxViews.addActionListener(new java.awt.event.ActionListener() { |
|
392 |
public void actionPerformed(final java.awt.event.ActionEvent evt) { |
|
393 |
if (getJRadioButtonViewExtent().isSelected()) { |
|
394 |
try { |
|
395 |
final NamedExtent ne = (NamedExtent) jComboBoxViews.getSelectedItem(); |
|
396 |
if (ne != null) { |
|
397 |
final Rectangle2D extent = ne.getExtent(); |
|
398 |
getJTextFieldXMin().setText(new Double(extent.getMinX()).toString()); |
|
399 |
getJTextFieldXMax().setText(new Double(extent.getMaxX()).toString()); |
|
400 |
getJTextFieldYMin().setText(new Double(extent.getMinY()).toString()); |
|
401 |
getJTextFieldYMax().setText(new Double(extent.getMaxY()).toString()); |
|
402 |
setTextFieldsEnabled(false); |
|
403 |
extentHasChanged(); |
|
404 |
} |
|
405 |
} |
|
406 |
catch (final Exception e) { |
|
407 |
Sextante.addErrorToLog(e); |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
}); |
|
289 |
protected JPanel getJPanelAnalysisExtentOptions() { |
|
290 |
if (jPanelAnalysisExtentOptions == null) { |
|
291 |
jPanelAnalysisExtentOptions = new JPanel(); |
|
292 |
final TableLayout jPanelRasterExtentOptionsLayout = new TableLayout( |
|
293 |
new double[][] { |
|
294 |
{ 253.0, TableLayoutConstants.FILL }, |
|
295 |
{ TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, |
|
296 |
TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM } }); |
|
297 |
jPanelRasterExtentOptionsLayout.setHGap(5); |
|
298 |
jPanelRasterExtentOptionsLayout.setVGap(5); |
|
299 |
jPanelAnalysisExtentOptions.setLayout(jPanelRasterExtentOptionsLayout); |
|
300 |
jPanelAnalysisExtentOptions.setPreferredSize(new java.awt.Dimension(660, |
|
301 |
200)); |
|
302 |
jPanelAnalysisExtentOptions.setBorder(BorderFactory |
|
303 |
.createTitledBorder(Sextante.getText("Extent_from"))); |
|
304 |
jPanelAnalysisExtentOptions.add(getJRadioButtonUserDefinedExtent(), |
|
305 |
"0, 1"); |
|
306 |
jPanelAnalysisExtentOptions.add(getJRadioButtonViewExtent(), "0, 2"); |
|
307 |
jPanelAnalysisExtentOptions.add(getJRadioButtonExtentFromLayer(), "0, 3"); |
|
308 |
getJButtonGroup().add(getJRadioButtonUserDefinedExtent()); |
|
309 |
getJButtonGroup().add(getJRadioButtonViewExtent()); |
|
310 |
getJButtonGroup().add(getJRadioButtonExtentFromLayer()); |
|
311 |
if (m_Algorithm.canDefineOutputExtentFromInput()) { |
|
312 |
jPanelAnalysisExtentOptions.add( |
|
313 |
getJRadioButtonAdjustToInputDataExtent(), "0, 0"); |
|
314 |
getJButtonGroup().add(getJRadioButtonAdjustToInputDataExtent()); |
|
315 |
getJRadioButtonAdjustToInputDataExtent().setSelected(true); |
|
412 | 316 |
} |
413 |
return jComboBoxViews; |
|
414 |
} |
|
317 |
else { |
|
318 |
getJRadioButtonUserDefinedExtent().setSelected(true); |
|
319 |
} |
|
320 |
jPanelAnalysisExtentOptions.add(getJComboBoxViews(), "1, 2"); |
|
321 |
jPanelAnalysisExtentOptions.add(getJComboBoxLayers(), "1, 3"); |
|
415 | 322 |
|
323 |
} |
|
324 |
return jPanelAnalysisExtentOptions; |
|
325 |
} |
|
416 | 326 |
|
417 |
protected JLabel getJLabelRangeX() {
|
|
327 |
protected JPanel getJPanelAnalysisExtentValues() {
|
|
418 | 328 |
|
419 |
if (jLabelRangeX == null) { |
|
420 |
jLabelRangeX = new JLabel(); |
|
421 |
jLabelRangeX.setText(Sextante.getText("Range_X")); |
|
329 |
if (jPanelAnalysisExtentValues == null) { |
|
330 |
jPanelAnalysisExtentValues = new JPanel(); |
|
331 |
final TableLayout jPanelRasterExtentValuesLayout = new TableLayout( |
|
332 |
new double[][] { |
|
333 |
{ 255.0, TableLayoutConstants.FILL, TableLayoutConstants.FILL }, |
|
334 |
{ TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, |
|
335 |
TableLayoutConstants.MINIMUM, TableLayoutConstants.MINIMUM, |
|
336 |
TableLayoutConstants.FILL } }); |
|
337 |
jPanelRasterExtentValuesLayout.setHGap(5); |
|
338 |
jPanelRasterExtentValuesLayout.setVGap(5); |
|
339 |
jPanelAnalysisExtentValues.setLayout(jPanelRasterExtentValuesLayout); |
|
340 |
jPanelAnalysisExtentValues.setBorder(BorderFactory |
|
341 |
.createTitledBorder(Sextante.getText("Extent__values"))); |
|
342 |
jPanelAnalysisExtentValues.setPreferredSize(new java.awt.Dimension(660, |
|
343 |
145)); |
|
344 |
jPanelAnalysisExtentValues.add(getJLabelRangeX(), "0, 0"); |
|
345 |
jPanelAnalysisExtentValues.add(getJLabelCellSize(), "0, 2"); |
|
346 |
jPanelAnalysisExtentValues.add(getJTextFieldCellSize(), "1, 2"); |
|
347 |
jPanelAnalysisExtentValues.add(getJTextFieldXMin(), "1, 0"); |
|
348 |
jPanelAnalysisExtentValues.add(getJTextFieldXMax(), "2, 0"); |
|
349 |
jPanelAnalysisExtentValues.add(getJTextFieldYMin(), "1, 1"); |
|
350 |
jPanelAnalysisExtentValues.add(getJTextFieldYMax(), "2, 1"); |
|
351 |
jPanelAnalysisExtentValues.add(getJLabelRangeY(), "0, 1"); |
|
352 |
jPanelAnalysisExtentValues.add(getJLabelRowsCols(), "0, 3"); |
|
353 |
jPanelAnalysisExtentValues.add(getJTextFieldRows(), "1, 3"); |
|
354 |
jPanelAnalysisExtentValues.add(getJTextFieldCols(), "2, 3"); |
|
355 |
jPanelAnalysisExtentValues.add(getJButtonExtentFromPoints(), "2,2"); |
|
356 |
} |
|
357 |
return jPanelAnalysisExtentValues; |
|
358 |
} |
|
359 |
|
|
360 |
private JButton getJButtonExtentFromPoints() { |
|
361 |
|
|
362 |
final JButton button = new JButton("..."); |
|
363 |
button.setSize(new Dimension(30, 30)); |
|
364 |
button.addActionListener(new ActionListener() { |
|
365 |
|
|
366 |
public void actionPerformed(final ActionEvent arg0) { |
|
367 |
final ExtentFromSavedPointsDialog dialog = new ExtentFromSavedPointsDialog(); |
|
368 |
dialog.pack(); |
|
369 |
dialog.setVisible(true); |
|
370 |
final double[] ret = dialog.getPoints(); |
|
371 |
if (ret != null) { |
|
372 |
getJTextFieldXMin().setText(Double.toString(ret[0])); |
|
373 |
getJTextFieldYMin().setText(Double.toString(ret[1])); |
|
374 |
getJTextFieldXMax().setText(Double.toString(ret[2])); |
|
375 |
getJTextFieldYMax().setText(Double.toString(ret[3])); |
|
376 |
} |
|
422 | 377 |
} |
423 |
return jLabelRangeX; |
|
378 |
}); |
|
379 |
return button; |
|
380 |
} |
|
424 | 381 |
|
425 |
}
|
|
382 |
protected JComboBox getJComboBoxLayers() {
|
|
426 | 383 |
|
384 |
if (jComboBoxLayers == null) { |
|
385 |
getJRadioButtonExtentFromLayer().setEnabled(m_Layers.length > 0); |
|
386 |
final ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel( |
|
387 |
m_Layers); |
|
388 |
jComboBoxLayers = new JComboBox(); |
|
389 |
jComboBoxLayers.setModel(jComboBoxLayersModel); |
|
390 |
jComboBoxLayers.setEnabled(m_Layers.length > 0); |
|
427 | 391 |
|
428 |
protected JTextField getNewJTextField() {
|
|
392 |
jComboBoxLayers.addActionListener(new java.awt.event.ActionListener() {
|
|
429 | 393 |
|
430 |
final JTextField jTextField = new JTextField(); |
|
431 |
jTextField.addFocusListener(new FocusAdapter() { |
|
432 |
@Override |
|
433 |
public void focusLost(final FocusEvent e) { |
|
434 |
final JTextField textField = (JTextField) e.getSource(); |
|
435 |
final String content = textField.getText(); |
|
436 |
if (content.length() != 0) { |
|
437 |
try { |
|
438 |
final double d = Double.parseDouble(content); |
|
439 |
extentHasChanged(); |
|
440 |
} |
|
441 |
catch (final NumberFormatException nfe) { |
|
442 |
getToolkit().beep(); |
|
443 |
textField.requestFocus(); |
|
444 |
} |
|
394 |
public void actionPerformed(final java.awt.event.ActionEvent evt) { |
|
395 |
double dCoord; |
|
396 |
if (getJRadioButtonExtentFromLayer().isSelected()) { |
|
397 |
try { |
|
398 |
final ILayer layer = (ILayer) jComboBoxLayers.getSelectedItem(); |
|
399 |
Rectangle2D fullExtent = layer.getFullExtent(); |
|
400 |
dCoord = fullExtent.getMinX(); |
|
401 |
getJTextFieldXMin().setText(new Double(dCoord).toString()); |
|
402 |
dCoord = fullExtent.getMaxX(); |
|
403 |
getJTextFieldXMax().setText(new Double(dCoord).toString()); |
|
404 |
dCoord = fullExtent.getMinY(); |
|
405 |
getJTextFieldYMin().setText(new Double(dCoord).toString()); |
|
406 |
dCoord = fullExtent.getMaxY(); |
|
407 |
getJTextFieldYMax().setText(new Double(dCoord).toString()); |
|
408 |
if (layer instanceof IRasterLayer) { |
|
409 |
getJTextFieldCellSize().setText( |
|
410 |
new Double(((IRasterLayer) layer).getLayerCellSize()) |
|
411 |
.toString()); |
|
412 |
} |
|
413 |
extentHasChanged(); |
|
445 | 414 |
} |
446 |
} |
|
415 |
catch (final Exception e) {} |
|
416 |
} |
|
417 |
} |
|
447 | 418 |
}); |
448 |
jTextField.addKeyListener(new KeyAdapter() { |
|
449 |
@Override |
|
450 |
public void keyTyped(final KeyEvent event) { |
|
451 |
validateKeyTyping(event); |
|
452 |
} |
|
453 |
}); |
|
419 |
} |
|
420 |
return jComboBoxLayers; |
|
421 |
} |
|
454 | 422 |
|
455 |
return jTextField; |
|
456 |
} |
|
423 |
private JComboBox getJComboBoxViews() { |
|
457 | 424 |
|
425 |
if (jComboBoxViews == null) { |
|
426 |
NamedExtent[] predefinedExtents = SextanteGUI.getInputFactory() |
|
427 |
.getPredefinedExtents(); |
|
428 |
boolean enabled = predefinedExtents.length > 1 || (predefinedExtents.length == 1 && predefinedExtents[0] != null); |
|
429 |
getJRadioButtonViewExtent().setEnabled(enabled); |
|
430 |
final ComboBoxModel jComboBoxViewsModel = new DefaultComboBoxModel( |
|
431 |
predefinedExtents); |
|
432 |
jComboBoxViews = new JComboBox(); |
|
433 |
jComboBoxViews.setModel(jComboBoxViewsModel); |
|
434 |
jComboBoxViews.setEnabled(enabled); |
|
458 | 435 |
|
459 |
protected JTextField getJTextFieldXMin() { |
|
460 |
if (jTextFieldXMin == null) { |
|
461 |
jTextFieldXMin = getNewJTextField(); |
|
462 |
} |
|
463 |
return jTextFieldXMin; |
|
464 |
} |
|
436 |
jComboBoxViews.addActionListener(new java.awt.event.ActionListener() { |
|
465 | 437 |
|
438 |
public void actionPerformed(final java.awt.event.ActionEvent evt) { |
|
439 |
if (getJRadioButtonViewExtent().isSelected()) { |
|
440 |
try { |
|
441 |
final NamedExtent ne = (NamedExtent) jComboBoxViews |
|
442 |
.getSelectedItem(); |
|
443 |
if (ne != null) { |
|
444 |
final Rectangle2D extent = ne.getExtent(); |
|
445 |
getJTextFieldXMin().setText( |
|
446 |
new Double(extent.getMinX()).toString()); |
|
447 |
getJTextFieldXMax().setText( |
|
448 |
new Double(extent.getMaxX()).toString()); |
|
449 |
getJTextFieldYMin().setText( |
|
450 |
new Double(extent.getMinY()).toString()); |
|
451 |
getJTextFieldYMax().setText( |
|
452 |
new Double(extent.getMaxY()).toString()); |
|
453 |
setTextFieldsEnabled(false); |
|
454 |
extentHasChanged(); |
|
455 |
} |
|
456 |
} |
|
457 |
catch (final Exception e) { |
|
458 |
Sextante.addErrorToLog(e); |
|
459 |
} |
|
460 |
} |
|
461 |
} |
|
462 |
}); |
|
463 |
} |
|
464 |
return jComboBoxViews; |
|
465 |
} |
|
466 | 466 |
|
467 |
protected JTextField getJTextFieldXMax() { |
|
468 |
if (jTextFieldXMax == null) { |
|
469 |
jTextFieldXMax = getNewJTextField(); |
|
470 |
} |
|
471 |
return jTextFieldXMax; |
|
472 |
} |
|
467 |
protected JLabel getJLabelRangeX() { |
|
473 | 468 |
|
469 |
if (jLabelRangeX == null) { |
|
470 |
jLabelRangeX = new JLabel(); |
|
471 |
jLabelRangeX.setText(Sextante.getText("Range_X")); |
|
472 |
} |
|
473 |
return jLabelRangeX; |
|
474 | 474 |
|
475 |
protected JTextField getJTextFieldYMin() { |
|
476 |
if (jTextFieldYMin == null) { |
|
477 |
jTextFieldYMin = getNewJTextField(); |
|
478 |
} |
|
479 |
return jTextFieldYMin; |
|
480 |
} |
|
475 |
} |
|
481 | 476 |
|
477 |
protected JTextField getNewJTextField() { |
|
482 | 478 |
|
483 |
protected JTextField getJTextFieldYMax() { |
|
484 |
if (jTextFieldYMax == null) { |
|
485 |
jTextFieldYMax = getNewJTextField(); |
|
486 |
} |
|
487 |
return jTextFieldYMax; |
|
488 |
} |
|
479 |
final JTextField jTextField = new JTextField(); |
|
480 |
jTextField.addFocusListener(new FocusAdapter() { |
|
489 | 481 |
|
490 |
|
|
491 |
protected JLabel getJLabelRangeY() { |
|
492 |
if (jLabelRangeY == null) { |
|
493 |
jLabelRangeY = new JLabel(); |
|
494 |
jLabelRangeY.setText(Sextante.getText("Range_Y")); |
|
482 |
@Override |
|
483 |
public void focusLost(final FocusEvent e) { |
|
484 |
final JTextField textField = (JTextField) e.getSource(); |
|
485 |
final String content = textField.getText(); |
|
486 |
if (content.length() != 0) { |
|
487 |
try { |
|
488 |
final double d = Double.parseDouble(content); |
|
489 |
extentHasChanged(); |
|
490 |
} |
|
491 |
catch (final NumberFormatException nfe) { |
|
492 |
getToolkit().beep(); |
|
493 |
textField.requestFocus(); |
|
494 |
} |
|
495 |
} |
|
495 | 496 |
} |
496 |
return jLabelRangeY;
|
|
497 |
}
|
|
497 |
});
|
|
498 |
jTextField.addKeyListener(new KeyAdapter() {
|
|
498 | 499 |
|
499 |
|
|
500 |
protected JLabel getJLabelCellSize() { |
|
501 |
if (jLabelCellSize == null) { |
|
502 |
jLabelCellSize = new JLabel(); |
|
503 |
jLabelCellSize.setText(Sextante.getText("Cell_size")); |
|
500 |
@Override |
|
501 |
public void keyTyped(final KeyEvent event) { |
|
502 |
validateKeyTyping(event); |
|
504 | 503 |
} |
505 |
return jLabelCellSize; |
|
506 |
} |
|
504 |
}); |
|
507 | 505 |
|
506 |
return jTextField; |
|
507 |
} |
|
508 | 508 |
|
509 |
protected JTextField getJTextFieldCellSize() { |
|
510 |
if (jTextFieldCellSize == null) { |
|
511 |
jTextFieldCellSize = new JTextField(); |
|
512 |
jTextFieldCellSize.setText("1"); |
|
513 |
jTextFieldCellSize.addFocusListener(new FocusAdapter() { |
|
514 |
@Override |
|
515 |
public void focusLost(final FocusEvent e) { |
|
516 |
final JTextField textField = (JTextField) e.getSource(); |
|
517 |
final String content = textField.getText(); |
|
518 |
if (content.length() != 0) { |
|
519 |
try { |
|
520 |
final double d = Double.parseDouble(content); |
|
521 |
if (d <= 0) { |
|
522 |
throw new NumberFormatException(); |
|
523 |
} |
|
524 |
else { |
|
525 |
extentHasChanged(); |
|
526 |
} |
|
527 |
} |
|
528 |
catch (final NumberFormatException nfe) { |
|
529 |
getToolkit().beep(); |
|
530 |
textField.requestFocus(); |
|
531 |
} |
|
532 |
} |
|
509 |
protected JTextField getJTextFieldXMin() { |
|
510 |
if (jTextFieldXMin == null) { |
|
511 |
jTextFieldXMin = getNewJTextField(); |
|
512 |
} |
|
513 |
return jTextFieldXMin; |
|
514 |
} |
|
533 | 515 |
|
534 |
} |
|
535 |
}); |
|
536 |
jTextFieldCellSize.addKeyListener(new KeyAdapter() { |
|
537 |
@Override |
|
538 |
public void keyTyped(final KeyEvent event) { |
|
539 |
validateKeyTyping(event); |
|
540 |
} |
|
541 |
}); |
|
542 |
} |
|
543 |
return jTextFieldCellSize; |
|
544 |
} |
|
516 |
protected JTextField getJTextFieldXMax() { |
|
517 |
if (jTextFieldXMax == null) { |
|
518 |
jTextFieldXMax = getNewJTextField(); |
|
519 |
} |
|
520 |
return jTextFieldXMax; |
|
521 |
} |
|
545 | 522 |
|
523 |
protected JTextField getJTextFieldYMin() { |
|
524 |
if (jTextFieldYMin == null) { |
|
525 |
jTextFieldYMin = getNewJTextField(); |
|
526 |
} |
|
527 |
return jTextFieldYMin; |
|
528 |
} |
|
546 | 529 |
|
547 |
protected JLabel getJLabelRowsCols() { |
|
548 |
if (jLabelRowsCols == null) { |
|
549 |
jLabelRowsCols = new JLabel(); |
|
550 |
jLabelRowsCols.setText(Sextante.getText("Number_of_rows-cols")); |
|
551 |
} |
|
552 |
return jLabelRowsCols; |
|
553 |
} |
|
530 |
protected JTextField getJTextFieldYMax() { |
|
531 |
if (jTextFieldYMax == null) { |
|
532 |
jTextFieldYMax = getNewJTextField(); |
|
533 |
} |
|
534 |
return jTextFieldYMax; |
|
535 |
} |
|
554 | 536 |
|
537 |
protected JLabel getJLabelRangeY() { |
|
538 |
if (jLabelRangeY == null) { |
|
539 |
jLabelRangeY = new JLabel(); |
|
540 |
jLabelRangeY.setText(Sextante.getText("Range_Y")); |
|
541 |
} |
|
542 |
return jLabelRangeY; |
|
543 |
} |
|
555 | 544 |
|
556 |
protected JTextField getJTextFieldRows() {
|
|
557 |
if (jTextFieldRows == null) {
|
|
558 |
jTextFieldRows = new JTextField();
|
|
559 |
jTextFieldRows.setEnabled(false);
|
|
560 |
}
|
|
561 |
return jTextFieldRows;
|
|
562 |
}
|
|
545 |
protected JLabel getJLabelCellSize() {
|
|
546 |
if (jLabelCellSize == null) {
|
|
547 |
jLabelCellSize = new JLabel();
|
|
548 |
jLabelCellSize.setText(Sextante.getText("Cell_size"));
|
|
549 |
} |
|
550 |
return jLabelCellSize;
|
|
551 |
} |
|
563 | 552 |
|
553 |
protected JTextField getJTextFieldCellSize() { |
|
554 |
if (jTextFieldCellSize == null) { |
|
555 |
jTextFieldCellSize = new JTextField(); |
|
556 |
jTextFieldCellSize.setText("1"); |
|
557 |
jTextFieldCellSize.addFocusListener(new FocusAdapter() { |
|
564 | 558 |
|
565 |
protected JTextField getJTextFieldCols() { |
|
566 |
if (jTextFieldCols == null) { |
|
567 |
jTextFieldCols = new JTextField(); |
|
568 |
jTextFieldCols.setEnabled(false); |
|
569 |
} |
|
570 |
return jTextFieldCols; |
|
571 |
} |
|
559 |
@Override |
|
560 |
public void focusLost(final FocusEvent e) { |
|
561 |
final JTextField textField = (JTextField) e.getSource(); |
|
562 |
final String content = textField.getText(); |
|
563 |
if (content.length() != 0) { |
|
564 |
try { |
|
565 |
final double d = Double.parseDouble(content); |
|
566 |
if (d <= 0) { |
|
567 |
throw new NumberFormatException(); |
|
568 |
} |
|
569 |
else { |
|
570 |
extentHasChanged(); |
|
571 |
} |
|
572 |
} |
|
573 |
catch (final NumberFormatException nfe) { |
|
574 |
getToolkit().beep(); |
|
575 |
textField.requestFocus(); |
|
576 |
} |
|
577 |
} |
|
572 | 578 |
|
579 |
} |
|
580 |
}); |
|
581 |
jTextFieldCellSize.addKeyListener(new KeyAdapter() { |
|
573 | 582 |
|
574 |
private void validateKeyTyping(final KeyEvent event) { |
|
575 |
String text = ((JTextField) event.getSource()).getText(); |
|
576 |
switch (event.getKeyChar()) { |
|
577 |
case KeyEvent.VK_ENTER: |
|
578 |
extentHasChanged(); |
|
579 |
break; |
|
580 |
default: |
|
581 |
text += event.getKeyChar(); |
|
582 |
break; |
|
583 |
} |
|
584 |
} |
|
583 |
@Override |
|
584 |
public void keyTyped(final KeyEvent event) { |
|
585 |
validateKeyTyping(event); |
|
586 |
} |
|
587 |
}); |
|
588 |
} |
|
589 |
return jTextFieldCellSize; |
|
590 |
} |
|
585 | 591 |
|
592 |
protected JLabel getJLabelRowsCols() { |
|
593 |
if (jLabelRowsCols == null) { |
|
594 |
jLabelRowsCols = new JLabel(); |
|
595 |
jLabelRowsCols.setText(Sextante.getText("Number_of_rows-cols")); |
|
596 |
} |
|
597 |
return jLabelRowsCols; |
|
598 |
} |
|
586 | 599 |
|
587 |
protected void setTextFieldsEnabled(final boolean bEnabled) { |
|
600 |
protected JTextField getJTextFieldRows() { |
|
601 |
if (jTextFieldRows == null) { |
|
602 |
jTextFieldRows = new JTextField(); |
|
603 |
jTextFieldRows.setEnabled(false); |
|
604 |
} |
|
605 |
return jTextFieldRows; |
|
606 |
} |
|
588 | 607 |
|
589 |
getJPanelAnalysisExtentValues().setVisible(true); |
|
590 |
getJTextFieldXMin().setEnabled(bEnabled); |
|
591 |
getJTextFieldXMax().setEnabled(bEnabled); |
|
592 |
getJTextFieldYMin().setEnabled(bEnabled); |
|
593 |
getJTextFieldYMax().setEnabled(bEnabled); |
|
608 |
protected JTextField getJTextFieldCols() { |
|
609 |
if (jTextFieldCols == null) { |
|
610 |
jTextFieldCols = new JTextField(); |
|
611 |
jTextFieldCols.setEnabled(false); |
|
612 |
} |
|
613 |
return jTextFieldCols; |
|
614 |
} |
|
594 | 615 |
|
595 |
} |
|
616 |
private void validateKeyTyping(final KeyEvent event) { |
|
617 |
String text = ((JTextField) event.getSource()).getText(); |
|
618 |
switch (event.getKeyChar()) { |
|
619 |
case KeyEvent.VK_ENTER: |
|
620 |
extentHasChanged(); |
|
621 |
break; |
|
622 |
default: |
|
623 |
text += event.getKeyChar(); |
|
624 |
break; |
|
625 |
} |
|
626 |
} |
|
596 | 627 |
|
628 |
protected void setTextFieldsEnabled(final boolean bEnabled) { |
|
597 | 629 |
|
598 |
protected void extentHasChanged() { |
|
630 |
getJPanelAnalysisExtentValues().setVisible(true); |
|
631 |
getJTextFieldXMin().setEnabled(bEnabled); |
|
632 |
getJTextFieldXMax().setEnabled(bEnabled); |
|
633 |
getJTextFieldYMin().setEnabled(bEnabled); |
|
634 |
getJTextFieldYMax().setEnabled(bEnabled); |
|
599 | 635 |
|
600 |
double dRangeX; |
|
601 |
double dRangeY; |
|
602 |
double dCellSize; |
|
603 |
int iRows; |
|
604 |
int iCols; |
|
636 |
} |
|
605 | 637 |
|
606 |
try { |
|
607 |
dRangeX = Math.abs(Double.parseDouble(getJTextFieldXMax().getText()) - Double.parseDouble(getJTextFieldXMin().getText())); |
|
608 |
dRangeY = Math.abs(Double.parseDouble(getJTextFieldYMax().getText()) - Double.parseDouble(getJTextFieldYMin().getText())); |
|
609 |
dCellSize = Double.parseDouble(getJTextFieldCellSize().getText()); |
|
610 |
iRows = (int) Math.floor(dRangeY / dCellSize); |
|
611 |
iCols = (int) Math.floor(dRangeX / dCellSize); |
|
612 |
getJTextFieldRows().setText(Integer.toString(iRows)); |
|
613 |
getJTextFieldCols().setText(Integer.toString(iCols)); |
|
614 |
} |
|
615 |
catch (final NumberFormatException e) { |
|
616 |
return; |
|
617 |
} |
|
638 |
protected void extentHasChanged() { |
|
618 | 639 |
|
619 |
} |
|
640 |
double dRangeX; |
|
641 |
double dRangeY; |
|
642 |
double dCellSize; |
|
643 |
int iRows; |
|
644 |
int iCols; |
|
620 | 645 |
|
646 |
try { |
|
647 |
dRangeX = Math.abs(Double.parseDouble(getJTextFieldXMax().getText()) |
|
648 |
- Double.parseDouble(getJTextFieldXMin().getText())); |
|
649 |
dRangeY = Math.abs(Double.parseDouble(getJTextFieldYMax().getText()) |
|
650 |
- Double.parseDouble(getJTextFieldYMin().getText())); |
|
651 |
dCellSize = Double.parseDouble(getJTextFieldCellSize().getText()); |
|
652 |
iRows = (int) Math.floor(dRangeY / dCellSize); |
|
653 |
iCols = (int) Math.floor(dRangeX / dCellSize); |
|
654 |
getJTextFieldRows().setText(Integer.toString(iRows)); |
|
655 |
getJTextFieldCols().setText(Integer.toString(iCols)); |
|
656 |
} |
|
657 |
catch (final NumberFormatException e) { |
|
658 |
return; |
|
659 |
} |
|
621 | 660 |
|
622 |
public void setExtent(final AnalysisExtent ge) {
|
|
661 |
}
|
|
623 | 662 |
|
624 |
getJRadioButtonUserDefinedExtent().setSelected(true); |
|
625 |
setTextFieldsEnabled(true); |
|
663 |
public void setExtent(final AnalysisExtent ge) { |
|
626 | 664 |
|
627 |
getJTextFieldCellSize().setText(Double.toString(ge.getCellSize())); |
|
628 |
getJTextFieldXMin().setText(Double.toString(ge.getXMin())); |
|
629 |
getJTextFieldXMax().setText(Double.toString(ge.getXMax())); |
|
630 |
getJTextFieldYMin().setText(Double.toString(ge.getYMin())); |
|
631 |
getJTextFieldYMax().setText(Double.toString(ge.getYMax())); |
|
632 |
extentHasChanged(); |
|
665 |
getJRadioButtonUserDefinedExtent().setSelected(true); |
|
666 |
setTextFieldsEnabled(true); |
|
633 | 667 |
|
634 |
} |
|
668 |
getJTextFieldCellSize().setText(Double.toString(ge.getCellSize())); |
|
669 |
getJTextFieldXMin().setText(Double.toString(ge.getXMin())); |
|
670 |
getJTextFieldXMax().setText(Double.toString(ge.getXMax())); |
|
671 |
getJTextFieldYMin().setText(Double.toString(ge.getYMin())); |
|
672 |
getJTextFieldYMax().setText(Double.toString(ge.getYMax())); |
|
673 |
extentHasChanged(); |
|
635 | 674 |
|
675 |
} |
|
636 | 676 |
|
637 |
public void setAutoExtent() {
|
|
677 |
public void setAutoExtent() { |
|
638 | 678 |
|
639 |
getJRadioButtonAdjustToInputDataExtent().setSelected(true);
|
|
640 |
setTextFieldsEnabled(false);
|
|
641 |
getJPanelAnalysisExtentValues().setVisible(false);
|
|
679 |
getJRadioButtonAdjustToInputDataExtent().setSelected(true); |
|
680 |
setTextFieldsEnabled(false); |
|
681 |
getJPanelAnalysisExtentValues().setVisible(false); |
|
642 | 682 |
|
683 |
} |
|
643 | 684 |
|
644 |
} |
|
645 |
|
|
646 |
|
|
647 | 685 |
} |
Also available in: Unified diff