root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / algorithm / DefaultParametersPanel.java @ 341
History | View | Annotate | Download (81.1 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.gui.algorithm; |
4 |
|
5 |
import info.clearthought.layout.TableLayout; |
6 |
import info.clearthought.layout.TableLayoutConstants; |
7 |
|
8 |
import java.awt.BorderLayout; |
9 |
import java.awt.Dimension; |
10 |
import java.awt.event.FocusAdapter; |
11 |
import java.awt.event.FocusEvent; |
12 |
import java.awt.geom.Point2D; |
13 |
import java.util.ArrayList; |
14 |
import java.util.HashMap; |
15 |
import java.util.List; |
16 |
import java.util.StringTokenizer; |
17 |
|
18 |
import javax.swing.BorderFactory; |
19 |
import javax.swing.ComboBoxModel; |
20 |
import javax.swing.DefaultComboBoxModel; |
21 |
import javax.swing.JCheckBox; |
22 |
import javax.swing.JComboBox; |
23 |
import javax.swing.JLabel; |
24 |
import javax.swing.JPanel; |
25 |
import javax.swing.JScrollPane; |
26 |
import javax.swing.JTextField; |
27 |
import javax.swing.ScrollPaneConstants; |
28 |
|
29 |
import org.japura.gui.Anchor; |
30 |
import org.japura.gui.BatchSelection; |
31 |
import org.japura.gui.CheckComboBox; |
32 |
import org.japura.gui.EmbeddedComponent; |
33 |
import org.japura.gui.model.ListCheckModel; |
34 |
|
35 |
import es.unex.sextante.additionalInfo.AdditionalInfoBand; |
36 |
import es.unex.sextante.additionalInfo.AdditionalInfoBoolean; |
37 |
import es.unex.sextante.additionalInfo.AdditionalInfoFilepath; |
38 |
import es.unex.sextante.additionalInfo.AdditionalInfoFixedTable; |
39 |
import es.unex.sextante.additionalInfo.AdditionalInfoMultipleInput; |
40 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
41 |
import es.unex.sextante.additionalInfo.AdditionalInfoRasterLayer; |
42 |
import es.unex.sextante.additionalInfo.AdditionalInfoSelection; |
43 |
import es.unex.sextante.additionalInfo.AdditionalInfoString; |
44 |
import es.unex.sextante.additionalInfo.AdditionalInfoTable; |
45 |
import es.unex.sextante.additionalInfo.AdditionalInfoTableField; |
46 |
import es.unex.sextante.additionalInfo.AdditionalInfoTableFilter; |
47 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
48 |
import es.unex.sextante.core.GeoAlgorithm; |
49 |
import es.unex.sextante.core.ObjectAndDescription; |
50 |
import es.unex.sextante.core.OutputObjectsSet; |
51 |
import es.unex.sextante.core.ParametersSet; |
52 |
import es.unex.sextante.core.Sextante; |
53 |
import es.unex.sextante.dataObjects.I3DRasterLayer; |
54 |
import es.unex.sextante.dataObjects.IDataObject; |
55 |
import es.unex.sextante.dataObjects.IRasterLayer; |
56 |
import es.unex.sextante.dataObjects.ITable; |
57 |
import es.unex.sextante.dataObjects.IVectorLayer; |
58 |
import es.unex.sextante.exceptions.NullParameterAdditionalInfoException; |
59 |
import es.unex.sextante.exceptions.WrongInputException; |
60 |
import es.unex.sextante.exceptions.WrongOutputChannelDataException; |
61 |
import es.unex.sextante.exceptions.WrongOutputIDException; |
62 |
import es.unex.sextante.exceptions.WrongParameterIDException; |
63 |
import es.unex.sextante.gui.core.SextanteGUI; |
64 |
import es.unex.sextante.gui.exceptions.LayerCannotBeOverwrittenException; |
65 |
import es.unex.sextante.gui.grass.GrassAlgorithm; |
66 |
import es.unex.sextante.gui.help.HelpElement; |
67 |
import es.unex.sextante.gui.help.HelpIO; |
68 |
import es.unex.sextante.outputs.IOutputChannel; |
69 |
import es.unex.sextante.outputs.Output; |
70 |
import es.unex.sextante.outputs.Output3DRasterLayer; |
71 |
import es.unex.sextante.outputs.OutputRasterLayer; |
72 |
import es.unex.sextante.outputs.OutputTable; |
73 |
import es.unex.sextante.outputs.OutputVectorLayer; |
74 |
import es.unex.sextante.outputs.OverwriteOutputChannel; |
75 |
import es.unex.sextante.parameters.FixedTableModel; |
76 |
import es.unex.sextante.parameters.Parameter; |
77 |
import es.unex.sextante.parameters.Parameter3DRasterLayer; |
78 |
import es.unex.sextante.parameters.ParameterBand; |
79 |
import es.unex.sextante.parameters.ParameterBoolean; |
80 |
import es.unex.sextante.parameters.ParameterDataObject; |
81 |
import es.unex.sextante.parameters.ParameterFilepath; |
82 |
import es.unex.sextante.parameters.ParameterFixedTable; |
83 |
import es.unex.sextante.parameters.ParameterMultipleInput; |
84 |
import es.unex.sextante.parameters.ParameterNumericalValue; |
85 |
import es.unex.sextante.parameters.ParameterPoint; |
86 |
import es.unex.sextante.parameters.ParameterRasterLayer; |
87 |
import es.unex.sextante.parameters.ParameterSelection; |
88 |
import es.unex.sextante.parameters.ParameterString; |
89 |
import es.unex.sextante.parameters.ParameterTable; |
90 |
import es.unex.sextante.parameters.ParameterTableField; |
91 |
import es.unex.sextante.parameters.ParameterTableFilter; |
92 |
import es.unex.sextante.parameters.ParameterVectorLayer; |
93 |
import es.unex.sextante.parameters.RasterLayerAndBand; |
94 |
import javax.swing.ImageIcon; |
95 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
96 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
97 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
98 |
|
99 |
/**
|
100 |
* A panel to introduce parameters for a geoalgorithm, created automatically based on the parameters needed by that geoalgorithm
|
101 |
* If no additional panel is provided for an algorithm, SEXTANTE will use this panel as the default one.
|
102 |
*
|
103 |
* @author volaya
|
104 |
*
|
105 |
*/
|
106 |
public class DefaultParametersPanel |
107 |
extends
|
108 |
GeoAlgorithmParametersPanel { |
109 |
|
110 |
protected static int CELL_HEIGHT = 18; |
111 |
protected static int COLUMN_WIDTH = 250; |
112 |
|
113 |
protected int m_iCurrentRow = 0; |
114 |
protected JScrollPane jScrollPanelParameters; |
115 |
protected JPanel jPanelParameters; |
116 |
protected ArrayList m_ParameterContainer = new ArrayList(); |
117 |
protected ArrayList m_ComboBox = new ArrayList(); |
118 |
protected GeoAlgorithm m_Algorithm;
|
119 |
protected ArrayList m_OutputParameterContainer = new ArrayList(); |
120 |
protected HashMap m_HelpElements; |
121 |
|
122 |
|
123 |
/**
|
124 |
* Constructor.
|
125 |
*/
|
126 |
public DefaultParametersPanel() {
|
127 |
|
128 |
super();
|
129 |
|
130 |
} |
131 |
|
132 |
|
133 |
@Override
|
134 |
public void init(final GeoAlgorithm alg) { |
135 |
|
136 |
m_Algorithm = alg; |
137 |
|
138 |
try {
|
139 |
final ArrayList list = HelpIO.open(SextanteGUI.getAlgorithmHelpFilename(alg, false)); |
140 |
|
141 |
if (list != null) { |
142 |
m_HelpElements = HelpIO.createMap(list); |
143 |
} |
144 |
else {
|
145 |
m_HelpElements = new HashMap(); |
146 |
} |
147 |
} |
148 |
catch (final Exception e) { |
149 |
m_HelpElements = new HashMap(); |
150 |
} |
151 |
|
152 |
initGUI(); |
153 |
|
154 |
} |
155 |
|
156 |
|
157 |
protected void initGUI() { |
158 |
|
159 |
m_ComboBox = new ArrayList(); |
160 |
|
161 |
{ |
162 |
jScrollPanelParameters = new JScrollPane(); |
163 |
jPanelParameters = new JPanel(); |
164 |
|
165 |
int guiRows = 0; |
166 |
|
167 |
final JPanel jInputs = new JPanel(); |
168 |
final JPanel jOptions = new JPanel(); |
169 |
final JPanel jOutputs = new JPanel(); |
170 |
|
171 |
final double[][] inputs_matrix = getInputsTableLayoutMatrix(); |
172 |
if (inputs_matrix[1].length > 1) { |
173 |
final TableLayout jInputsLayout = new TableLayout(inputs_matrix); |
174 |
jInputsLayout.setHGap(5);
|
175 |
jInputsLayout.setVGap(5);
|
176 |
jInputs.setLayout(jInputsLayout); |
177 |
|
178 |
jInputs.setBorder(BorderFactory.createTitledBorder(Sextante.getText("Inputs"))); |
179 |
|
180 |
jPanelParameters.add(jInputs, BorderLayout.NORTH);
|
181 |
guiRows += inputs_matrix[1].length;
|
182 |
|
183 |
} |
184 |
|
185 |
final double[][] options_matrix = getOptionsTableLayoutMatrix(); |
186 |
if (options_matrix[1].length > 1) { |
187 |
final TableLayout jOptionsLayout = new TableLayout(options_matrix); |
188 |
jOptionsLayout.setHGap(5);
|
189 |
jOptionsLayout.setVGap(5);
|
190 |
jOptions.setLayout(jOptionsLayout); |
191 |
|
192 |
jOptions.setBorder(BorderFactory.createTitledBorder(Sextante.getText("Options"))); |
193 |
|
194 |
jPanelParameters.add(jOptions, BorderLayout.CENTER);
|
195 |
guiRows += options_matrix[1].length;
|
196 |
} |
197 |
|
198 |
final double[][] outputs_matrix = getOutputsTableLayoutMatrix(); |
199 |
if (outputs_matrix[1].length > 1) { |
200 |
|
201 |
final TableLayout jOutputsLayout = new TableLayout(getOutputsTableLayoutMatrix()); |
202 |
jOutputsLayout.setHGap(5);
|
203 |
jOutputsLayout.setVGap(5);
|
204 |
jOutputs.setLayout(jOutputsLayout); |
205 |
|
206 |
jOutputs.setBorder(BorderFactory.createTitledBorder(Sextante.getText("Outputs"))); |
207 |
|
208 |
jPanelParameters.add(jOutputs, BorderLayout.SOUTH);
|
209 |
guiRows += outputs_matrix[1].length;
|
210 |
} |
211 |
|
212 |
if (m_Algorithm.requiresRasterLayers() || m_Algorithm.requiresMultipleRasterLayers()
|
213 |
|| m_Algorithm.requiresMultipleRasterBands()) { |
214 |
addRasterLayers(jInputs); |
215 |
} |
216 |
if (m_Algorithm.requires3DRasterLayers()) {
|
217 |
add3DRasterLayers(jInputs); |
218 |
} |
219 |
if (m_Algorithm.requiresVectorLayers() || m_Algorithm.requiresMultipleVectorLayers()) {
|
220 |
addVectorLayers(jInputs); |
221 |
} |
222 |
if (m_Algorithm.requiresTables() || m_Algorithm.requiresMultipleTables()) {
|
223 |
addTables(jInputs); |
224 |
} |
225 |
if (m_Algorithm.requiresNonDataObjects()) {
|
226 |
addNonDataObjects(jOptions); |
227 |
} |
228 |
if (m_Algorithm.generatesLayersOrTables()) {
|
229 |
addOutputObjects(jOutputs); |
230 |
} |
231 |
|
232 |
final int gui_height = (int) (CELL_HEIGHT * guiRows * 1.5); |
233 |
jPanelParameters.setPreferredSize(new Dimension(660, gui_height)); |
234 |
jScrollPanelParameters.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
235 |
jScrollPanelParameters.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
236 |
jScrollPanelParameters.setPreferredSize(new java.awt.Dimension(680, 300)); |
237 |
jScrollPanelParameters.setViewportView(jPanelParameters); |
238 |
this.add(jScrollPanelParameters);
|
239 |
|
240 |
for (int i = 0; i < m_ParameterContainer.size(); i++) { |
241 |
final ParameterContainer pc = (ParameterContainer) m_ParameterContainer.get(i);
|
242 |
final HelpElement help = (HelpElement) m_HelpElements.get(pc.getParameter().getParameterName());
|
243 |
if (m_Algorithm instanceof GrassAlgorithm) { |
244 |
if (pc.getParameter().getParameterTooltip() != null) { |
245 |
pc.getContainer().setToolTipText(pc.getParameter().getParameterTooltip()); |
246 |
} |
247 |
} |
248 |
if (help != null) { |
249 |
pc.getContainer().setToolTipText("<html>" + help.getTextAsFormattedHTML() + "</html>"); |
250 |
} |
251 |
} |
252 |
|
253 |
} |
254 |
} |
255 |
|
256 |
|
257 |
protected void addOutputObjects(final JPanel pane) { |
258 |
|
259 |
String sDescription;
|
260 |
final OutputObjectsSet ooset = m_Algorithm.getOutputObjects();
|
261 |
|
262 |
m_iCurrentRow = 0;
|
263 |
|
264 |
for (int i = 0; i < ooset.getOutputObjectsCount(); i++) { |
265 |
final Output out = ooset.getOutput(i);
|
266 |
if ((out instanceof OutputRasterLayer) || (out instanceof OutputVectorLayer) || (out instanceof OutputTable) |
267 |
|| (out instanceof Output3DRasterLayer)) {
|
268 |
sDescription = out.getDescription() + "[" + out.getTypeDescription() + "]"; |
269 |
addTitleLabel(pane, sDescription, m_iCurrentRow, false);
|
270 |
final OutputChannelSelectionPanel panel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters()); |
271 |
final HelpElement help = (HelpElement) m_HelpElements.get(out.getName());
|
272 |
if (help != null) { |
273 |
panel.setToolTipText("<html>" + help.getTextAsFormattedHTML() + "</html>"); |
274 |
} |
275 |
pane.add(panel, getStringTableCoords(2, m_iCurrentRow));
|
276 |
|
277 |
m_iCurrentRow++; |
278 |
m_OutputParameterContainer.add(new OutputParameterContainer(out.getName(), panel));
|
279 |
} |
280 |
} |
281 |
|
282 |
} |
283 |
|
284 |
|
285 |
protected void addRasterLayers(final JPanel pane) { |
286 |
|
287 |
int i, j;
|
288 |
boolean bAddNotSetField = false; |
289 |
final ArrayList childComboBoxIndex = new ArrayList(); |
290 |
Parameter parameter; |
291 |
Parameter subParameter; |
292 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
293 |
JComboBox comboBox;
|
294 |
String sParameterName;
|
295 |
|
296 |
addTitleLabel(pane, Sextante.getText("Raster_layers"), m_iCurrentRow, true); |
297 |
m_iCurrentRow++; |
298 |
|
299 |
for (i = 0; i < m_Algorithm.getNumberOfParameters(); i++) { |
300 |
parameter = parameters.getParameter(i); |
301 |
if (parameter instanceof ParameterRasterLayer) { |
302 |
//check for bands that depend on this raster layer
|
303 |
sParameterName = parameter.getParameterName(); |
304 |
childComboBoxIndex.clear(); |
305 |
for (j = 0; j < m_Algorithm.getNumberOfParameters(); j++) { |
306 |
subParameter = parameters.getParameter(j); |
307 |
if (subParameter instanceof ParameterBand) { |
308 |
try {
|
309 |
if (((AdditionalInfoBand) subParameter.getParameterAdditionalInfo()).getParentParameterName().equals(
|
310 |
sParameterName)) { |
311 |
m_iCurrentRow++; |
312 |
addTitleLabel(pane, " " + subParameter.getParameterDescription(), m_iCurrentRow, false); |
313 |
comboBox = getBandSelectionComboBox(); |
314 |
childComboBoxIndex.add(new Integer(m_ComboBox.size())); |
315 |
m_ComboBox.add(comboBox); |
316 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow));
|
317 |
m_ParameterContainer.add(new ParameterContainer(subParameter, comboBox));
|
318 |
} |
319 |
} |
320 |
catch (final NullParameterAdditionalInfoException e) { |
321 |
Sextante.addErrorToLog(e); |
322 |
} |
323 |
} |
324 |
} |
325 |
try {
|
326 |
if (((AdditionalInfoRasterLayer) parameter.getParameterAdditionalInfo()).getIsMandatory()) {
|
327 |
bAddNotSetField = false;
|
328 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow - childComboBoxIndex.size(), false);
|
329 |
} |
330 |
else {
|
331 |
bAddNotSetField = true;
|
332 |
addTitleLabel(pane, parameter.getParameterDescription() + Sextante.getText("[optional]"),
|
333 |
m_iCurrentRow - childComboBoxIndex.size(), false);
|
334 |
} |
335 |
} |
336 |
catch (final NullParameterAdditionalInfoException e) { |
337 |
Sextante.addErrorToLog(e); |
338 |
} |
339 |
comboBox = getRasterLayerSelectionComboBox(childComboBoxIndex, bAddNotSetField); |
340 |
if (bAddNotSetField) {
|
341 |
comboBox.setSelectedIndex(0);
|
342 |
} |
343 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow - childComboBoxIndex.size()));
|
344 |
m_iCurrentRow++; |
345 |
m_ParameterContainer.add(new ParameterContainer(parameter, comboBox));
|
346 |
} |
347 |
else if (parameter instanceof ParameterMultipleInput) { |
348 |
try {
|
349 |
final AdditionalInfoMultipleInput additionalInfo = (AdditionalInfoMultipleInput) parameter.getParameterAdditionalInfo();
|
350 |
|
351 |
if ((additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_RASTER)
|
352 |
|| (additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_BAND)) { |
353 |
addMultipleInput(pane, (ParameterMultipleInput) parameter); |
354 |
} |
355 |
} |
356 |
catch (final NullParameterAdditionalInfoException e) { |
357 |
Sextante.addErrorToLog(e); |
358 |
} |
359 |
} |
360 |
} |
361 |
} |
362 |
|
363 |
|
364 |
protected void add3DRasterLayers(final JPanel pane) { |
365 |
|
366 |
int i;
|
367 |
boolean bAddNotSetField = false; |
368 |
Parameter parameter; |
369 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
370 |
JComboBox comboBox;
|
371 |
|
372 |
addTitleLabel(pane, Sextante.getText("3DRaster_layers"), m_iCurrentRow, true); |
373 |
m_iCurrentRow++; |
374 |
|
375 |
for (i = 0; i < m_Algorithm.getNumberOfParameters(); i++) { |
376 |
parameter = parameters.getParameter(i); |
377 |
if (parameter instanceof Parameter3DRasterLayer) { |
378 |
try {
|
379 |
if (((AdditionalInfoRasterLayer) parameter.getParameterAdditionalInfo()).getIsMandatory()) {
|
380 |
bAddNotSetField = false;
|
381 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
382 |
} |
383 |
else {
|
384 |
bAddNotSetField = true;
|
385 |
addTitleLabel(pane, parameter.getParameterDescription() + Sextante.getText("[optional]"), m_iCurrentRow, false); |
386 |
} |
387 |
} |
388 |
catch (final NullParameterAdditionalInfoException e) { |
389 |
Sextante.addErrorToLog(e); |
390 |
} |
391 |
comboBox = get3DRasterLayerSelectionComboBox(bAddNotSetField); |
392 |
if (bAddNotSetField) {
|
393 |
comboBox.setSelectedIndex(0);
|
394 |
} |
395 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow));
|
396 |
m_iCurrentRow++; |
397 |
m_ParameterContainer.add(new ParameterContainer(parameter, comboBox));
|
398 |
} |
399 |
} |
400 |
} |
401 |
|
402 |
|
403 |
protected void addVectorLayers(final JPanel pane) { |
404 |
|
405 |
boolean bAddNotSetField = false; |
406 |
int i, j;
|
407 |
String sParameterName;
|
408 |
final ArrayList childComboBoxIndex = new ArrayList(); |
409 |
|
410 |
Parameter parameter; |
411 |
Parameter subParameter; |
412 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
413 |
JComboBox comboBox;
|
414 |
|
415 |
addTitleLabel(pane, Sextante.getText("Vector_layer"), m_iCurrentRow, true); |
416 |
m_iCurrentRow++; |
417 |
|
418 |
|
419 |
for (i = 0; i < m_Algorithm.getNumberOfParameters(); i++) { |
420 |
//int tableFiltersApplied = 0;
|
421 |
parameter = parameters.getParameter(i); |
422 |
if (parameter instanceof ParameterVectorLayer) { |
423 |
try {
|
424 |
int[] shapeTypes = ((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getShapeTypes(); |
425 |
//check for table fields that depend on this vector layer
|
426 |
sParameterName = parameter.getParameterName(); |
427 |
childComboBoxIndex.clear(); |
428 |
|
429 |
for (j = 0; j < m_Algorithm.getNumberOfParameters(); j++) { |
430 |
subParameter = parameters.getParameter(j); |
431 |
if (subParameter instanceof ParameterTableField) { |
432 |
try {
|
433 |
if (((AdditionalInfoTableField) subParameter.getParameterAdditionalInfo()).getParentParameterName().equals(
|
434 |
sParameterName)) { |
435 |
m_iCurrentRow++; |
436 |
addTitleLabel(pane, " " + subParameter.getParameterDescription(), m_iCurrentRow, false); |
437 |
comboBox = getVectorLayerFieldSelectionComboBox(shapeTypes); |
438 |
childComboBoxIndex.add(new Integer(m_ComboBox.size())); |
439 |
m_ComboBox.add(comboBox); |
440 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow));
|
441 |
m_ParameterContainer.add(new ParameterContainer(subParameter, comboBox));
|
442 |
} |
443 |
} |
444 |
catch (final NullParameterAdditionalInfoException e) { |
445 |
Sextante.addErrorToLog(e); |
446 |
} |
447 |
} else if (subParameter instanceof ParameterTableFilter) { |
448 |
if (((AdditionalInfoTableFilter) subParameter.getParameterAdditionalInfo()).getParentParameterName().equals(
|
449 |
sParameterName)) { |
450 |
addTableFilter(pane, (ParameterVectorLayer) parameter, (ParameterTableFilter) subParameter, shapeTypes, childComboBoxIndex); |
451 |
//tableFiltersApplied++;
|
452 |
} |
453 |
} |
454 |
} |
455 |
} |
456 |
catch (final NullParameterAdditionalInfoException e1) { |
457 |
e1.printStackTrace(); |
458 |
} |
459 |
// add vector layer
|
460 |
try {
|
461 |
AdditionalInfoVectorLayer parameterAdditionalInfo = (AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo(); |
462 |
// iShapeType = parameterAdditionalInfo.getShapeType();
|
463 |
int[] shapeTypes = parameterAdditionalInfo.getShapeTypes(); |
464 |
|
465 |
if (((AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo()).getIsMandatory()) {
|
466 |
bAddNotSetField = false;
|
467 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow - childComboBoxIndex.size(), false); //- tableFiltersApplied |
468 |
} |
469 |
else {
|
470 |
bAddNotSetField = true;
|
471 |
addTitleLabel(pane, parameter.getParameterDescription() + Sextante.getText("[optional]"),
|
472 |
m_iCurrentRow - childComboBoxIndex.size(), false);
|
473 |
} |
474 |
comboBox = getVectorLayerSelectionComboBox(shapeTypes, childComboBoxIndex, bAddNotSetField); |
475 |
if (bAddNotSetField) {
|
476 |
comboBox.setSelectedIndex(0);
|
477 |
} |
478 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow - childComboBoxIndex.size())); // -tableFilerApplied |
479 |
m_iCurrentRow++; |
480 |
m_ParameterContainer.add(new ParameterContainer(parameter, comboBox));
|
481 |
} |
482 |
catch (final NullParameterAdditionalInfoException e) { |
483 |
Sextante.addErrorToLog(e); |
484 |
} |
485 |
} |
486 |
else if (parameter instanceof ParameterMultipleInput) { |
487 |
try {
|
488 |
final AdditionalInfoMultipleInput additionalInfo = (AdditionalInfoMultipleInput) parameter.getParameterAdditionalInfo();
|
489 |
|
490 |
if ((additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POINT)
|
491 |
|| (additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_LINE) |
492 |
|| (additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POLYGON) |
493 |
|| (additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY)) { |
494 |
addMultipleInput(pane, (ParameterMultipleInput) parameter); |
495 |
} |
496 |
} |
497 |
catch (final NullParameterAdditionalInfoException e) { |
498 |
Sextante.addErrorToLog(e); |
499 |
} |
500 |
} |
501 |
} |
502 |
} |
503 |
|
504 |
|
505 |
protected void addTables(final JPanel pane) { |
506 |
|
507 |
boolean bAddNotSetField = false; |
508 |
int i, j;
|
509 |
String sParameterName;
|
510 |
final ArrayList childComboBoxIndex = new ArrayList(); |
511 |
Parameter parameter; |
512 |
Parameter subParameter; |
513 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
514 |
JComboBox comboBox;
|
515 |
|
516 |
addTitleLabel(pane, Sextante.getText("Tables"), m_iCurrentRow, true); |
517 |
m_iCurrentRow++; |
518 |
|
519 |
for (i = 0; i < m_Algorithm.getNumberOfParameters(); i++) { |
520 |
parameter = parameters.getParameter(i); |
521 |
if (parameter instanceof ParameterTable) { |
522 |
//check for table fields that depend on this table
|
523 |
//int[] tableTypes = ((AdditionalInfoTable) parameter.getParameterAdditionalInfo()); //.getShapeTypes();
|
524 |
|
525 |
sParameterName = parameter.getParameterName(); |
526 |
childComboBoxIndex.clear(); |
527 |
for (j = 0; j < m_Algorithm.getNumberOfParameters(); j++) { |
528 |
subParameter = parameters.getParameter(j); |
529 |
if (subParameter instanceof ParameterTableField) { |
530 |
try {
|
531 |
if (((AdditionalInfoTableField) subParameter.getParameterAdditionalInfo()).getParentParameterName().equals(
|
532 |
sParameterName)) { |
533 |
m_iCurrentRow++; |
534 |
addTitleLabel(pane, " " + subParameter.getParameterDescription(), m_iCurrentRow, false); |
535 |
comboBox = getTableFieldSelectionComboBox(); |
536 |
childComboBoxIndex.add(new Integer(m_ComboBox.size())); |
537 |
m_ComboBox.add(comboBox); |
538 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow));
|
539 |
m_ParameterContainer.add(new ParameterContainer(subParameter, comboBox));
|
540 |
} |
541 |
} |
542 |
catch (final NullParameterAdditionalInfoException e) { |
543 |
Sextante.addErrorToLog(e); |
544 |
} |
545 |
} else if (subParameter instanceof ParameterTableFilter) { |
546 |
try {
|
547 |
if (((AdditionalInfoTableFilter) subParameter.getParameterAdditionalInfo()).getParentParameterName().equals(
|
548 |
sParameterName)) { |
549 |
Object shapeTypes = null; |
550 |
addTableFilter(pane, (ParameterTable) parameter, (ParameterTableFilter) subParameter, childComboBoxIndex); |
551 |
//tableFiltersApplied++;
|
552 |
} |
553 |
} catch (NullParameterAdditionalInfoException ex) {
|
554 |
Sextante.addErrorToLog(ex); |
555 |
} |
556 |
} |
557 |
} |
558 |
// add table
|
559 |
try {
|
560 |
if (((AdditionalInfoTable) parameter.getParameterAdditionalInfo()).getIsMandatory()) {
|
561 |
bAddNotSetField = false;
|
562 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow - childComboBoxIndex.size(), false);
|
563 |
} |
564 |
else {
|
565 |
bAddNotSetField = true;
|
566 |
addTitleLabel(pane, parameter.getParameterDescription() + Sextante.getText("[optional]"),
|
567 |
m_iCurrentRow - childComboBoxIndex.size(), false);
|
568 |
} |
569 |
} |
570 |
catch (final NullParameterAdditionalInfoException e) { |
571 |
Sextante.addErrorToLog(e); |
572 |
} |
573 |
comboBox = getTableSelectionComboBox(childComboBoxIndex, bAddNotSetField); |
574 |
if (bAddNotSetField) {
|
575 |
comboBox.setSelectedIndex(comboBox.getItemCount() - 1);
|
576 |
} |
577 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow - childComboBoxIndex.size()));
|
578 |
m_iCurrentRow++; |
579 |
m_ParameterContainer.add(new ParameterContainer(parameter, comboBox));
|
580 |
} |
581 |
else if (parameter instanceof ParameterMultipleInput) { |
582 |
try {
|
583 |
final AdditionalInfoMultipleInput additionalInfo = (AdditionalInfoMultipleInput) parameter.getParameterAdditionalInfo();
|
584 |
|
585 |
if (additionalInfo.getDataType() == AdditionalInfoMultipleInput.DATA_TYPE_TABLE) {
|
586 |
addMultipleInput(pane, (ParameterMultipleInput) parameter); |
587 |
} |
588 |
} |
589 |
catch (final NullParameterAdditionalInfoException e) { |
590 |
Sextante.addErrorToLog(e); |
591 |
} |
592 |
} |
593 |
} |
594 |
|
595 |
} |
596 |
|
597 |
|
598 |
protected void addNonDataObjects(final JPanel pane) { |
599 |
|
600 |
int i;
|
601 |
Parameter parameter; |
602 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
603 |
|
604 |
m_iCurrentRow = 0;
|
605 |
|
606 |
for (i = 0; i < m_Algorithm.getNumberOfParameters(); i++) { |
607 |
parameter = parameters.getParameter(i); |
608 |
if (parameter instanceof ParameterNumericalValue) { |
609 |
addNumericalTextField(pane, (ParameterNumericalValue) parameter); |
610 |
} |
611 |
else if (parameter instanceof ParameterString) { |
612 |
addStringTextField(pane, (ParameterString) parameter); |
613 |
} |
614 |
else if (parameter instanceof ParameterSelection) { |
615 |
addSelection(pane, (ParameterSelection) parameter); |
616 |
} |
617 |
else if (parameter instanceof ParameterFixedTable) { |
618 |
addFixedTable(pane, (ParameterFixedTable) parameter); |
619 |
} |
620 |
else if (parameter instanceof ParameterPoint) { |
621 |
addPoint(pane, (ParameterPoint) parameter); |
622 |
} |
623 |
else if (parameter instanceof ParameterBoolean) { |
624 |
addCheckBox(pane, (ParameterBoolean) parameter); |
625 |
} |
626 |
else if (parameter instanceof ParameterFilepath) { |
627 |
addFilepath(pane, (ParameterFilepath) parameter); |
628 |
} |
629 |
} |
630 |
} |
631 |
|
632 |
|
633 |
protected void addMultipleInput(final JPanel pane, |
634 |
final ParameterMultipleInput parameter) {
|
635 |
|
636 |
Object[] objs; |
637 |
|
638 |
try {
|
639 |
final AdditionalInfoMultipleInput additionalInfo = (AdditionalInfoMultipleInput) parameter.getParameterAdditionalInfo();
|
640 |
|
641 |
switch (additionalInfo.getDataType()) {
|
642 |
case AdditionalInfoMultipleInput.DATA_TYPE_RASTER:
|
643 |
objs = SextanteGUI.getInputFactory().getRasterLayers(); |
644 |
break;
|
645 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY:
|
646 |
objs = SextanteGUI.getInputFactory().getVectorLayers(AdditionalInfoVectorLayer.SHAPE_TYPE_ANY); |
647 |
//objs = getVectorLayersAsObjectAndDescription(AdditionalInfoVectorLayer.SHAPE_TYPE_ANY);
|
648 |
break;
|
649 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POINT:
|
650 |
objs = SextanteGUI.getInputFactory().getVectorLayers(AdditionalInfoVectorLayer.SHAPE_TYPE_POINT); |
651 |
break;
|
652 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_LINE:
|
653 |
objs = SextanteGUI.getInputFactory().getVectorLayers(AdditionalInfoVectorLayer.SHAPE_TYPE_POINT); |
654 |
break;
|
655 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POLYGON:
|
656 |
objs = SextanteGUI.getInputFactory().getVectorLayers(AdditionalInfoVectorLayer.SHAPE_TYPE_POLYGON); |
657 |
//objs = getVectorLayersAsObjectAndDescription(AdditionalInfoVectorLayer.SHAPE_TYPE_POLYGON);
|
658 |
break;
|
659 |
case AdditionalInfoMultipleInput.DATA_TYPE_TABLE:
|
660 |
objs = SextanteGUI.getInputFactory().getTables(); |
661 |
break;
|
662 |
case AdditionalInfoMultipleInput.DATA_TYPE_BAND:
|
663 |
objs = SextanteGUI.getInputFactory().getBands(); |
664 |
break;
|
665 |
default:
|
666 |
return;
|
667 |
} |
668 |
|
669 |
String sDescription = parameter.getParameterDescription();
|
670 |
if (!additionalInfo.getIsMandatory()) {
|
671 |
sDescription = sDescription + Sextante.getText("[optional]");
|
672 |
} |
673 |
|
674 |
addTitleLabel(pane, sDescription, m_iCurrentRow, false);
|
675 |
|
676 |
final CheckComboBox ccb = new CheckComboBox(); |
677 |
ccb.setTextFor(CheckComboBox.NONE, Sextante.getText("no_elements_selected"));
|
678 |
ccb.setTextFor(CheckComboBox.MULTIPLE, Sextante.getText("multiple_elements_selected"));
|
679 |
final ListCheckModel model = ccb.getModel();
|
680 |
for (final Object obj : objs) { |
681 |
|
682 |
model.addElement(obj); |
683 |
} |
684 |
//
|
685 |
//ccb.setRenderer(renderer);
|
686 |
final BatchSelection bs = new BatchSelection.CheckBox(); |
687 |
final EmbeddedComponent comp = new EmbeddedComponent(bs, Anchor.NORTH); |
688 |
ccb.setEmbeddedComponent(comp); |
689 |
|
690 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
691 |
|
692 |
pane.add(ccb, getStringTableCoords(2, m_iCurrentRow));
|
693 |
m_ParameterContainer.add(new ParameterContainer(parameter, ccb));
|
694 |
m_iCurrentRow++; |
695 |
} |
696 |
catch (final NullParameterAdditionalInfoException e) { |
697 |
Sextante.addErrorToLog(e); |
698 |
} |
699 |
} |
700 |
|
701 |
|
702 |
protected void addFixedTable(final JPanel pane, |
703 |
final ParameterFixedTable parameter) {
|
704 |
|
705 |
boolean bIsNumberOfRowsFixed;
|
706 |
int iRows;
|
707 |
String[] sCols; |
708 |
|
709 |
try {
|
710 |
final AdditionalInfoFixedTable additionalInfo = (AdditionalInfoFixedTable) parameter.getParameterAdditionalInfo();
|
711 |
|
712 |
iRows = additionalInfo.getRowsCount(); |
713 |
sCols = additionalInfo.getCols(); |
714 |
bIsNumberOfRowsFixed = additionalInfo.isNumberOfRowsFixed(); |
715 |
|
716 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
717 |
|
718 |
final FixedTablePanel fixedTablePanel = new FixedTablePanel(sCols, iRows, bIsNumberOfRowsFixed); |
719 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
720 |
|
721 |
pane.add(fixedTablePanel, getStringTableCoords(2, m_iCurrentRow));
|
722 |
m_ParameterContainer.add(new ParameterContainer(parameter, fixedTablePanel));
|
723 |
m_iCurrentRow++; |
724 |
} |
725 |
catch (final NullParameterAdditionalInfoException e) { |
726 |
Sextante.addErrorToLog(e); |
727 |
} |
728 |
|
729 |
} |
730 |
|
731 |
|
732 |
protected void addFilepath(final JPanel pane, |
733 |
final ParameterFilepath parameter) {
|
734 |
|
735 |
try {
|
736 |
final AdditionalInfoFilepath additionalInfo = (AdditionalInfoFilepath) parameter.getParameterAdditionalInfo();
|
737 |
|
738 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
739 |
|
740 |
String sExtension = "*.*"; |
741 |
final String[] sExtensions = additionalInfo.getExtensions(); |
742 |
if (sExtensions != null) { |
743 |
final StringBuffer sb = new StringBuffer(); |
744 |
for (int i = 0; i < sExtensions.length; i++) { |
745 |
sb.append(sExtensions[i]); |
746 |
if (i < sExtensions.length - 1) { |
747 |
sb.append(",");
|
748 |
} |
749 |
} |
750 |
sExtension = sb.toString(); |
751 |
} |
752 |
final FileSelectionPanel fileSelectionPanel = new FileSelectionPanel(additionalInfo.isFolder(), |
753 |
additionalInfo.isOpenDialog(), additionalInfo.getExtensions(), Sextante.getText("Files") + " " + sExtension); |
754 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
755 |
|
756 |
pane.add(fileSelectionPanel, getStringTableCoords(2, m_iCurrentRow));
|
757 |
m_ParameterContainer.add(new ParameterContainer(parameter, fileSelectionPanel));
|
758 |
m_iCurrentRow++; |
759 |
} |
760 |
catch (final NullParameterAdditionalInfoException e) { |
761 |
Sextante.addErrorToLog(e); |
762 |
} |
763 |
|
764 |
} |
765 |
protected void addTableFilter(final JPanel pane, |
766 |
final ParameterTable parameter,
|
767 |
final ParameterTableFilter subParameter,
|
768 |
ArrayList childComboBoxIndex) {
|
769 |
|
770 |
try {
|
771 |
final AdditionalInfoTable additionalInfo = (AdditionalInfoTable) parameter.getParameterAdditionalInfo();
|
772 |
m_iCurrentRow++; |
773 |
addTitleLabel(pane, " " + subParameter.getParameterDescription(), m_iCurrentRow, false); |
774 |
} catch (final NullParameterAdditionalInfoException e) { |
775 |
Sextante.addErrorToLog(e); |
776 |
} |
777 |
TableFilterPanel tableFilterPanel; |
778 |
// IVectorLayer ivlayer = parameter.getParameterValueAsVectorLayer();
|
779 |
List<ITable> tables = getTables();
|
780 |
if (tables.size() > 0) { |
781 |
ITable table = tables.get(0);
|
782 |
FeatureStore store = table.getFeatureStore(); |
783 |
tableFilterPanel = new TableFilterPanel(store);
|
784 |
} else {
|
785 |
tableFilterPanel = new TableFilterPanel();
|
786 |
} |
787 |
childComboBoxIndex.add(new Integer(m_ComboBox.size())); |
788 |
pane.add(tableFilterPanel, getStringTableCoords(2, m_iCurrentRow));
|
789 |
m_ComboBox.add(tableFilterPanel); |
790 |
m_ParameterContainer.add(new ParameterContainer(subParameter, tableFilterPanel));
|
791 |
|
792 |
} |
793 |
|
794 |
protected void addTableFilter(final JPanel pane, |
795 |
final ParameterVectorLayer parameter,
|
796 |
final ParameterTableFilter subParameter,
|
797 |
int[] shapeTypes, |
798 |
ArrayList childComboBoxIndex) {
|
799 |
|
800 |
try {
|
801 |
final AdditionalInfoVectorLayer additionalInfo = (AdditionalInfoVectorLayer) parameter.getParameterAdditionalInfo();
|
802 |
m_iCurrentRow++; |
803 |
addTitleLabel(pane, " " + subParameter.getParameterDescription(), m_iCurrentRow, false); |
804 |
} catch (final NullParameterAdditionalInfoException e) { |
805 |
Sextante.addErrorToLog(e); |
806 |
} |
807 |
TableFilterPanel tableFilterPanel; |
808 |
// IVectorLayer ivlayer = parameter.getParameterValueAsVectorLayer();
|
809 |
List<IVectorLayer> layers = getVectorLayers(shapeTypes);
|
810 |
if (layers.size() > 0) { |
811 |
IVectorLayer ivlayer = layers.get(0);
|
812 |
FeatureStore store = ivlayer.getFeatureStore(); |
813 |
tableFilterPanel = new TableFilterPanel(store);
|
814 |
} else {
|
815 |
tableFilterPanel = new TableFilterPanel();
|
816 |
} |
817 |
childComboBoxIndex.add(new Integer(m_ComboBox.size())); |
818 |
pane.add(tableFilterPanel, getStringTableCoords(2, m_iCurrentRow));
|
819 |
m_ComboBox.add(tableFilterPanel); |
820 |
m_ParameterContainer.add(new ParameterContainer(subParameter, tableFilterPanel));
|
821 |
|
822 |
} |
823 |
|
824 |
protected void addPoint(final JPanel pane, |
825 |
final ParameterPoint parameter) {
|
826 |
|
827 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
828 |
|
829 |
final PointSelectionPanel pointSelectionPanel = new PointSelectionPanel(); |
830 |
|
831 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
832 |
|
833 |
pane.add(pointSelectionPanel, getStringTableCoords(2, m_iCurrentRow));
|
834 |
m_ParameterContainer.add(new ParameterContainer(parameter, pointSelectionPanel));
|
835 |
m_iCurrentRow++; |
836 |
|
837 |
} |
838 |
|
839 |
|
840 |
protected void addSelection(final JPanel pane, |
841 |
final ParameterSelection parameter) {
|
842 |
|
843 |
try {
|
844 |
final JComboBox comboBox = new JComboBox(); |
845 |
final String[] sValues = ((AdditionalInfoSelection) parameter.getParameterAdditionalInfo()).getValues(); |
846 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(sValues); |
847 |
comboBox.setModel(defaultModel); |
848 |
comboBox.setSelectedIndex(0);
|
849 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
850 |
pane.add(comboBox, getStringTableCoords(2, m_iCurrentRow));
|
851 |
m_iCurrentRow++; |
852 |
m_ParameterContainer.add(new ParameterContainer(parameter, comboBox));
|
853 |
} |
854 |
catch (final NullParameterAdditionalInfoException e) { |
855 |
Sextante.addErrorToLog(e); |
856 |
} |
857 |
|
858 |
} |
859 |
|
860 |
|
861 |
protected void addNumericalTextField(final JPanel pane, |
862 |
final ParameterNumericalValue parameter) {
|
863 |
|
864 |
final JTextField textField = new JTextField(); |
865 |
final double dMinValue, dMaxValue; |
866 |
final int iType; |
867 |
|
868 |
try {
|
869 |
final AdditionalInfoNumericalValue additionalInfo = (AdditionalInfoNumericalValue) parameter.getParameterAdditionalInfo();
|
870 |
dMinValue = additionalInfo.getMinValue(); |
871 |
dMaxValue = additionalInfo.getMaxValue(); |
872 |
iType = additionalInfo.getType(); |
873 |
|
874 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
875 |
|
876 |
if (iType == AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE) {
|
877 |
textField.setText(Double.toString(additionalInfo.getDefaultValue()));
|
878 |
} |
879 |
else {
|
880 |
textField.setText(Integer.toString((int) additionalInfo.getDefaultValue())); |
881 |
} |
882 |
textField.addFocusListener(new FocusAdapter() { |
883 |
@Override
|
884 |
public void focusLost(final FocusEvent e) { |
885 |
final JTextField textField = (JTextField) e.getSource(); |
886 |
final String content = textField.getText(); |
887 |
if (content.length() != 0) { |
888 |
try {
|
889 |
if (iType == AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE) {
|
890 |
final double d = Double.parseDouble(content); |
891 |
if (d > dMaxValue) {
|
892 |
textField.setText(Double.toString(dMaxValue));
|
893 |
} |
894 |
if (d < dMinValue) {
|
895 |
textField.setText(Double.toString(dMinValue));
|
896 |
} |
897 |
} |
898 |
else {
|
899 |
final int i = (int) Double.parseDouble(content); |
900 |
if (i > dMaxValue) {
|
901 |
textField.setText(Integer.toString((int) dMaxValue)); |
902 |
} |
903 |
if (i < dMinValue) {
|
904 |
textField.setText(Integer.toString((int) dMinValue)); |
905 |
} |
906 |
textField.setText(Integer.toString(i));
|
907 |
} |
908 |
} |
909 |
catch (final NumberFormatException nfe) { |
910 |
getToolkit().beep(); |
911 |
textField.requestFocus(); |
912 |
} |
913 |
} |
914 |
} |
915 |
}); |
916 |
|
917 |
pane.add(textField, getStringTableCoords(2, m_iCurrentRow));
|
918 |
m_ParameterContainer.add(new ParameterContainer(parameter, textField));
|
919 |
m_iCurrentRow++; |
920 |
} |
921 |
catch (final NullParameterAdditionalInfoException e) { |
922 |
Sextante.addErrorToLog(e); |
923 |
} |
924 |
|
925 |
} |
926 |
|
927 |
|
928 |
protected void addStringTextField(final JPanel pane, |
929 |
final ParameterString parameter) {
|
930 |
|
931 |
try {
|
932 |
final AdditionalInfoString ai = (AdditionalInfoString) parameter.getParameterAdditionalInfo();
|
933 |
final JTextField textField = new JTextField(ai.getDefaultString()); |
934 |
|
935 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
936 |
|
937 |
pane.add(textField, getStringTableCoords(2, m_iCurrentRow));
|
938 |
m_ParameterContainer.add(new ParameterContainer(parameter, textField));
|
939 |
m_iCurrentRow++; |
940 |
} |
941 |
catch (final NullParameterAdditionalInfoException e) { |
942 |
Sextante.addErrorToLog(e); |
943 |
} |
944 |
|
945 |
} |
946 |
|
947 |
|
948 |
protected void addCheckBox(final JPanel pane, |
949 |
final ParameterBoolean parameter) {
|
950 |
|
951 |
final JCheckBox checkBox = new JCheckBox(); |
952 |
try {
|
953 |
final AdditionalInfoBoolean ai = (AdditionalInfoBoolean) parameter.getParameterAdditionalInfo();
|
954 |
checkBox.setSelected(ai.getDefaultValue()); |
955 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
956 |
pane.add(checkBox, getStringTableCoords(2, m_iCurrentRow));
|
957 |
m_ParameterContainer.add(new ParameterContainer(parameter, checkBox));
|
958 |
m_iCurrentRow++; |
959 |
} |
960 |
catch (final NullParameterAdditionalInfoException e) { |
961 |
Sextante.addErrorToLog(e); |
962 |
} |
963 |
|
964 |
|
965 |
} |
966 |
|
967 |
|
968 |
protected void addTitleLabel(final JPanel pane, |
969 |
final String sText, |
970 |
final int iRow, |
971 |
final boolean isSectionTitleLabel) { |
972 |
|
973 |
JLabel label;
|
974 |
label = new JLabel(); |
975 |
label.setText(sText); |
976 |
label.setPreferredSize(new java.awt.Dimension(COLUMN_WIDTH, CELL_HEIGHT));
|
977 |
|
978 |
if (isSectionTitleLabel) {
|
979 |
label.setFont(new java.awt.Font("Tahoma", 1, 11)); |
980 |
label.setForeground(java.awt.Color.BLUE); |
981 |
} |
982 |
|
983 |
pane.add(label, getStringTableCoords(1, iRow));
|
984 |
|
985 |
} |
986 |
|
987 |
|
988 |
protected String getStringTableCoords(final int iCol, |
989 |
final int iRow) { |
990 |
|
991 |
final StringBuffer sCellCoords = new StringBuffer(); |
992 |
|
993 |
sCellCoords.append(Integer.toString(iCol));
|
994 |
sCellCoords.append(",");
|
995 |
sCellCoords.append(Integer.toString(iRow));
|
996 |
|
997 |
return sCellCoords.toString();
|
998 |
|
999 |
} |
1000 |
|
1001 |
|
1002 |
protected double[][] getInputsTableLayoutMatrix() { |
1003 |
|
1004 |
int iRows = 1; |
1005 |
|
1006 |
if (m_Algorithm.requiresRasterLayers() || m_Algorithm.requiresMultipleRasterLayers()
|
1007 |
|| m_Algorithm.requiresMultipleRasterBands()) { |
1008 |
//Adds 1 for label
|
1009 |
iRows += 1;
|
1010 |
iRows += m_Algorithm.getNumberOfRasterLayers(true);
|
1011 |
final int tf_num = m_Algorithm.getNumberOfBandsParameters(); |
1012 |
if (tf_num > 0) { |
1013 |
iRows += tf_num; |
1014 |
} |
1015 |
} |
1016 |
if (m_Algorithm.requiresVectorLayers() || m_Algorithm.requiresMultipleVectorLayers()) {
|
1017 |
//Adds 1 for label
|
1018 |
iRows += 1;
|
1019 |
iRows += m_Algorithm.getNumberOfVectorLayers(true);
|
1020 |
final int tf_num = m_Algorithm.getNumberOfTableFieldsParameters(); |
1021 |
if (tf_num > 0) { |
1022 |
iRows += tf_num; |
1023 |
} |
1024 |
final int tfilter_num = m_Algorithm.getNumberOfTableFilterParameters(); |
1025 |
if (tfilter_num > 0) { |
1026 |
iRows += tfilter_num; |
1027 |
} |
1028 |
} |
1029 |
if (m_Algorithm.requiresTables() || m_Algorithm.requiresMultipleTables()) {
|
1030 |
//Adds 1 for label
|
1031 |
iRows += 1;
|
1032 |
iRows += m_Algorithm.getNumberOfTables(); |
1033 |
final int tf_num = m_Algorithm.getNumberOfTableFieldsParameters(); |
1034 |
if (tf_num > 0) { |
1035 |
iRows += tf_num; |
1036 |
} |
1037 |
} |
1038 |
if (m_Algorithm.requires3DRasterLayers()) {
|
1039 |
//Adds 1 for label
|
1040 |
iRows += 1;
|
1041 |
iRows += m_Algorithm.getParameters().getNumberOf3DRasterLayers(); |
1042 |
} |
1043 |
|
1044 |
return getTableMatrixSize(iRows);
|
1045 |
|
1046 |
} |
1047 |
|
1048 |
|
1049 |
protected double[][] getOptionsTableLayoutMatrix() { |
1050 |
|
1051 |
int iRows = 1; |
1052 |
|
1053 |
if (m_Algorithm.requiresNonDataObjects()) {
|
1054 |
iRows += m_Algorithm.getNumberOfNoDataParameters(); |
1055 |
} |
1056 |
|
1057 |
return getTableMatrixSize(iRows);
|
1058 |
|
1059 |
} |
1060 |
|
1061 |
|
1062 |
protected double[][] getOutputsTableLayoutMatrix() { |
1063 |
|
1064 |
int iRows = 0; |
1065 |
|
1066 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
1067 |
final int iOutput = ooSet.getOutputDataObjectsCount(); |
1068 |
iRows += iOutput; |
1069 |
|
1070 |
if (m_Algorithm.generatesLayersOrTables()) {
|
1071 |
iRows += 1;
|
1072 |
} |
1073 |
|
1074 |
return getTableMatrixSize(iRows);
|
1075 |
|
1076 |
} |
1077 |
|
1078 |
|
1079 |
protected double[][] getTableMatrixSize(final int iRows) { |
1080 |
|
1081 |
final double iSizeColumns[] = { 10, TableLayoutConstants.FILL, 360, 10 }; |
1082 |
final double iSizeRows[] = new double[iRows]; |
1083 |
|
1084 |
for (int i = 0; i < (iRows - 1); i++) { |
1085 |
iSizeRows[i] = CELL_HEIGHT; |
1086 |
} |
1087 |
if (iRows > 0) { |
1088 |
// Last row is smaller on the interface
|
1089 |
iSizeRows[iRows - 1] = 5; |
1090 |
} |
1091 |
|
1092 |
final double iSize[][] = new double[2][]; |
1093 |
iSize[0] = iSizeColumns;
|
1094 |
iSize[1] = iSizeRows;
|
1095 |
|
1096 |
return iSize;
|
1097 |
|
1098 |
} |
1099 |
|
1100 |
|
1101 |
protected JComboBox getRasterLayerSelectionComboBox(final ArrayList childComboBoxes, |
1102 |
final boolean bAddNotSetField) { |
1103 |
|
1104 |
int i;
|
1105 |
|
1106 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1107 |
for (i = 0; i < childsArray.length; i++) { |
1108 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1109 |
} |
1110 |
|
1111 |
final IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers(); |
1112 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
1113 |
IconTheme tm = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1114 |
for (i = 0; i < layers.length; i++) { |
1115 |
ImageIcon rasterIcon = tm.get("layer-type-raster"); |
1116 |
IRasterLayer layer = layers[i]; |
1117 |
String viewName = layer.getContextName();
|
1118 |
String description;
|
1119 |
if (viewName!=null) { |
1120 |
description = layer.getName() + " [" + viewName + "]"; |
1121 |
} else {
|
1122 |
description = layer.getName(); |
1123 |
} |
1124 |
|
1125 |
oad[i] = new ObjectAndDescription(description, layer, rasterIcon);
|
1126 |
} |
1127 |
|
1128 |
final JComboBox cb = new JComboBox(oad); |
1129 |
LayerComboBoxRenderer renderer = new LayerComboBoxRenderer();
|
1130 |
cb.setRenderer(renderer); |
1131 |
|
1132 |
if (bAddNotSetField) {
|
1133 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1134 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1135 |
} |
1136 |
|
1137 |
cb.addItemListener(new java.awt.event.ItemListener() {
|
1138 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1139 |
int i;
|
1140 |
int iIndex;
|
1141 |
String sNames[] = null; |
1142 |
DefaultComboBoxModel defaultModel;
|
1143 |
for (i = 0; i < childsArray.length; i++) { |
1144 |
iIndex = (childsArray[i]).intValue(); |
1145 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
|
1146 |
final IRasterLayer layer = (IRasterLayer) ob.getObject();
|
1147 |
if (layer != null) { |
1148 |
sNames = getBandNames(layer); |
1149 |
if (sNames != null) { |
1150 |
defaultModel = new DefaultComboBoxModel(sNames); |
1151 |
((JComboBox) m_ComboBox.get(iIndex)).setModel(defaultModel);
|
1152 |
} |
1153 |
} |
1154 |
} |
1155 |
} |
1156 |
}); |
1157 |
|
1158 |
return cb;
|
1159 |
|
1160 |
} |
1161 |
|
1162 |
|
1163 |
protected JComboBox get3DRasterLayerSelectionComboBox(final boolean bAddNotSetField) { |
1164 |
|
1165 |
int i;
|
1166 |
|
1167 |
final I3DRasterLayer[] layers = SextanteGUI.getInputFactory().get3DRasterLayers(); |
1168 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
1169 |
for (i = 0; i < layers.length; i++) { |
1170 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
1171 |
} |
1172 |
|
1173 |
final JComboBox cb = new JComboBox(oad); |
1174 |
|
1175 |
if (bAddNotSetField) {
|
1176 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1177 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1178 |
} |
1179 |
|
1180 |
return cb;
|
1181 |
|
1182 |
} |
1183 |
|
1184 |
protected ObjectAndDescription[] getVectorLayersAsObjectAndDescription(int shapeTypes) { |
1185 |
int[] shapeTypesList = new int[1]; |
1186 |
shapeTypesList[0] = shapeTypes;
|
1187 |
return getVectorLayersAsObjectAndDescription(shapeTypesList);
|
1188 |
} |
1189 |
|
1190 |
protected ObjectAndDescription[] getVectorLayersAsObjectAndDescription(int[] shapeTypes) { |
1191 |
final List<IVectorLayer> layers = getVectorLayers(shapeTypes); |
1192 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.size()]; |
1193 |
int i = 0; |
1194 |
for (IVectorLayer layer : layers) {
|
1195 |
String viewName = layer.getContextName();
|
1196 |
String description;
|
1197 |
String moreinfo = null; |
1198 |
|
1199 |
if (layer.hasSelection()) {
|
1200 |
moreinfo = " [" + layer.getShapesCount() + " selected]"; |
1201 |
} |
1202 |
if (viewName != null && moreinfo == null) { |
1203 |
description = layer.getName() + " [" + viewName + "]"; |
1204 |
} else if (viewName != null && moreinfo != null) { |
1205 |
description = layer.getName() + " [" + viewName + "]" + moreinfo; |
1206 |
} else {
|
1207 |
description = layer.getName(); |
1208 |
} |
1209 |
IconTheme tm = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1210 |
ImageIcon layerIcon = null; |
1211 |
if (layer.hasSelection()) {
|
1212 |
switch (layer.getShapeType()) {
|
1213 |
case IVectorLayer.SHAPE_TYPE_POINT:
|
1214 |
layerIcon = tm.get("layer-type-point-sel");
|
1215 |
break;
|
1216 |
case IVectorLayer.SHAPE_TYPE_MULTIPOINT:
|
1217 |
layerIcon = tm.get("layer-type-multipoint-sel");
|
1218 |
break;
|
1219 |
case IVectorLayer.SHAPE_TYPE_LINE:
|
1220 |
layerIcon = tm.get("layer-type-line-sel");
|
1221 |
break;
|
1222 |
case IVectorLayer.SHAPE_TYPE_MULTILINE:
|
1223 |
layerIcon = tm.get("layer-type-multiline-sel");
|
1224 |
break;
|
1225 |
case IVectorLayer.SHAPE_TYPE_POLYGON:
|
1226 |
layerIcon = tm.get("layer-type-polygon-sel");
|
1227 |
break;
|
1228 |
case IVectorLayer.SHAPE_TYPE_MULTIPOLYGON:
|
1229 |
layerIcon = tm.get("layer-type-multipolygon-sel");
|
1230 |
break;
|
1231 |
case IVectorLayer.SHAPE_TYPE_MIXED:
|
1232 |
layerIcon = tm.get("layer-type-mix-sel");
|
1233 |
break;
|
1234 |
case IVectorLayer.SHAPE_TYPE_WRONG:
|
1235 |
layerIcon = tm.get("layer-type-wrong");
|
1236 |
break;
|
1237 |
} |
1238 |
} else if (!layer.hasSelection()) { |
1239 |
switch (layer.getShapeType()) {
|
1240 |
case IVectorLayer.SHAPE_TYPE_POINT:
|
1241 |
layerIcon = tm.get("layer-type-point");
|
1242 |
break;
|
1243 |
case IVectorLayer.SHAPE_TYPE_MULTIPOINT:
|
1244 |
layerIcon = tm.get("layer-type-multipoint");
|
1245 |
break;
|
1246 |
case IVectorLayer.SHAPE_TYPE_LINE:
|
1247 |
layerIcon = tm.get("layer-type-line");
|
1248 |
break;
|
1249 |
case IVectorLayer.SHAPE_TYPE_MULTILINE:
|
1250 |
layerIcon = tm.get("layer-type-multiline");
|
1251 |
break;
|
1252 |
case IVectorLayer.SHAPE_TYPE_POLYGON:
|
1253 |
layerIcon = tm.get("layer-type-polygon");
|
1254 |
break;
|
1255 |
case IVectorLayer.SHAPE_TYPE_MULTIPOLYGON:
|
1256 |
layerIcon = tm.get("layer-type-multipolygon");
|
1257 |
break;
|
1258 |
case IVectorLayer.SHAPE_TYPE_MIXED:
|
1259 |
layerIcon = tm.get("layer-type-mix");
|
1260 |
break;
|
1261 |
case IVectorLayer.SHAPE_TYPE_WRONG:
|
1262 |
layerIcon = tm.get("layer-type-wrong");
|
1263 |
break;
|
1264 |
} |
1265 |
} |
1266 |
|
1267 |
oad[i] = new ObjectAndDescription(description, layers.get(i), layerIcon);
|
1268 |
i++; |
1269 |
} |
1270 |
return oad;
|
1271 |
} |
1272 |
|
1273 |
protected JComboBox getVectorLayerSelectionComboBox(final int iShapeType, |
1274 |
final ArrayList childComboBoxes, |
1275 |
final boolean bAddNotSetField) { |
1276 |
|
1277 |
int i;
|
1278 |
|
1279 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1280 |
for (i = 0; i < childsArray.length; i++) { |
1281 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1282 |
} |
1283 |
|
1284 |
ObjectAndDescription[] oad = getVectorLayersAsObjectAndDescription(iShapeType);
|
1285 |
final JComboBox cb = new JComboBox(oad); |
1286 |
|
1287 |
if (bAddNotSetField) {
|
1288 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1289 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1290 |
} |
1291 |
|
1292 |
cb.addItemListener(new java.awt.event.ItemListener() {
|
1293 |
@Override
|
1294 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1295 |
int i;
|
1296 |
int iIndex;
|
1297 |
DefaultComboBoxModel defaultModel;
|
1298 |
for (i = 0; i < childsArray.length; i++) { |
1299 |
iIndex = (childsArray[i]); |
1300 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
|
1301 |
final IVectorLayer layer = (IVectorLayer) ob.getObject();
|
1302 |
if (layer != null) { |
1303 |
Object item = m_ComboBox.get(iIndex);
|
1304 |
if (item instanceof JComboBox) { |
1305 |
FieldDescriptionComboBox[] sNames = getVectorLayerFieldRendererComboBox(layer);
|
1306 |
if (sNames != null) { |
1307 |
defaultModel = new DefaultComboBoxModel(sNames); |
1308 |
JComboBox cmb = (JComboBox) item; |
1309 |
cmb.setModel(defaultModel); |
1310 |
} |
1311 |
} |
1312 |
if (item instanceof TableFilterPanel) { |
1313 |
TableFilterPanel pane = (TableFilterPanel) item; |
1314 |
pane.setStore(layer.getFeatureStore()); |
1315 |
} |
1316 |
} |
1317 |
} |
1318 |
} |
1319 |
}); |
1320 |
|
1321 |
return cb;
|
1322 |
|
1323 |
} |
1324 |
|
1325 |
protected JComboBox<ObjectAndDescription> getVectorLayerSelectionComboBox(int[] shapeTypes, final List childComboBoxes, |
1326 |
final boolean bAddNotSetField) { |
1327 |
|
1328 |
int i;
|
1329 |
|
1330 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1331 |
for (i = 0; i < childsArray.length; i++) { |
1332 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1333 |
} |
1334 |
|
1335 |
ObjectAndDescription[] oad = getVectorLayersAsObjectAndDescription(shapeTypes);
|
1336 |
final JComboBox cb = new JComboBox(oad); |
1337 |
LayerComboBoxRenderer renderer = new LayerComboBoxRenderer();
|
1338 |
cb.setRenderer(renderer); |
1339 |
|
1340 |
if (bAddNotSetField) {
|
1341 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1342 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1343 |
} |
1344 |
|
1345 |
cb.addItemListener(new java.awt.event.ItemListener() {
|
1346 |
|
1347 |
@Override
|
1348 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1349 |
int i;
|
1350 |
int iIndex;
|
1351 |
DefaultComboBoxModel defaultModel;
|
1352 |
for (i = 0; i < childsArray.length; i++) { |
1353 |
iIndex = (childsArray[i]); |
1354 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
|
1355 |
final IVectorLayer layer = (IVectorLayer) ob.getObject();
|
1356 |
if (layer != null) { |
1357 |
Object item = m_ComboBox.get(iIndex);
|
1358 |
if (item instanceof JComboBox) { |
1359 |
FieldDescriptionComboBox[] sNames = getVectorLayerFieldRendererComboBox(layer);
|
1360 |
if (sNames != null) { |
1361 |
defaultModel = new DefaultComboBoxModel(sNames); |
1362 |
JComboBox cmb = (JComboBox) item; |
1363 |
cmb.setModel(defaultModel); |
1364 |
} |
1365 |
} |
1366 |
if (item instanceof TableFilterPanel) { |
1367 |
TableFilterPanel pane = (TableFilterPanel) item; |
1368 |
pane.setStore(layer.getFeatureStore()); |
1369 |
} |
1370 |
} |
1371 |
} |
1372 |
} |
1373 |
}); |
1374 |
|
1375 |
return cb;
|
1376 |
|
1377 |
} |
1378 |
|
1379 |
/**
|
1380 |
* @param shapeTypes
|
1381 |
* @return
|
1382 |
*/
|
1383 |
private List<ITable> getTables() { |
1384 |
List<ITable> tables = new ArrayList<ITable>(); |
1385 |
ITable[] allTables = SextanteGUI.getInputFactory().getTables();
|
1386 |
for (int k = 0; k < allTables.length; k++) { |
1387 |
tables.add(allTables[k]); |
1388 |
}; |
1389 |
|
1390 |
return tables;
|
1391 |
} |
1392 |
|
1393 |
/**
|
1394 |
* @param shapeTypes
|
1395 |
* @return
|
1396 |
*/
|
1397 |
private List<IVectorLayer> getVectorLayers(int[] shapeTypes) { |
1398 |
List<IVectorLayer> layers = new ArrayList<IVectorLayer>(); |
1399 |
for (int j = 0; j < shapeTypes.length; j++) { |
1400 |
IVectorLayer[] layersPerType = SextanteGUI.getInputFactory().getVectorLayers(shapeTypes[j]);
|
1401 |
for (int k = 0; k < layersPerType.length; k++) { |
1402 |
layers.add(layersPerType[k]); |
1403 |
}; |
1404 |
} |
1405 |
return layers;
|
1406 |
} |
1407 |
|
1408 |
protected JComboBox getTableSelectionComboBox(final ArrayList childComboBoxes, |
1409 |
final boolean bAddNotSetField) { |
1410 |
|
1411 |
int i;
|
1412 |
final JComboBox comboBox = new JComboBox(); |
1413 |
|
1414 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1415 |
for (i = 0; i < childsArray.length; i++) { |
1416 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1417 |
} |
1418 |
|
1419 |
final ITable[] tables = SextanteGUI.getInputFactory().getTables(); |
1420 |
final ObjectAndDescription[] oad = new ObjectAndDescription[tables.length]; |
1421 |
for (i = 0; i < tables.length; i++) { |
1422 |
oad[i] = new ObjectAndDescription(tables[i].getName(), tables[i]);
|
1423 |
} |
1424 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(oad); |
1425 |
comboBox.setModel(defaultModel); |
1426 |
|
1427 |
if (bAddNotSetField) {
|
1428 |
defaultModel.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1429 |
} |
1430 |
|
1431 |
comboBox.addItemListener(new java.awt.event.ItemListener() {
|
1432 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1433 |
int i;
|
1434 |
int iIndex;
|
1435 |
String sNames[] = null; |
1436 |
DefaultComboBoxModel defaultModel;
|
1437 |
for (i = 0; i < childsArray.length; i++) { |
1438 |
iIndex = (childsArray[i]).intValue(); |
1439 |
final ObjectAndDescription ob = (ObjectAndDescription) comboBox.getSelectedItem();
|
1440 |
final ITable table = (ITable) ob.getObject();
|
1441 |
if (table != null) { |
1442 |
Object item = m_ComboBox.get(iIndex);
|
1443 |
if (item instanceof JComboBox) { |
1444 |
sNames = getTableFieldNames(table); |
1445 |
if (sNames != null) { |
1446 |
defaultModel = new DefaultComboBoxModel(sNames); |
1447 |
((JComboBox) item).setModel(defaultModel);
|
1448 |
} |
1449 |
} |
1450 |
if (item instanceof TableFilterPanel) { |
1451 |
TableFilterPanel pane = (TableFilterPanel) item; |
1452 |
pane.setStore(table.getFeatureStore()); |
1453 |
|
1454 |
} |
1455 |
} |
1456 |
} |
1457 |
} |
1458 |
}); |
1459 |
|
1460 |
return comboBox;
|
1461 |
|
1462 |
} |
1463 |
|
1464 |
|
1465 |
protected JComboBox getTableFieldSelectionComboBox() { |
1466 |
|
1467 |
final ITable[] tables = SextanteGUI.getInputFactory().getTables(); |
1468 |
|
1469 |
if (tables.length > 0) { |
1470 |
final JComboBox comboBox = new JComboBox(); |
1471 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getTableFieldNames(tables[0])); |
1472 |
comboBox.setModel(defaultModel); |
1473 |
return comboBox;
|
1474 |
} |
1475 |
else {
|
1476 |
return new JComboBox(); |
1477 |
} |
1478 |
|
1479 |
} |
1480 |
|
1481 |
|
1482 |
protected JComboBox getBandSelectionComboBox() { |
1483 |
|
1484 |
final IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers(); |
1485 |
|
1486 |
if (layers.length > 0) { |
1487 |
final JComboBox comboBox = new JComboBox(); |
1488 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getBandNames(layers[0])); |
1489 |
comboBox.setModel(defaultModel); |
1490 |
return comboBox;
|
1491 |
} |
1492 |
else {
|
1493 |
return new JComboBox(); |
1494 |
} |
1495 |
|
1496 |
} |
1497 |
|
1498 |
|
1499 |
protected JComboBox getVectorLayerFieldSelectionComboBox(final int iShapeType) { |
1500 |
|
1501 |
final IVectorLayer[] layers = SextanteGUI.getInputFactory().getVectorLayers(iShapeType); |
1502 |
|
1503 |
if (layers.length > 0) { |
1504 |
final JComboBox comboBox = new JComboBox(); |
1505 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldNames(layers[0])); |
1506 |
comboBox.setModel(defaultModel); |
1507 |
return comboBox;
|
1508 |
} |
1509 |
else {
|
1510 |
return new JComboBox(); |
1511 |
} |
1512 |
|
1513 |
} |
1514 |
|
1515 |
protected FieldDescriptionComboBox[] getVectorLayerFieldRendererComboBox(IVectorLayer layer) { |
1516 |
final FieldDescriptionComboBox[] oad = new FieldDescriptionComboBox[layer.getFieldNames().length]; |
1517 |
for (int i = 0; i < layer.getFieldNames().length; i++) { |
1518 |
String fieldName = layer.getFieldName(i);
|
1519 |
Class fieldClass = layer.getFieldType(i);
|
1520 |
oad[i]=new FieldDescriptionComboBox(fieldName, fieldClass);
|
1521 |
} |
1522 |
return oad;
|
1523 |
} |
1524 |
protected JComboBox getVectorLayerFieldSelectionComboBox(final int[] shapeTypes) { |
1525 |
|
1526 |
List<IVectorLayer> layers = getVectorLayers(shapeTypes);
|
1527 |
|
1528 |
if (layers.size() > 0) { |
1529 |
final JComboBox comboBox = new JComboBox(); |
1530 |
IVectorLayer layer = layers.get(0);
|
1531 |
//final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldNames(layers.get(0)));
|
1532 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldRendererComboBox(layer)); |
1533 |
FieldComboBoxRenderer renderer = new FieldComboBoxRenderer();
|
1534 |
comboBox.setRenderer(renderer); |
1535 |
comboBox.setModel(defaultModel); |
1536 |
return comboBox;
|
1537 |
} |
1538 |
else {
|
1539 |
return new JComboBox(); |
1540 |
} |
1541 |
|
1542 |
} |
1543 |
|
1544 |
protected String[] getTableFieldNames(final ITable table) { |
1545 |
|
1546 |
return table.getFieldNames();
|
1547 |
|
1548 |
} |
1549 |
|
1550 |
|
1551 |
protected String[] getVectorLayerFieldNames(final IVectorLayer vectorLayer) { |
1552 |
|
1553 |
return vectorLayer.getFieldNames();
|
1554 |
|
1555 |
} |
1556 |
|
1557 |
|
1558 |
protected String[] getBandNames(final IRasterLayer layer) { |
1559 |
|
1560 |
int j;
|
1561 |
int iBands;
|
1562 |
String[] bands = null; |
1563 |
|
1564 |
iBands = layer.getBandsCount(); |
1565 |
bands = new String[iBands]; |
1566 |
for (j = 0; j < iBands; j++) { |
1567 |
bands[j] = Integer.toString(j + 1); |
1568 |
} |
1569 |
|
1570 |
return bands;
|
1571 |
|
1572 |
} |
1573 |
|
1574 |
|
1575 |
@Override
|
1576 |
public void assignParameters() throws WrongInputException, LayerCannotBeOverwrittenException { |
1577 |
|
1578 |
boolean bAssigningOK = true; |
1579 |
int i;
|
1580 |
ParameterContainer parameterContainer; |
1581 |
String sType;
|
1582 |
|
1583 |
for (i = 0; i < m_ParameterContainer.size(); i++) { |
1584 |
parameterContainer = (ParameterContainer) m_ParameterContainer.get(i); |
1585 |
sType = parameterContainer.getType(); |
1586 |
if (sType.equals("Table")) { |
1587 |
bAssigningOK = assignInputTable(parameterContainer); |
1588 |
} |
1589 |
else if (sType.equals("Vector Layer") || sType.equals("Raster Layer") || sType.equals("3D Raster Layer")) { |
1590 |
bAssigningOK = assignInputLayer(parameterContainer); |
1591 |
} |
1592 |
else if (sType.equals("Numerical Value")) { |
1593 |
bAssigningOK = assignInputNumericalValue(parameterContainer); |
1594 |
} |
1595 |
else if (sType.equals("String")) { |
1596 |
bAssigningOK = assignInputString(parameterContainer); |
1597 |
} |
1598 |
else if (sType.equals("Boolean")) { |
1599 |
bAssigningOK = assignInputBoolean(parameterContainer); |
1600 |
} |
1601 |
else if (sType.equals("Fixed Table")) { |
1602 |
bAssigningOK = assignInputFixedTable(parameterContainer); |
1603 |
} |
1604 |
else if (sType.equals("Multiple Input")) { |
1605 |
bAssigningOK = assignInputMultipleInput(parameterContainer); |
1606 |
} |
1607 |
else if (sType.equals("Point")) { |
1608 |
bAssigningOK = assignInputPoint(parameterContainer); |
1609 |
} |
1610 |
else if (parameterContainer.getType().equals("Filepath")) { |
1611 |
bAssigningOK = assignInputFilepath(parameterContainer); |
1612 |
} |
1613 |
else if (sType.equals("Table Field") || sType.equals("Selection") || sType.equals("Band")) { |
1614 |
bAssigningOK = assignInputSelection(parameterContainer); |
1615 |
} |
1616 |
else if (sType.equals("Table Filter")) { |
1617 |
bAssigningOK = assignInputTableFilter(parameterContainer); |
1618 |
} |
1619 |
|
1620 |
if (!bAssigningOK) {
|
1621 |
throw new WrongInputException(); |
1622 |
} |
1623 |
|
1624 |
} |
1625 |
|
1626 |
final OutputObjectsSet ooset = m_Algorithm.getOutputObjects();
|
1627 |
for (i = 0; i < m_OutputParameterContainer.size(); i++) { |
1628 |
final OutputParameterContainer opc = (OutputParameterContainer) m_OutputParameterContainer.get(i);
|
1629 |
Output out; |
1630 |
|
1631 |
try {
|
1632 |
out = ooset.getOutput(opc.getName()); |
1633 |
} |
1634 |
catch (final WrongOutputIDException e) { |
1635 |
throw new WrongInputException(); |
1636 |
} |
1637 |
|
1638 |
final OutputChannelSelectionPanel ocsp = (OutputChannelSelectionPanel) opc.getContainer();
|
1639 |
IOutputChannel channel; |
1640 |
try {
|
1641 |
channel = ocsp.getOutputChannel(); |
1642 |
} |
1643 |
catch (final WrongOutputChannelDataException e) { |
1644 |
throw new WrongInputException(); |
1645 |
} |
1646 |
|
1647 |
if (channel instanceof OverwriteOutputChannel) { |
1648 |
final OverwriteOutputChannel ooc = (OverwriteOutputChannel) channel;
|
1649 |
if (!ooc.getLayer().canBeEdited()) {
|
1650 |
throw new LayerCannotBeOverwrittenException(); |
1651 |
} |
1652 |
} |
1653 |
out.setOutputChannel(channel); |
1654 |
//TODO Check that output channels do not match with input layers
|
1655 |
|
1656 |
} |
1657 |
|
1658 |
|
1659 |
} |
1660 |
|
1661 |
|
1662 |
protected boolean assignInputTable(final ParameterContainer parameterContainer) { |
1663 |
|
1664 |
boolean bReturn = true; |
1665 |
|
1666 |
try {
|
1667 |
final JComboBox comboBox = (JComboBox) parameterContainer.getContainer(); |
1668 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1669 |
final ObjectAndDescription oad = (ObjectAndDescription) comboBox.getSelectedItem();
|
1670 |
bReturn = parameter.setParameterValue(oad.getObject()); |
1671 |
} |
1672 |
catch (final Exception e) { |
1673 |
Sextante.addErrorToLog(e); |
1674 |
return false; |
1675 |
} |
1676 |
|
1677 |
return bReturn;
|
1678 |
|
1679 |
} |
1680 |
|
1681 |
|
1682 |
protected boolean assignInputLayer(final ParameterContainer parameterContainer) { |
1683 |
|
1684 |
boolean bReturn = true; |
1685 |
|
1686 |
try {
|
1687 |
final JComboBox comboBox = (JComboBox) parameterContainer.getContainer(); |
1688 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1689 |
final ObjectAndDescription oad = (ObjectAndDescription) comboBox.getSelectedItem();
|
1690 |
bReturn = parameter.setParameterValue(oad.getObject()); |
1691 |
} |
1692 |
catch (final Exception e) { |
1693 |
Sextante.addErrorToLog(e); |
1694 |
return false; |
1695 |
} |
1696 |
|
1697 |
return bReturn;
|
1698 |
|
1699 |
} |
1700 |
|
1701 |
|
1702 |
protected boolean assignInputMultipleInput(final ParameterContainer parameterContainer) { |
1703 |
|
1704 |
boolean bReturn;
|
1705 |
|
1706 |
try {
|
1707 |
//final MultipleInputSelectionPanel panel = (MultipleInputSelectionPanel) parameterContainer.getContainer();
|
1708 |
final CheckComboBox ccb = (CheckComboBox) parameterContainer.getContainer();
|
1709 |
final ParameterMultipleInput parameter = (ParameterMultipleInput) m_Algorithm.getParameters().getParameter(
|
1710 |
parameterContainer.getName()); |
1711 |
final List<Object> list = ccb.getModel().getCheckeds(); |
1712 |
//final ArrayList list = panel.getSelectedObjects();
|
1713 |
final AdditionalInfoMultipleInput ai = (AdditionalInfoMultipleInput) parameter.getParameterAdditionalInfo();
|
1714 |
final boolean bMandatory = ai.getIsMandatory(); |
1715 |
if (bMandatory && (list.size() == 0)) { |
1716 |
return false; |
1717 |
} |
1718 |
bReturn = parameter.setParameterValue(list); |
1719 |
} |
1720 |
catch (final Exception e) { |
1721 |
Sextante.addErrorToLog(e); |
1722 |
return false; |
1723 |
} |
1724 |
|
1725 |
return bReturn;
|
1726 |
|
1727 |
} |
1728 |
|
1729 |
|
1730 |
protected boolean assignInputSelection(final ParameterContainer parameterContainer) { |
1731 |
|
1732 |
int iIndex;
|
1733 |
boolean bReturn = true; |
1734 |
|
1735 |
try {
|
1736 |
final JComboBox comboBox = (JComboBox) parameterContainer.getContainer(); |
1737 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1738 |
iIndex = comboBox.getSelectedIndex(); |
1739 |
bReturn = parameter.setParameterValue(new Integer(iIndex)); |
1740 |
|
1741 |
if (parameter instanceof ParameterTableField) { |
1742 |
parameter.setParameterValue(comboBox.getSelectedItem().toString()); |
1743 |
} |
1744 |
|
1745 |
} |
1746 |
catch (final WrongParameterIDException e) { |
1747 |
Sextante.addErrorToLog(e); |
1748 |
return false; |
1749 |
} |
1750 |
|
1751 |
return bReturn;
|
1752 |
|
1753 |
} |
1754 |
|
1755 |
|
1756 |
protected boolean assignInputNumericalValue(final ParameterContainer parameterContainer) { |
1757 |
|
1758 |
boolean bReturn;
|
1759 |
|
1760 |
try {
|
1761 |
final JTextField txtField = (JTextField) parameterContainer.getContainer(); |
1762 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1763 |
bReturn = parameter.setParameterValue(new Double(Double.parseDouble(txtField.getText()))); |
1764 |
} |
1765 |
catch (final Exception e) { |
1766 |
Sextante.addErrorToLog(e); |
1767 |
return false; |
1768 |
} |
1769 |
|
1770 |
return bReturn;
|
1771 |
|
1772 |
} |
1773 |
|
1774 |
|
1775 |
protected boolean assignInputFixedTable(final ParameterContainer parameterContainer) { |
1776 |
|
1777 |
boolean bReturn;
|
1778 |
|
1779 |
try {
|
1780 |
final FixedTablePanel panel = (FixedTablePanel) parameterContainer.getContainer();
|
1781 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1782 |
bReturn = parameter.setParameterValue(panel.getTableModel()); |
1783 |
} |
1784 |
catch (final WrongParameterIDException e) { |
1785 |
Sextante.addErrorToLog(e); |
1786 |
return false; |
1787 |
} |
1788 |
|
1789 |
return bReturn;
|
1790 |
|
1791 |
} |
1792 |
|
1793 |
|
1794 |
protected boolean assignInputString(final ParameterContainer parameterContainer) { |
1795 |
|
1796 |
boolean bReturn;
|
1797 |
|
1798 |
try {
|
1799 |
final JTextField txtField = (JTextField) parameterContainer.getContainer(); |
1800 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1801 |
bReturn = parameter.setParameterValue(txtField.getText()); |
1802 |
} |
1803 |
catch (final WrongParameterIDException e) { |
1804 |
Sextante.addErrorToLog(e); |
1805 |
return false; |
1806 |
} |
1807 |
|
1808 |
return bReturn;
|
1809 |
|
1810 |
} |
1811 |
|
1812 |
|
1813 |
protected boolean assignInputFilepath(final ParameterContainer parameterContainer) { |
1814 |
|
1815 |
boolean bReturn;
|
1816 |
|
1817 |
try {
|
1818 |
final FileSelectionPanel fileSelectionPanel = (FileSelectionPanel) parameterContainer.getContainer();
|
1819 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1820 |
bReturn = parameter.setParameterValue(fileSelectionPanel.getFilepath()); |
1821 |
} |
1822 |
catch (final WrongParameterIDException e) { |
1823 |
Sextante.addErrorToLog(e); |
1824 |
return false; |
1825 |
} |
1826 |
|
1827 |
return bReturn;
|
1828 |
|
1829 |
} |
1830 |
|
1831 |
protected boolean assignInputTableFilter(final ParameterContainer parameterContainer) { |
1832 |
|
1833 |
boolean bReturn;
|
1834 |
|
1835 |
try {
|
1836 |
final TableFilterPanel fileSelectionPanel = (TableFilterPanel) parameterContainer.getContainer();
|
1837 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1838 |
bReturn = parameter.setParameterValue(fileSelectionPanel.getExpression()); |
1839 |
} |
1840 |
catch (final WrongParameterIDException e) { |
1841 |
Sextante.addErrorToLog(e); |
1842 |
return false; |
1843 |
} |
1844 |
|
1845 |
return bReturn;
|
1846 |
|
1847 |
} |
1848 |
|
1849 |
protected boolean assignInputPoint(final ParameterContainer parameterContainer) { |
1850 |
|
1851 |
boolean bReturn;
|
1852 |
|
1853 |
try {
|
1854 |
final PointSelectionPanel pointSelectionPanel = (PointSelectionPanel) parameterContainer.getContainer();
|
1855 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1856 |
bReturn = parameter.setParameterValue(pointSelectionPanel.getPoint()); |
1857 |
} |
1858 |
catch (final Exception e) { |
1859 |
Sextante.addErrorToLog(e); |
1860 |
return false; |
1861 |
} |
1862 |
|
1863 |
return bReturn;
|
1864 |
|
1865 |
} |
1866 |
|
1867 |
|
1868 |
protected boolean assignInputBoolean(final ParameterContainer parameterContainer) { |
1869 |
|
1870 |
boolean bReturn;
|
1871 |
|
1872 |
try {
|
1873 |
final JCheckBox checkBox = (JCheckBox) parameterContainer.getContainer(); |
1874 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1875 |
bReturn = parameter.setParameterValue(new Boolean(checkBox.isSelected())); |
1876 |
} |
1877 |
catch (final WrongParameterIDException e) { |
1878 |
Sextante.addErrorToLog(e); |
1879 |
return false; |
1880 |
} |
1881 |
|
1882 |
return bReturn;
|
1883 |
|
1884 |
} |
1885 |
|
1886 |
|
1887 |
@Override
|
1888 |
public void setOutputValue(final String sOutputName, |
1889 |
final String sValue) { |
1890 |
|
1891 |
for (int i = 0; i < m_OutputParameterContainer.size(); i++) { |
1892 |
final OutputParameterContainer container = (OutputParameterContainer) m_OutputParameterContainer.get(i);
|
1893 |
if (sOutputName.equals(container.getName())) {
|
1894 |
final OutputChannelSelectionPanel ocsp = (OutputChannelSelectionPanel) container.getContainer();
|
1895 |
ocsp.setText(sValue); |
1896 |
} |
1897 |
} |
1898 |
|
1899 |
} |
1900 |
|
1901 |
|
1902 |
@Override
|
1903 |
public void setParameterValue(final String sParameterName, |
1904 |
final String sValue) { |
1905 |
|
1906 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
1907 |
Parameter param; |
1908 |
try {
|
1909 |
param = parameters.getParameter(sParameterName); |
1910 |
} |
1911 |
catch (final WrongParameterIDException e1) { |
1912 |
return;
|
1913 |
} |
1914 |
Object container = null; |
1915 |
for (int i = 0; i < m_ParameterContainer.size(); i++) { |
1916 |
final ParameterContainer pc = (ParameterContainer) m_ParameterContainer.get(i);
|
1917 |
if (pc.getName().equals(sParameterName)) {
|
1918 |
container = pc.getContainer(); |
1919 |
break;
|
1920 |
} |
1921 |
} |
1922 |
|
1923 |
if (container == null) { |
1924 |
return;
|
1925 |
} |
1926 |
|
1927 |
try {
|
1928 |
if (param instanceof ParameterDataObject) { |
1929 |
if (container instanceof JComboBox) { |
1930 |
final JComboBox cb = (JComboBox) container; |
1931 |
final ComboBoxModel model = cb.getModel(); |
1932 |
for (int i = 0; i < model.getSize(); i++) { |
1933 |
final ObjectAndDescription oad = (ObjectAndDescription) model.getElementAt(i);
|
1934 |
if (oad.getDescription().equals(sValue)) {
|
1935 |
cb.setSelectedIndex(i); |
1936 |
break;
|
1937 |
} |
1938 |
} |
1939 |
} else if (container instanceof TableFilterPanel) { |
1940 |
TableFilterPanel cb = (TableFilterPanel) container; |
1941 |
cb.setPhrase(cb.getPhrase()); |
1942 |
} |
1943 |
} |
1944 |
else if ((param instanceof ParameterNumericalValue) || (param instanceof ParameterString)) { |
1945 |
if (!sValue.equals("#")) { |
1946 |
final JTextField tf = (JTextField) container; |
1947 |
tf.setText(sValue); |
1948 |
} |
1949 |
} |
1950 |
else if (param instanceof ParameterFilepath) { |
1951 |
final FileSelectionPanel fsp = (FileSelectionPanel) container;
|
1952 |
fsp.setFilepath(sValue); |
1953 |
} |
1954 |
else if (param instanceof ParameterFixedTable) { |
1955 |
this.setFixedTableValue(param, (FixedTablePanel) container, sValue);
|
1956 |
} |
1957 |
else if (param instanceof ParameterBoolean) { |
1958 |
if (!sValue.equals("#")) { |
1959 |
final JCheckBox cb = (JCheckBox) container; |
1960 |
boolean bValue;
|
1961 |
if (sValue.equals("true")) { |
1962 |
bValue = true;
|
1963 |
} |
1964 |
else {
|
1965 |
bValue = false;
|
1966 |
} |
1967 |
cb.setSelected(bValue); |
1968 |
|
1969 |
} |
1970 |
} |
1971 |
else if (param instanceof ParameterSelection) { |
1972 |
if (!sValue.equals("#")) { |
1973 |
final int iIndex = Integer.parseInt(sValue); |
1974 |
final AdditionalInfoSelection ai = (AdditionalInfoSelection) param.getParameterAdditionalInfo();
|
1975 |
if ((iIndex >= 0) && (iIndex < ai.getValues().length)) { |
1976 |
final JComboBox cb = (JComboBox) container; |
1977 |
cb.setSelectedIndex(iIndex); |
1978 |
} |
1979 |
} |
1980 |
} |
1981 |
else if (param instanceof ParameterMultipleInput) { |
1982 |
|
1983 |
final ArrayList selectedIndices = new ArrayList(); |
1984 |
final String[] sObjects = sValue.split(","); |
1985 |
//final MultipleInputSelectionPanel msp = (MultipleInputSelectionPanel) container;
|
1986 |
final CheckComboBox ccb = (CheckComboBox) container;
|
1987 |
final Object[] objs = new Object[ccb.getModel().getSize()]; |
1988 |
for (int j = 0; j < objs.length; j++) { |
1989 |
objs[j] = ccb.getModel().getElementAt(j); |
1990 |
} |
1991 |
for (int j = 0; j < objs.length; j++) { |
1992 |
for (int i = 0; i < sObjects.length; i++) { |
1993 |
if (objs[j] instanceof IDataObject) { |
1994 |
final IDataObject ido = (IDataObject) objs[j];
|
1995 |
if (ido.getName().equals(sObjects[i].trim())) {
|
1996 |
ccb.getModel().addCheck(objs[j]); |
1997 |
//selectedIndices.add(new Integer(j));
|
1998 |
break;
|
1999 |
} |
2000 |
} |
2001 |
else if (objs[j] instanceof RasterLayerAndBand) { |
2002 |
try {
|
2003 |
final RasterLayerAndBand rlab = (RasterLayerAndBand) objs[j];
|
2004 |
if (rlab.getRasterLayer().getName().equals(sObjects[i].trim())) {
|
2005 |
if (Integer.parseInt(sObjects[i + 1].trim()) - 1 == rlab.getBand()) { |
2006 |
ccb.getModel().addCheck(objs[j]); |
2007 |
//selectedIndices.add(new Integer(j));
|
2008 |
break;
|
2009 |
} |
2010 |
} |
2011 |
} |
2012 |
catch (final Exception e) { |
2013 |
} |
2014 |
|
2015 |
} |
2016 |
} |
2017 |
} |
2018 |
//msp.setSelectedIndices(selectedIndices);
|
2019 |
} |
2020 |
else if (param instanceof ParameterPoint) { |
2021 |
final StringTokenizer st = new StringTokenizer(sValue, ","); |
2022 |
if (st.countTokens() == 2) { |
2023 |
final double x = Double.parseDouble(st.nextToken()); |
2024 |
final double y = Double.parseDouble(st.nextToken()); |
2025 |
final PointSelectionPanel psp = (PointSelectionPanel) container;
|
2026 |
psp.setPoint(new Point2D.Double(x, y)); |
2027 |
} |
2028 |
} |
2029 |
else if ((param instanceof ParameterTableField) || (param instanceof ParameterBand)) { |
2030 |
final JComboBox cb = (JComboBox) container; |
2031 |
try {
|
2032 |
cb.setSelectedIndex(Integer.parseInt(sValue));
|
2033 |
} |
2034 |
catch (final Exception e) { |
2035 |
} |
2036 |
} |
2037 |
|
2038 |
} |
2039 |
catch (final NullParameterAdditionalInfoException e) { |
2040 |
Sextante.addErrorToLog(e); |
2041 |
} catch (final NumberFormatException e) { |
2042 |
Sextante.addErrorToLog(e); |
2043 |
} |
2044 |
|
2045 |
} |
2046 |
|
2047 |
|
2048 |
protected void setFixedTableValue(final Parameter param, |
2049 |
final FixedTablePanel container,
|
2050 |
final String sValue) { |
2051 |
|
2052 |
boolean bIsNumberOfRowsFixed;
|
2053 |
int iCols, iRows;
|
2054 |
int iCol, iRow;
|
2055 |
int iToken = 0; |
2056 |
FixedTableModel tableModel; |
2057 |
final StringTokenizer st = new StringTokenizer(sValue, ","); |
2058 |
String sToken;
|
2059 |
AdditionalInfoFixedTable ai; |
2060 |
try {
|
2061 |
ai = (AdditionalInfoFixedTable) param.getParameterAdditionalInfo(); |
2062 |
iCols = ai.getColsCount(); |
2063 |
final int iTokens = st.countTokens(); |
2064 |
iRows = (st.countTokens() / iCols); |
2065 |
bIsNumberOfRowsFixed = ai.isNumberOfRowsFixed(); |
2066 |
tableModel = new FixedTableModel(ai.getCols(), iRows, bIsNumberOfRowsFixed);
|
2067 |
|
2068 |
if (bIsNumberOfRowsFixed) {
|
2069 |
if (iRows != ai.getRowsCount()) {
|
2070 |
return;
|
2071 |
} |
2072 |
} |
2073 |
else {
|
2074 |
if (st.countTokens() % iCols != 0) { |
2075 |
return;
|
2076 |
} |
2077 |
} |
2078 |
|
2079 |
while (st.hasMoreTokens()) {
|
2080 |
iRow = (int) Math.floor(iToken / (double) iCols); |
2081 |
iCol = iToken % iCols; |
2082 |
sToken = st.nextToken().trim(); |
2083 |
tableModel.setValueAt(sToken, iRow, iCol); |
2084 |
iToken++; |
2085 |
} |
2086 |
|
2087 |
container.setTableModel(tableModel); |
2088 |
|
2089 |
} |
2090 |
catch (final NullParameterAdditionalInfoException e) { |
2091 |
} |
2092 |
|
2093 |
} |
2094 |
|
2095 |
|
2096 |
} |