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