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