root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / algorithm / DefaultParametersPanel.java @ 353
History | View | Annotate | Download (81.2 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 |
ToolsSwingLocator.getToolsSwingManager().setDefaultPopupMenu(textField); |
935 |
|
936 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
937 |
|
938 |
pane.add(textField, getStringTableCoords(2, m_iCurrentRow));
|
939 |
m_ParameterContainer.add(new ParameterContainer(parameter, textField));
|
940 |
m_iCurrentRow++; |
941 |
} |
942 |
catch (final NullParameterAdditionalInfoException e) { |
943 |
Sextante.addErrorToLog(e); |
944 |
} |
945 |
|
946 |
} |
947 |
|
948 |
|
949 |
protected void addCheckBox(final JPanel pane, |
950 |
final ParameterBoolean parameter) {
|
951 |
|
952 |
final JCheckBox checkBox = new JCheckBox(); |
953 |
try {
|
954 |
final AdditionalInfoBoolean ai = (AdditionalInfoBoolean) parameter.getParameterAdditionalInfo();
|
955 |
checkBox.setSelected(ai.getDefaultValue()); |
956 |
addTitleLabel(pane, parameter.getParameterDescription(), m_iCurrentRow, false);
|
957 |
pane.add(checkBox, getStringTableCoords(2, m_iCurrentRow));
|
958 |
m_ParameterContainer.add(new ParameterContainer(parameter, checkBox));
|
959 |
m_iCurrentRow++; |
960 |
} |
961 |
catch (final NullParameterAdditionalInfoException e) { |
962 |
Sextante.addErrorToLog(e); |
963 |
} |
964 |
|
965 |
|
966 |
} |
967 |
|
968 |
|
969 |
protected void addTitleLabel(final JPanel pane, |
970 |
final String sText, |
971 |
final int iRow, |
972 |
final boolean isSectionTitleLabel) { |
973 |
|
974 |
JLabel label;
|
975 |
label = new JLabel(); |
976 |
label.setText(sText); |
977 |
label.setPreferredSize(new java.awt.Dimension(COLUMN_WIDTH, CELL_HEIGHT));
|
978 |
|
979 |
if (isSectionTitleLabel) {
|
980 |
label.setFont(new java.awt.Font("Tahoma", 1, 11)); |
981 |
label.setForeground(java.awt.Color.BLUE); |
982 |
} |
983 |
|
984 |
pane.add(label, getStringTableCoords(1, iRow));
|
985 |
|
986 |
} |
987 |
|
988 |
|
989 |
protected String getStringTableCoords(final int iCol, |
990 |
final int iRow) { |
991 |
|
992 |
final StringBuffer sCellCoords = new StringBuffer(); |
993 |
|
994 |
sCellCoords.append(Integer.toString(iCol));
|
995 |
sCellCoords.append(",");
|
996 |
sCellCoords.append(Integer.toString(iRow));
|
997 |
|
998 |
return sCellCoords.toString();
|
999 |
|
1000 |
} |
1001 |
|
1002 |
|
1003 |
protected double[][] getInputsTableLayoutMatrix() { |
1004 |
|
1005 |
int iRows = 1; |
1006 |
|
1007 |
if (m_Algorithm.requiresRasterLayers() || m_Algorithm.requiresMultipleRasterLayers()
|
1008 |
|| m_Algorithm.requiresMultipleRasterBands()) { |
1009 |
//Adds 1 for label
|
1010 |
iRows += 1;
|
1011 |
iRows += m_Algorithm.getNumberOfRasterLayers(true);
|
1012 |
final int tf_num = m_Algorithm.getNumberOfBandsParameters(); |
1013 |
if (tf_num > 0) { |
1014 |
iRows += tf_num; |
1015 |
} |
1016 |
} |
1017 |
if (m_Algorithm.requiresVectorLayers() || m_Algorithm.requiresMultipleVectorLayers()) {
|
1018 |
//Adds 1 for label
|
1019 |
iRows += 1;
|
1020 |
iRows += m_Algorithm.getNumberOfVectorLayers(true);
|
1021 |
final int tf_num = m_Algorithm.getNumberOfTableFieldsParameters(); |
1022 |
if (tf_num > 0) { |
1023 |
iRows += tf_num; |
1024 |
} |
1025 |
final int tfilter_num = m_Algorithm.getNumberOfTableFilterParameters(); |
1026 |
if (tfilter_num > 0) { |
1027 |
iRows += tfilter_num; |
1028 |
} |
1029 |
} |
1030 |
if (m_Algorithm.requiresTables() || m_Algorithm.requiresMultipleTables()) {
|
1031 |
//Adds 1 for label
|
1032 |
iRows += 1;
|
1033 |
iRows += m_Algorithm.getNumberOfTables(); |
1034 |
final int tf_num = m_Algorithm.getNumberOfTableFieldsParameters(); |
1035 |
if (tf_num > 0) { |
1036 |
iRows += tf_num; |
1037 |
} |
1038 |
} |
1039 |
if (m_Algorithm.requires3DRasterLayers()) {
|
1040 |
//Adds 1 for label
|
1041 |
iRows += 1;
|
1042 |
iRows += m_Algorithm.getParameters().getNumberOf3DRasterLayers(); |
1043 |
} |
1044 |
|
1045 |
return getTableMatrixSize(iRows);
|
1046 |
|
1047 |
} |
1048 |
|
1049 |
|
1050 |
protected double[][] getOptionsTableLayoutMatrix() { |
1051 |
|
1052 |
int iRows = 1; |
1053 |
|
1054 |
if (m_Algorithm.requiresNonDataObjects()) {
|
1055 |
iRows += m_Algorithm.getNumberOfNoDataParameters(); |
1056 |
} |
1057 |
|
1058 |
return getTableMatrixSize(iRows);
|
1059 |
|
1060 |
} |
1061 |
|
1062 |
|
1063 |
protected double[][] getOutputsTableLayoutMatrix() { |
1064 |
|
1065 |
int iRows = 0; |
1066 |
|
1067 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
1068 |
final int iOutput = ooSet.getOutputDataObjectsCount(); |
1069 |
iRows += iOutput; |
1070 |
|
1071 |
if (m_Algorithm.generatesLayersOrTables()) {
|
1072 |
iRows += 1;
|
1073 |
} |
1074 |
|
1075 |
return getTableMatrixSize(iRows);
|
1076 |
|
1077 |
} |
1078 |
|
1079 |
|
1080 |
protected double[][] getTableMatrixSize(final int iRows) { |
1081 |
|
1082 |
final double iSizeColumns[] = { 10, TableLayoutConstants.FILL, 360, 10 }; |
1083 |
final double iSizeRows[] = new double[iRows]; |
1084 |
|
1085 |
for (int i = 0; i < (iRows - 1); i++) { |
1086 |
iSizeRows[i] = CELL_HEIGHT; |
1087 |
} |
1088 |
if (iRows > 0) { |
1089 |
// Last row is smaller on the interface
|
1090 |
iSizeRows[iRows - 1] = 5; |
1091 |
} |
1092 |
|
1093 |
final double iSize[][] = new double[2][]; |
1094 |
iSize[0] = iSizeColumns;
|
1095 |
iSize[1] = iSizeRows;
|
1096 |
|
1097 |
return iSize;
|
1098 |
|
1099 |
} |
1100 |
|
1101 |
|
1102 |
protected JComboBox getRasterLayerSelectionComboBox(final ArrayList childComboBoxes, |
1103 |
final boolean bAddNotSetField) { |
1104 |
|
1105 |
int i;
|
1106 |
|
1107 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1108 |
for (i = 0; i < childsArray.length; i++) { |
1109 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1110 |
} |
1111 |
|
1112 |
final IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers(); |
1113 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
1114 |
IconTheme tm = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1115 |
for (i = 0; i < layers.length; i++) { |
1116 |
ImageIcon rasterIcon = tm.get("layer-type-raster"); |
1117 |
IRasterLayer layer = layers[i]; |
1118 |
String viewName = layer.getContextName();
|
1119 |
String description;
|
1120 |
if (viewName!=null) { |
1121 |
description = layer.getName() + " [" + viewName + "]"; |
1122 |
} else {
|
1123 |
description = layer.getName(); |
1124 |
} |
1125 |
|
1126 |
oad[i] = new ObjectAndDescription(description, layer, rasterIcon);
|
1127 |
} |
1128 |
|
1129 |
final JComboBox cb = new JComboBox(oad); |
1130 |
LayerComboBoxRenderer renderer = new LayerComboBoxRenderer();
|
1131 |
cb.setRenderer(renderer); |
1132 |
|
1133 |
if (bAddNotSetField) {
|
1134 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1135 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1136 |
} |
1137 |
|
1138 |
cb.addItemListener(new java.awt.event.ItemListener() {
|
1139 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1140 |
int i;
|
1141 |
int iIndex;
|
1142 |
String sNames[] = null; |
1143 |
DefaultComboBoxModel defaultModel;
|
1144 |
for (i = 0; i < childsArray.length; i++) { |
1145 |
iIndex = (childsArray[i]).intValue(); |
1146 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
|
1147 |
final IRasterLayer layer = (IRasterLayer) ob.getObject();
|
1148 |
if (layer != null) { |
1149 |
sNames = getBandNames(layer); |
1150 |
if (sNames != null) { |
1151 |
defaultModel = new DefaultComboBoxModel(sNames); |
1152 |
((JComboBox) m_ComboBox.get(iIndex)).setModel(defaultModel);
|
1153 |
} |
1154 |
} |
1155 |
} |
1156 |
} |
1157 |
}); |
1158 |
|
1159 |
return cb;
|
1160 |
|
1161 |
} |
1162 |
|
1163 |
|
1164 |
protected JComboBox get3DRasterLayerSelectionComboBox(final boolean bAddNotSetField) { |
1165 |
|
1166 |
int i;
|
1167 |
|
1168 |
final I3DRasterLayer[] layers = SextanteGUI.getInputFactory().get3DRasterLayers(); |
1169 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
1170 |
for (i = 0; i < layers.length; i++) { |
1171 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
1172 |
} |
1173 |
|
1174 |
final JComboBox cb = new JComboBox(oad); |
1175 |
|
1176 |
if (bAddNotSetField) {
|
1177 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1178 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1179 |
} |
1180 |
|
1181 |
return cb;
|
1182 |
|
1183 |
} |
1184 |
|
1185 |
protected ObjectAndDescription[] getVectorLayersAsObjectAndDescription(int shapeTypes) { |
1186 |
int[] shapeTypesList = new int[1]; |
1187 |
shapeTypesList[0] = shapeTypes;
|
1188 |
return getVectorLayersAsObjectAndDescription(shapeTypesList);
|
1189 |
} |
1190 |
|
1191 |
protected ObjectAndDescription[] getVectorLayersAsObjectAndDescription(int[] shapeTypes) { |
1192 |
final List<IVectorLayer> layers = getVectorLayers(shapeTypes); |
1193 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.size()]; |
1194 |
int i = 0; |
1195 |
for (IVectorLayer layer : layers) {
|
1196 |
String viewName = layer.getContextName();
|
1197 |
String description;
|
1198 |
String moreinfo = null; |
1199 |
|
1200 |
if (layer.hasSelection()) {
|
1201 |
moreinfo = " [" + layer.getShapesCount() + " selected]"; |
1202 |
} |
1203 |
if (viewName != null && moreinfo == null) { |
1204 |
description = layer.getName() + " [" + viewName + "]"; |
1205 |
} else if (viewName != null && moreinfo != null) { |
1206 |
description = layer.getName() + " [" + viewName + "]" + moreinfo; |
1207 |
} else {
|
1208 |
description = layer.getName(); |
1209 |
} |
1210 |
IconTheme tm = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1211 |
ImageIcon layerIcon = null; |
1212 |
if (layer.hasSelection()) {
|
1213 |
switch (layer.getShapeType()) {
|
1214 |
case IVectorLayer.SHAPE_TYPE_POINT:
|
1215 |
layerIcon = tm.get("layer-type-point-sel");
|
1216 |
break;
|
1217 |
case IVectorLayer.SHAPE_TYPE_MULTIPOINT:
|
1218 |
layerIcon = tm.get("layer-type-multipoint-sel");
|
1219 |
break;
|
1220 |
case IVectorLayer.SHAPE_TYPE_LINE:
|
1221 |
layerIcon = tm.get("layer-type-line-sel");
|
1222 |
break;
|
1223 |
case IVectorLayer.SHAPE_TYPE_MULTILINE:
|
1224 |
layerIcon = tm.get("layer-type-multiline-sel");
|
1225 |
break;
|
1226 |
case IVectorLayer.SHAPE_TYPE_POLYGON:
|
1227 |
layerIcon = tm.get("layer-type-polygon-sel");
|
1228 |
break;
|
1229 |
case IVectorLayer.SHAPE_TYPE_MULTIPOLYGON:
|
1230 |
layerIcon = tm.get("layer-type-multipolygon-sel");
|
1231 |
break;
|
1232 |
case IVectorLayer.SHAPE_TYPE_MIXED:
|
1233 |
layerIcon = tm.get("layer-type-mix-sel");
|
1234 |
break;
|
1235 |
case IVectorLayer.SHAPE_TYPE_WRONG:
|
1236 |
layerIcon = tm.get("layer-type-wrong");
|
1237 |
break;
|
1238 |
} |
1239 |
} else if (!layer.hasSelection()) { |
1240 |
switch (layer.getShapeType()) {
|
1241 |
case IVectorLayer.SHAPE_TYPE_POINT:
|
1242 |
layerIcon = tm.get("layer-type-point");
|
1243 |
break;
|
1244 |
case IVectorLayer.SHAPE_TYPE_MULTIPOINT:
|
1245 |
layerIcon = tm.get("layer-type-multipoint");
|
1246 |
break;
|
1247 |
case IVectorLayer.SHAPE_TYPE_LINE:
|
1248 |
layerIcon = tm.get("layer-type-line");
|
1249 |
break;
|
1250 |
case IVectorLayer.SHAPE_TYPE_MULTILINE:
|
1251 |
layerIcon = tm.get("layer-type-multiline");
|
1252 |
break;
|
1253 |
case IVectorLayer.SHAPE_TYPE_POLYGON:
|
1254 |
layerIcon = tm.get("layer-type-polygon");
|
1255 |
break;
|
1256 |
case IVectorLayer.SHAPE_TYPE_MULTIPOLYGON:
|
1257 |
layerIcon = tm.get("layer-type-multipolygon");
|
1258 |
break;
|
1259 |
case IVectorLayer.SHAPE_TYPE_MIXED:
|
1260 |
layerIcon = tm.get("layer-type-mix");
|
1261 |
break;
|
1262 |
case IVectorLayer.SHAPE_TYPE_WRONG:
|
1263 |
layerIcon = tm.get("layer-type-wrong");
|
1264 |
break;
|
1265 |
} |
1266 |
} |
1267 |
|
1268 |
oad[i] = new ObjectAndDescription(description, layers.get(i), layerIcon);
|
1269 |
i++; |
1270 |
} |
1271 |
return oad;
|
1272 |
} |
1273 |
|
1274 |
protected JComboBox getVectorLayerSelectionComboBox(final int iShapeType, |
1275 |
final ArrayList childComboBoxes, |
1276 |
final boolean bAddNotSetField) { |
1277 |
|
1278 |
int i;
|
1279 |
|
1280 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1281 |
for (i = 0; i < childsArray.length; i++) { |
1282 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1283 |
} |
1284 |
|
1285 |
ObjectAndDescription[] oad = getVectorLayersAsObjectAndDescription(iShapeType);
|
1286 |
final JComboBox cb = new JComboBox(oad); |
1287 |
|
1288 |
if (bAddNotSetField) {
|
1289 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1290 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1291 |
} |
1292 |
|
1293 |
cb.addItemListener(new java.awt.event.ItemListener() {
|
1294 |
@Override
|
1295 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1296 |
int i;
|
1297 |
int iIndex;
|
1298 |
DefaultComboBoxModel defaultModel;
|
1299 |
for (i = 0; i < childsArray.length; i++) { |
1300 |
iIndex = (childsArray[i]); |
1301 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
|
1302 |
final IVectorLayer layer = (IVectorLayer) ob.getObject();
|
1303 |
if (layer != null) { |
1304 |
Object item = m_ComboBox.get(iIndex);
|
1305 |
if (item instanceof JComboBox) { |
1306 |
FieldDescriptionComboBox[] sNames = getVectorLayerFieldRendererComboBox(layer);
|
1307 |
if (sNames != null) { |
1308 |
defaultModel = new DefaultComboBoxModel(sNames); |
1309 |
JComboBox cmb = (JComboBox) item; |
1310 |
cmb.setModel(defaultModel); |
1311 |
} |
1312 |
} |
1313 |
if (item instanceof TableFilterPanel) { |
1314 |
TableFilterPanel pane = (TableFilterPanel) item; |
1315 |
pane.setStore(layer.getFeatureStore()); |
1316 |
} |
1317 |
} |
1318 |
} |
1319 |
} |
1320 |
}); |
1321 |
|
1322 |
return cb;
|
1323 |
|
1324 |
} |
1325 |
|
1326 |
protected JComboBox<ObjectAndDescription> getVectorLayerSelectionComboBox(int[] shapeTypes, final List childComboBoxes, |
1327 |
final boolean bAddNotSetField) { |
1328 |
|
1329 |
int i;
|
1330 |
|
1331 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1332 |
for (i = 0; i < childsArray.length; i++) { |
1333 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1334 |
} |
1335 |
|
1336 |
ObjectAndDescription[] oad = getVectorLayersAsObjectAndDescription(shapeTypes);
|
1337 |
final JComboBox cb = new JComboBox(oad); |
1338 |
LayerComboBoxRenderer renderer = new LayerComboBoxRenderer();
|
1339 |
cb.setRenderer(renderer); |
1340 |
|
1341 |
if (bAddNotSetField) {
|
1342 |
final DefaultComboBoxModel model = (DefaultComboBoxModel) cb.getModel(); |
1343 |
model.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1344 |
} |
1345 |
|
1346 |
cb.addItemListener(new java.awt.event.ItemListener() {
|
1347 |
|
1348 |
@Override
|
1349 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1350 |
int i;
|
1351 |
int iIndex;
|
1352 |
DefaultComboBoxModel defaultModel;
|
1353 |
for (i = 0; i < childsArray.length; i++) { |
1354 |
iIndex = (childsArray[i]); |
1355 |
final ObjectAndDescription ob = (ObjectAndDescription) cb.getSelectedItem();
|
1356 |
final IVectorLayer layer = (IVectorLayer) ob.getObject();
|
1357 |
if (layer != null) { |
1358 |
Object item = m_ComboBox.get(iIndex);
|
1359 |
if (item instanceof JComboBox) { |
1360 |
FieldDescriptionComboBox[] sNames = getVectorLayerFieldRendererComboBox(layer);
|
1361 |
if (sNames != null) { |
1362 |
defaultModel = new DefaultComboBoxModel(sNames); |
1363 |
JComboBox cmb = (JComboBox) item; |
1364 |
cmb.setModel(defaultModel); |
1365 |
} |
1366 |
} |
1367 |
if (item instanceof TableFilterPanel) { |
1368 |
TableFilterPanel pane = (TableFilterPanel) item; |
1369 |
pane.setStore(layer.getFeatureStore()); |
1370 |
} |
1371 |
} |
1372 |
} |
1373 |
} |
1374 |
}); |
1375 |
|
1376 |
return cb;
|
1377 |
|
1378 |
} |
1379 |
|
1380 |
/**
|
1381 |
* @param shapeTypes
|
1382 |
* @return
|
1383 |
*/
|
1384 |
private List<ITable> getTables() { |
1385 |
List<ITable> tables = new ArrayList<ITable>(); |
1386 |
ITable[] allTables = SextanteGUI.getInputFactory().getTables();
|
1387 |
for (int k = 0; k < allTables.length; k++) { |
1388 |
tables.add(allTables[k]); |
1389 |
}; |
1390 |
|
1391 |
return tables;
|
1392 |
} |
1393 |
|
1394 |
/**
|
1395 |
* @param shapeTypes
|
1396 |
* @return
|
1397 |
*/
|
1398 |
private List<IVectorLayer> getVectorLayers(int[] shapeTypes) { |
1399 |
List<IVectorLayer> layers = new ArrayList<IVectorLayer>(); |
1400 |
for (int j = 0; j < shapeTypes.length; j++) { |
1401 |
IVectorLayer[] layersPerType = SextanteGUI.getInputFactory().getVectorLayers(shapeTypes[j]);
|
1402 |
for (int k = 0; k < layersPerType.length; k++) { |
1403 |
layers.add(layersPerType[k]); |
1404 |
}; |
1405 |
} |
1406 |
return layers;
|
1407 |
} |
1408 |
|
1409 |
protected JComboBox getTableSelectionComboBox(final ArrayList childComboBoxes, |
1410 |
final boolean bAddNotSetField) { |
1411 |
|
1412 |
int i;
|
1413 |
final JComboBox comboBox = new JComboBox(); |
1414 |
|
1415 |
final Integer[] childsArray = new Integer[childComboBoxes.size()]; |
1416 |
for (i = 0; i < childsArray.length; i++) { |
1417 |
childsArray[i] = (Integer) childComboBoxes.get(i);
|
1418 |
} |
1419 |
|
1420 |
final ITable[] tables = SextanteGUI.getInputFactory().getTables(); |
1421 |
final ObjectAndDescription[] oad = new ObjectAndDescription[tables.length]; |
1422 |
for (i = 0; i < tables.length; i++) { |
1423 |
oad[i] = new ObjectAndDescription(tables[i].getName(), tables[i]);
|
1424 |
} |
1425 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(oad); |
1426 |
comboBox.setModel(defaultModel); |
1427 |
|
1428 |
if (bAddNotSetField) {
|
1429 |
defaultModel.insertElementAt(new ObjectAndDescription(Sextante.getText("[Not_selected]"), null), 0); |
1430 |
} |
1431 |
|
1432 |
comboBox.addItemListener(new java.awt.event.ItemListener() {
|
1433 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
1434 |
int i;
|
1435 |
int iIndex;
|
1436 |
String sNames[] = null; |
1437 |
DefaultComboBoxModel defaultModel;
|
1438 |
for (i = 0; i < childsArray.length; i++) { |
1439 |
iIndex = (childsArray[i]).intValue(); |
1440 |
final ObjectAndDescription ob = (ObjectAndDescription) comboBox.getSelectedItem();
|
1441 |
final ITable table = (ITable) ob.getObject();
|
1442 |
if (table != null) { |
1443 |
Object item = m_ComboBox.get(iIndex);
|
1444 |
if (item instanceof JComboBox) { |
1445 |
sNames = getTableFieldNames(table); |
1446 |
if (sNames != null) { |
1447 |
defaultModel = new DefaultComboBoxModel(sNames); |
1448 |
((JComboBox) item).setModel(defaultModel);
|
1449 |
} |
1450 |
} |
1451 |
if (item instanceof TableFilterPanel) { |
1452 |
TableFilterPanel pane = (TableFilterPanel) item; |
1453 |
pane.setStore(table.getFeatureStore()); |
1454 |
|
1455 |
} |
1456 |
} |
1457 |
} |
1458 |
} |
1459 |
}); |
1460 |
|
1461 |
return comboBox;
|
1462 |
|
1463 |
} |
1464 |
|
1465 |
|
1466 |
protected JComboBox getTableFieldSelectionComboBox() { |
1467 |
|
1468 |
final ITable[] tables = SextanteGUI.getInputFactory().getTables(); |
1469 |
|
1470 |
if (tables.length > 0) { |
1471 |
final JComboBox comboBox = new JComboBox(); |
1472 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getTableFieldNames(tables[0])); |
1473 |
comboBox.setModel(defaultModel); |
1474 |
return comboBox;
|
1475 |
} |
1476 |
else {
|
1477 |
return new JComboBox(); |
1478 |
} |
1479 |
|
1480 |
} |
1481 |
|
1482 |
|
1483 |
protected JComboBox getBandSelectionComboBox() { |
1484 |
|
1485 |
final IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers(); |
1486 |
|
1487 |
if (layers.length > 0) { |
1488 |
final JComboBox comboBox = new JComboBox(); |
1489 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getBandNames(layers[0])); |
1490 |
comboBox.setModel(defaultModel); |
1491 |
return comboBox;
|
1492 |
} |
1493 |
else {
|
1494 |
return new JComboBox(); |
1495 |
} |
1496 |
|
1497 |
} |
1498 |
|
1499 |
|
1500 |
protected JComboBox getVectorLayerFieldSelectionComboBox(final int iShapeType) { |
1501 |
|
1502 |
final IVectorLayer[] layers = SextanteGUI.getInputFactory().getVectorLayers(iShapeType); |
1503 |
|
1504 |
if (layers.length > 0) { |
1505 |
final JComboBox comboBox = new JComboBox(); |
1506 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldNames(layers[0])); |
1507 |
comboBox.setModel(defaultModel); |
1508 |
return comboBox;
|
1509 |
} |
1510 |
else {
|
1511 |
return new JComboBox(); |
1512 |
} |
1513 |
|
1514 |
} |
1515 |
|
1516 |
protected FieldDescriptionComboBox[] getVectorLayerFieldRendererComboBox(IVectorLayer layer) { |
1517 |
final FieldDescriptionComboBox[] oad = new FieldDescriptionComboBox[layer.getFieldNames().length]; |
1518 |
for (int i = 0; i < layer.getFieldNames().length; i++) { |
1519 |
String fieldName = layer.getFieldName(i);
|
1520 |
Class fieldClass = layer.getFieldType(i);
|
1521 |
oad[i]=new FieldDescriptionComboBox(fieldName, fieldClass);
|
1522 |
} |
1523 |
return oad;
|
1524 |
} |
1525 |
protected JComboBox getVectorLayerFieldSelectionComboBox(final int[] shapeTypes) { |
1526 |
|
1527 |
List<IVectorLayer> layers = getVectorLayers(shapeTypes);
|
1528 |
|
1529 |
if (layers.size() > 0) { |
1530 |
final JComboBox comboBox = new JComboBox(); |
1531 |
IVectorLayer layer = layers.get(0);
|
1532 |
//final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldNames(layers.get(0)));
|
1533 |
final DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getVectorLayerFieldRendererComboBox(layer)); |
1534 |
FieldComboBoxRenderer renderer = new FieldComboBoxRenderer();
|
1535 |
comboBox.setRenderer(renderer); |
1536 |
comboBox.setModel(defaultModel); |
1537 |
return comboBox;
|
1538 |
} |
1539 |
else {
|
1540 |
return new JComboBox(); |
1541 |
} |
1542 |
|
1543 |
} |
1544 |
|
1545 |
protected String[] getTableFieldNames(final ITable table) { |
1546 |
|
1547 |
return table.getFieldNames();
|
1548 |
|
1549 |
} |
1550 |
|
1551 |
|
1552 |
protected String[] getVectorLayerFieldNames(final IVectorLayer vectorLayer) { |
1553 |
|
1554 |
return vectorLayer.getFieldNames();
|
1555 |
|
1556 |
} |
1557 |
|
1558 |
|
1559 |
protected String[] getBandNames(final IRasterLayer layer) { |
1560 |
|
1561 |
int j;
|
1562 |
int iBands;
|
1563 |
String[] bands = null; |
1564 |
|
1565 |
iBands = layer.getBandsCount(); |
1566 |
bands = new String[iBands]; |
1567 |
for (j = 0; j < iBands; j++) { |
1568 |
bands[j] = Integer.toString(j + 1); |
1569 |
} |
1570 |
|
1571 |
return bands;
|
1572 |
|
1573 |
} |
1574 |
|
1575 |
|
1576 |
@Override
|
1577 |
public void assignParameters() throws WrongInputException, LayerCannotBeOverwrittenException { |
1578 |
|
1579 |
boolean bAssigningOK = true; |
1580 |
int i;
|
1581 |
ParameterContainer parameterContainer; |
1582 |
String sType;
|
1583 |
|
1584 |
for (i = 0; i < m_ParameterContainer.size(); i++) { |
1585 |
parameterContainer = (ParameterContainer) m_ParameterContainer.get(i); |
1586 |
sType = parameterContainer.getType(); |
1587 |
if (sType.equals("Table")) { |
1588 |
bAssigningOK = assignInputTable(parameterContainer); |
1589 |
} |
1590 |
else if (sType.equals("Vector Layer") || sType.equals("Raster Layer") || sType.equals("3D Raster Layer")) { |
1591 |
bAssigningOK = assignInputLayer(parameterContainer); |
1592 |
} |
1593 |
else if (sType.equals("Numerical Value")) { |
1594 |
bAssigningOK = assignInputNumericalValue(parameterContainer); |
1595 |
} |
1596 |
else if (sType.equals("String")) { |
1597 |
bAssigningOK = assignInputString(parameterContainer); |
1598 |
} |
1599 |
else if (sType.equals("Boolean")) { |
1600 |
bAssigningOK = assignInputBoolean(parameterContainer); |
1601 |
} |
1602 |
else if (sType.equals("Fixed Table")) { |
1603 |
bAssigningOK = assignInputFixedTable(parameterContainer); |
1604 |
} |
1605 |
else if (sType.equals("Multiple Input")) { |
1606 |
bAssigningOK = assignInputMultipleInput(parameterContainer); |
1607 |
} |
1608 |
else if (sType.equals("Point")) { |
1609 |
bAssigningOK = assignInputPoint(parameterContainer); |
1610 |
} |
1611 |
else if (parameterContainer.getType().equals("Filepath")) { |
1612 |
bAssigningOK = assignInputFilepath(parameterContainer); |
1613 |
} |
1614 |
else if (sType.equals("Table Field") || sType.equals("Selection") || sType.equals("Band")) { |
1615 |
bAssigningOK = assignInputSelection(parameterContainer); |
1616 |
} |
1617 |
else if (sType.equals("Table Filter")) { |
1618 |
bAssigningOK = assignInputTableFilter(parameterContainer); |
1619 |
} |
1620 |
|
1621 |
if (!bAssigningOK) {
|
1622 |
throw new WrongInputException(); |
1623 |
} |
1624 |
|
1625 |
} |
1626 |
|
1627 |
final OutputObjectsSet ooset = m_Algorithm.getOutputObjects();
|
1628 |
for (i = 0; i < m_OutputParameterContainer.size(); i++) { |
1629 |
final OutputParameterContainer opc = (OutputParameterContainer) m_OutputParameterContainer.get(i);
|
1630 |
Output out; |
1631 |
|
1632 |
try {
|
1633 |
out = ooset.getOutput(opc.getName()); |
1634 |
} |
1635 |
catch (final WrongOutputIDException e) { |
1636 |
throw new WrongInputException(); |
1637 |
} |
1638 |
|
1639 |
final OutputChannelSelectionPanel ocsp = (OutputChannelSelectionPanel) opc.getContainer();
|
1640 |
IOutputChannel channel; |
1641 |
try {
|
1642 |
channel = ocsp.getOutputChannel(); |
1643 |
} |
1644 |
catch (final WrongOutputChannelDataException e) { |
1645 |
throw new WrongInputException(); |
1646 |
} |
1647 |
|
1648 |
if (channel instanceof OverwriteOutputChannel) { |
1649 |
final OverwriteOutputChannel ooc = (OverwriteOutputChannel) channel;
|
1650 |
if (!ooc.getLayer().canBeEdited()) {
|
1651 |
throw new LayerCannotBeOverwrittenException(); |
1652 |
} |
1653 |
} |
1654 |
out.setOutputChannel(channel); |
1655 |
//TODO Check that output channels do not match with input layers
|
1656 |
|
1657 |
} |
1658 |
|
1659 |
|
1660 |
} |
1661 |
|
1662 |
|
1663 |
protected boolean assignInputTable(final ParameterContainer parameterContainer) { |
1664 |
|
1665 |
boolean bReturn = true; |
1666 |
|
1667 |
try {
|
1668 |
final JComboBox comboBox = (JComboBox) parameterContainer.getContainer(); |
1669 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1670 |
final ObjectAndDescription oad = (ObjectAndDescription) comboBox.getSelectedItem();
|
1671 |
bReturn = parameter.setParameterValue(oad.getObject()); |
1672 |
} |
1673 |
catch (final Exception e) { |
1674 |
Sextante.addErrorToLog(e); |
1675 |
return false; |
1676 |
} |
1677 |
|
1678 |
return bReturn;
|
1679 |
|
1680 |
} |
1681 |
|
1682 |
|
1683 |
protected boolean assignInputLayer(final ParameterContainer parameterContainer) { |
1684 |
|
1685 |
boolean bReturn = true; |
1686 |
|
1687 |
try {
|
1688 |
final JComboBox comboBox = (JComboBox) parameterContainer.getContainer(); |
1689 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1690 |
final ObjectAndDescription oad = (ObjectAndDescription) comboBox.getSelectedItem();
|
1691 |
bReturn = parameter.setParameterValue(oad.getObject()); |
1692 |
} |
1693 |
catch (final Exception e) { |
1694 |
Sextante.addErrorToLog(e); |
1695 |
return false; |
1696 |
} |
1697 |
|
1698 |
return bReturn;
|
1699 |
|
1700 |
} |
1701 |
|
1702 |
|
1703 |
protected boolean assignInputMultipleInput(final ParameterContainer parameterContainer) { |
1704 |
|
1705 |
boolean bReturn;
|
1706 |
|
1707 |
try {
|
1708 |
//final MultipleInputSelectionPanel panel = (MultipleInputSelectionPanel) parameterContainer.getContainer();
|
1709 |
final CheckComboBox ccb = (CheckComboBox) parameterContainer.getContainer();
|
1710 |
final ParameterMultipleInput parameter = (ParameterMultipleInput) m_Algorithm.getParameters().getParameter(
|
1711 |
parameterContainer.getName()); |
1712 |
final List<Object> list = ccb.getModel().getCheckeds(); |
1713 |
//final ArrayList list = panel.getSelectedObjects();
|
1714 |
final AdditionalInfoMultipleInput ai = (AdditionalInfoMultipleInput) parameter.getParameterAdditionalInfo();
|
1715 |
final boolean bMandatory = ai.getIsMandatory(); |
1716 |
if (bMandatory && (list.size() == 0)) { |
1717 |
return false; |
1718 |
} |
1719 |
bReturn = parameter.setParameterValue(list); |
1720 |
} |
1721 |
catch (final Exception e) { |
1722 |
Sextante.addErrorToLog(e); |
1723 |
return false; |
1724 |
} |
1725 |
|
1726 |
return bReturn;
|
1727 |
|
1728 |
} |
1729 |
|
1730 |
|
1731 |
protected boolean assignInputSelection(final ParameterContainer parameterContainer) { |
1732 |
|
1733 |
int iIndex;
|
1734 |
boolean bReturn = true; |
1735 |
|
1736 |
try {
|
1737 |
final JComboBox comboBox = (JComboBox) parameterContainer.getContainer(); |
1738 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1739 |
iIndex = comboBox.getSelectedIndex(); |
1740 |
bReturn = parameter.setParameterValue(new Integer(iIndex)); |
1741 |
|
1742 |
if (parameter instanceof ParameterTableField) { |
1743 |
parameter.setParameterValue(comboBox.getSelectedItem().toString()); |
1744 |
} |
1745 |
|
1746 |
} |
1747 |
catch (final WrongParameterIDException e) { |
1748 |
Sextante.addErrorToLog(e); |
1749 |
return false; |
1750 |
} |
1751 |
|
1752 |
return bReturn;
|
1753 |
|
1754 |
} |
1755 |
|
1756 |
|
1757 |
protected boolean assignInputNumericalValue(final ParameterContainer parameterContainer) { |
1758 |
|
1759 |
boolean bReturn;
|
1760 |
|
1761 |
try {
|
1762 |
final JTextField txtField = (JTextField) parameterContainer.getContainer(); |
1763 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1764 |
bReturn = parameter.setParameterValue(new Double(Double.parseDouble(txtField.getText()))); |
1765 |
} |
1766 |
catch (final Exception e) { |
1767 |
Sextante.addErrorToLog(e); |
1768 |
return false; |
1769 |
} |
1770 |
|
1771 |
return bReturn;
|
1772 |
|
1773 |
} |
1774 |
|
1775 |
|
1776 |
protected boolean assignInputFixedTable(final ParameterContainer parameterContainer) { |
1777 |
|
1778 |
boolean bReturn;
|
1779 |
|
1780 |
try {
|
1781 |
final FixedTablePanel panel = (FixedTablePanel) parameterContainer.getContainer();
|
1782 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1783 |
bReturn = parameter.setParameterValue(panel.getTableModel()); |
1784 |
} |
1785 |
catch (final WrongParameterIDException e) { |
1786 |
Sextante.addErrorToLog(e); |
1787 |
return false; |
1788 |
} |
1789 |
|
1790 |
return bReturn;
|
1791 |
|
1792 |
} |
1793 |
|
1794 |
|
1795 |
protected boolean assignInputString(final ParameterContainer parameterContainer) { |
1796 |
|
1797 |
boolean bReturn;
|
1798 |
|
1799 |
try {
|
1800 |
final JTextField txtField = (JTextField) parameterContainer.getContainer(); |
1801 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1802 |
bReturn = parameter.setParameterValue(txtField.getText()); |
1803 |
} |
1804 |
catch (final WrongParameterIDException e) { |
1805 |
Sextante.addErrorToLog(e); |
1806 |
return false; |
1807 |
} |
1808 |
|
1809 |
return bReturn;
|
1810 |
|
1811 |
} |
1812 |
|
1813 |
|
1814 |
protected boolean assignInputFilepath(final ParameterContainer parameterContainer) { |
1815 |
|
1816 |
boolean bReturn;
|
1817 |
|
1818 |
try {
|
1819 |
final FileSelectionPanel fileSelectionPanel = (FileSelectionPanel) parameterContainer.getContainer();
|
1820 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1821 |
bReturn = parameter.setParameterValue(fileSelectionPanel.getFilepath()); |
1822 |
} |
1823 |
catch (final WrongParameterIDException e) { |
1824 |
Sextante.addErrorToLog(e); |
1825 |
return false; |
1826 |
} |
1827 |
|
1828 |
return bReturn;
|
1829 |
|
1830 |
} |
1831 |
|
1832 |
protected boolean assignInputTableFilter(final ParameterContainer parameterContainer) { |
1833 |
|
1834 |
boolean bReturn;
|
1835 |
|
1836 |
try {
|
1837 |
final TableFilterPanel fileSelectionPanel = (TableFilterPanel) parameterContainer.getContainer();
|
1838 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1839 |
bReturn = parameter.setParameterValue(fileSelectionPanel.getExpression()); |
1840 |
} |
1841 |
catch (final WrongParameterIDException e) { |
1842 |
Sextante.addErrorToLog(e); |
1843 |
return false; |
1844 |
} |
1845 |
|
1846 |
return bReturn;
|
1847 |
|
1848 |
} |
1849 |
|
1850 |
protected boolean assignInputPoint(final ParameterContainer parameterContainer) { |
1851 |
|
1852 |
boolean bReturn;
|
1853 |
|
1854 |
try {
|
1855 |
final PointSelectionPanel pointSelectionPanel = (PointSelectionPanel) parameterContainer.getContainer();
|
1856 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1857 |
bReturn = parameter.setParameterValue(pointSelectionPanel.getPoint()); |
1858 |
} |
1859 |
catch (final Exception e) { |
1860 |
Sextante.addErrorToLog(e); |
1861 |
return false; |
1862 |
} |
1863 |
|
1864 |
return bReturn;
|
1865 |
|
1866 |
} |
1867 |
|
1868 |
|
1869 |
protected boolean assignInputBoolean(final ParameterContainer parameterContainer) { |
1870 |
|
1871 |
boolean bReturn;
|
1872 |
|
1873 |
try {
|
1874 |
final JCheckBox checkBox = (JCheckBox) parameterContainer.getContainer(); |
1875 |
final Parameter parameter = m_Algorithm.getParameters().getParameter(parameterContainer.getName());
|
1876 |
bReturn = parameter.setParameterValue(new Boolean(checkBox.isSelected())); |
1877 |
} |
1878 |
catch (final WrongParameterIDException e) { |
1879 |
Sextante.addErrorToLog(e); |
1880 |
return false; |
1881 |
} |
1882 |
|
1883 |
return bReturn;
|
1884 |
|
1885 |
} |
1886 |
|
1887 |
|
1888 |
@Override
|
1889 |
public void setOutputValue(final String sOutputName, |
1890 |
final String sValue) { |
1891 |
|
1892 |
for (int i = 0; i < m_OutputParameterContainer.size(); i++) { |
1893 |
final OutputParameterContainer container = (OutputParameterContainer) m_OutputParameterContainer.get(i);
|
1894 |
if (sOutputName.equals(container.getName())) {
|
1895 |
final OutputChannelSelectionPanel ocsp = (OutputChannelSelectionPanel) container.getContainer();
|
1896 |
ocsp.setText(sValue); |
1897 |
} |
1898 |
} |
1899 |
|
1900 |
} |
1901 |
|
1902 |
|
1903 |
@Override
|
1904 |
public void setParameterValue(final String sParameterName, |
1905 |
final String sValue) { |
1906 |
|
1907 |
final ParametersSet parameters = m_Algorithm.getParameters();
|
1908 |
Parameter param; |
1909 |
try {
|
1910 |
param = parameters.getParameter(sParameterName); |
1911 |
} |
1912 |
catch (final WrongParameterIDException e1) { |
1913 |
return;
|
1914 |
} |
1915 |
Object container = null; |
1916 |
for (int i = 0; i < m_ParameterContainer.size(); i++) { |
1917 |
final ParameterContainer pc = (ParameterContainer) m_ParameterContainer.get(i);
|
1918 |
if (pc.getName().equals(sParameterName)) {
|
1919 |
container = pc.getContainer(); |
1920 |
break;
|
1921 |
} |
1922 |
} |
1923 |
|
1924 |
if (container == null) { |
1925 |
return;
|
1926 |
} |
1927 |
|
1928 |
try {
|
1929 |
if (param instanceof ParameterDataObject) { |
1930 |
if (container instanceof JComboBox) { |
1931 |
final JComboBox cb = (JComboBox) container; |
1932 |
final ComboBoxModel model = cb.getModel(); |
1933 |
for (int i = 0; i < model.getSize(); i++) { |
1934 |
final ObjectAndDescription oad = (ObjectAndDescription) model.getElementAt(i);
|
1935 |
if (oad.getDescription().equals(sValue)) {
|
1936 |
cb.setSelectedIndex(i); |
1937 |
break;
|
1938 |
} |
1939 |
} |
1940 |
} else if (container instanceof TableFilterPanel) { |
1941 |
TableFilterPanel cb = (TableFilterPanel) container; |
1942 |
cb.setPhrase(cb.getPhrase()); |
1943 |
} |
1944 |
} |
1945 |
else if ((param instanceof ParameterNumericalValue) || (param instanceof ParameterString)) { |
1946 |
if (!sValue.equals("#")) { |
1947 |
final JTextField tf = (JTextField) container; |
1948 |
tf.setText(sValue); |
1949 |
} |
1950 |
} |
1951 |
else if (param instanceof ParameterFilepath) { |
1952 |
final FileSelectionPanel fsp = (FileSelectionPanel) container;
|
1953 |
fsp.setFilepath(sValue); |
1954 |
} |
1955 |
else if (param instanceof ParameterFixedTable) { |
1956 |
this.setFixedTableValue(param, (FixedTablePanel) container, sValue);
|
1957 |
} |
1958 |
else if (param instanceof ParameterBoolean) { |
1959 |
if (!sValue.equals("#")) { |
1960 |
final JCheckBox cb = (JCheckBox) container; |
1961 |
boolean bValue;
|
1962 |
if (sValue.equals("true")) { |
1963 |
bValue = true;
|
1964 |
} |
1965 |
else {
|
1966 |
bValue = false;
|
1967 |
} |
1968 |
cb.setSelected(bValue); |
1969 |
|
1970 |
} |
1971 |
} |
1972 |
else if (param instanceof ParameterSelection) { |
1973 |
if (!sValue.equals("#")) { |
1974 |
final int iIndex = Integer.parseInt(sValue); |
1975 |
final AdditionalInfoSelection ai = (AdditionalInfoSelection) param.getParameterAdditionalInfo();
|
1976 |
if ((iIndex >= 0) && (iIndex < ai.getValues().length)) { |
1977 |
final JComboBox cb = (JComboBox) container; |
1978 |
cb.setSelectedIndex(iIndex); |
1979 |
} |
1980 |
} |
1981 |
} |
1982 |
else if (param instanceof ParameterMultipleInput) { |
1983 |
|
1984 |
final ArrayList selectedIndices = new ArrayList(); |
1985 |
final String[] sObjects = sValue.split(","); |
1986 |
//final MultipleInputSelectionPanel msp = (MultipleInputSelectionPanel) container;
|
1987 |
final CheckComboBox ccb = (CheckComboBox) container;
|
1988 |
final Object[] objs = new Object[ccb.getModel().getSize()]; |
1989 |
for (int j = 0; j < objs.length; j++) { |
1990 |
objs[j] = ccb.getModel().getElementAt(j); |
1991 |
} |
1992 |
for (int j = 0; j < objs.length; j++) { |
1993 |
for (int i = 0; i < sObjects.length; i++) { |
1994 |
if (objs[j] instanceof IDataObject) { |
1995 |
final IDataObject ido = (IDataObject) objs[j];
|
1996 |
if (ido.getName().equals(sObjects[i].trim())) {
|
1997 |
ccb.getModel().addCheck(objs[j]); |
1998 |
//selectedIndices.add(new Integer(j));
|
1999 |
break;
|
2000 |
} |
2001 |
} |
2002 |
else if (objs[j] instanceof RasterLayerAndBand) { |
2003 |
try {
|
2004 |
final RasterLayerAndBand rlab = (RasterLayerAndBand) objs[j];
|
2005 |
if (rlab.getRasterLayer().getName().equals(sObjects[i].trim())) {
|
2006 |
if (Integer.parseInt(sObjects[i + 1].trim()) - 1 == rlab.getBand()) { |
2007 |
ccb.getModel().addCheck(objs[j]); |
2008 |
//selectedIndices.add(new Integer(j));
|
2009 |
break;
|
2010 |
} |
2011 |
} |
2012 |
} |
2013 |
catch (final Exception e) { |
2014 |
} |
2015 |
|
2016 |
} |
2017 |
} |
2018 |
} |
2019 |
//msp.setSelectedIndices(selectedIndices);
|
2020 |
} |
2021 |
else if (param instanceof ParameterPoint) { |
2022 |
final StringTokenizer st = new StringTokenizer(sValue, ","); |
2023 |
if (st.countTokens() == 2) { |
2024 |
final double x = Double.parseDouble(st.nextToken()); |
2025 |
final double y = Double.parseDouble(st.nextToken()); |
2026 |
final PointSelectionPanel psp = (PointSelectionPanel) container;
|
2027 |
psp.setPoint(new Point2D.Double(x, y)); |
2028 |
} |
2029 |
} |
2030 |
else if ((param instanceof ParameterTableField) || (param instanceof ParameterBand)) { |
2031 |
final JComboBox cb = (JComboBox) container; |
2032 |
try {
|
2033 |
cb.setSelectedIndex(Integer.parseInt(sValue));
|
2034 |
} |
2035 |
catch (final Exception e) { |
2036 |
} |
2037 |
} |
2038 |
|
2039 |
} |
2040 |
catch (final NullParameterAdditionalInfoException e) { |
2041 |
Sextante.addErrorToLog(e); |
2042 |
} catch (final NumberFormatException e) { |
2043 |
Sextante.addErrorToLog(e); |
2044 |
} |
2045 |
|
2046 |
} |
2047 |
|
2048 |
|
2049 |
protected void setFixedTableValue(final Parameter param, |
2050 |
final FixedTablePanel container,
|
2051 |
final String sValue) { |
2052 |
|
2053 |
boolean bIsNumberOfRowsFixed;
|
2054 |
int iCols, iRows;
|
2055 |
int iCol, iRow;
|
2056 |
int iToken = 0; |
2057 |
FixedTableModel tableModel; |
2058 |
final StringTokenizer st = new StringTokenizer(sValue, ","); |
2059 |
String sToken;
|
2060 |
AdditionalInfoFixedTable ai; |
2061 |
try {
|
2062 |
ai = (AdditionalInfoFixedTable) param.getParameterAdditionalInfo(); |
2063 |
iCols = ai.getColsCount(); |
2064 |
final int iTokens = st.countTokens(); |
2065 |
iRows = (st.countTokens() / iCols); |
2066 |
bIsNumberOfRowsFixed = ai.isNumberOfRowsFixed(); |
2067 |
tableModel = new FixedTableModel(ai.getCols(), iRows, bIsNumberOfRowsFixed);
|
2068 |
|
2069 |
if (bIsNumberOfRowsFixed) {
|
2070 |
if (iRows != ai.getRowsCount()) {
|
2071 |
return;
|
2072 |
} |
2073 |
} |
2074 |
else {
|
2075 |
if (st.countTokens() % iCols != 0) { |
2076 |
return;
|
2077 |
} |
2078 |
} |
2079 |
|
2080 |
while (st.hasMoreTokens()) {
|
2081 |
iRow = (int) Math.floor(iToken / (double) iCols); |
2082 |
iCol = iToken % iCols; |
2083 |
sToken = st.nextToken().trim(); |
2084 |
tableModel.setValueAt(sToken, iRow, iCol); |
2085 |
iToken++; |
2086 |
} |
2087 |
|
2088 |
container.setTableModel(tableModel); |
2089 |
|
2090 |
} |
2091 |
catch (final NullParameterAdditionalInfoException e) { |
2092 |
} |
2093 |
|
2094 |
} |
2095 |
|
2096 |
|
2097 |
} |