root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / modeler / parameters / MultipleInputPanel.java @ 83
History | View | Annotate | Download (5.82 KB)
1 |
package es.unex.sextante.gui.modeler.parameters; |
---|---|
2 |
|
3 |
import info.clearthought.layout.TableLayout; |
4 |
import info.clearthought.layout.TableLayoutConstants; |
5 |
|
6 |
import javax.swing.ComboBoxModel; |
7 |
import javax.swing.DefaultComboBoxModel; |
8 |
import javax.swing.JCheckBox; |
9 |
import javax.swing.JComboBox; |
10 |
import javax.swing.JDialog; |
11 |
import javax.swing.JLabel; |
12 |
import javax.swing.JOptionPane; |
13 |
|
14 |
import es.unex.sextante.additionalInfo.AdditionalInfoMultipleInput; |
15 |
import es.unex.sextante.core.Sextante; |
16 |
import es.unex.sextante.exceptions.NullParameterAdditionalInfoException; |
17 |
import es.unex.sextante.gui.modeler.ModelerPanel; |
18 |
import es.unex.sextante.parameters.Parameter; |
19 |
import es.unex.sextante.parameters.ParameterMultipleInput; |
20 |
|
21 |
public class MultipleInputPanel |
22 |
extends
|
23 |
ParameterPanel { |
24 |
|
25 |
private JLabel jLabelType; |
26 |
private JComboBox jComboBoxType; |
27 |
private JCheckBox jCheckBoxMandatory; |
28 |
|
29 |
|
30 |
public MultipleInputPanel(final JDialog parent, |
31 |
final ModelerPanel panel) {
|
32 |
|
33 |
super(parent, panel);
|
34 |
|
35 |
} |
36 |
|
37 |
|
38 |
public MultipleInputPanel(final ModelerPanel panel) { |
39 |
|
40 |
super(panel);
|
41 |
|
42 |
} |
43 |
|
44 |
|
45 |
@Override
|
46 |
protected void initGUI() { |
47 |
|
48 |
super.initGUI();
|
49 |
|
50 |
super.setTitle(Sextante.getText("modeler_add_par_multiple")); |
51 |
|
52 |
super.setPreferredSize(new java.awt.Dimension(400, 200)); |
53 |
|
54 |
try {
|
55 |
{ |
56 |
final TableLayout thisLayout = new TableLayout |
57 |
(new double[][] { { TableLayoutConstants.MINIMUM, 5.0, TableLayoutConstants.FILL }, |
58 |
{ TableLayoutConstants.MINIMUM, |
59 |
1.0,
|
60 |
TableLayoutConstants.MINIMUM, |
61 |
1.0 } });
|
62 |
thisLayout.setHGap(5);
|
63 |
thisLayout.setVGap(5);
|
64 |
jPanelMiddle.setLayout(thisLayout); |
65 |
{ |
66 |
jLabelType = new JLabel(); |
67 |
jPanelMiddle.add(jLabelType, "0, 0");
|
68 |
jLabelType.setText(Sextante.getText("Input_type"));
|
69 |
} |
70 |
{ |
71 |
final ComboBoxModel jComboBoxTypeModel = new DefaultComboBoxModel(new String[] { |
72 |
Sextante.getText("Vector_any_type"),
|
73 |
Sextante.getText("Vectorial__points"),
|
74 |
Sextante.getText("Vectorial__lines"),
|
75 |
Sextante.getText("Vectorial__polygons"),
|
76 |
Sextante.getText("Raster"),
|
77 |
Sextante.getText("Raster_band"),
|
78 |
Sextante.getText("Table") });
|
79 |
jComboBoxType = new JComboBox(); |
80 |
jPanelMiddle.add(jComboBoxType, "2, 0");
|
81 |
jComboBoxType.setModel(jComboBoxTypeModel); |
82 |
} |
83 |
{ |
84 |
jCheckBoxMandatory = new JCheckBox(); |
85 |
jCheckBoxMandatory.setSelected(true);
|
86 |
jPanelMiddle.add(jCheckBoxMandatory, "0,2,2,2");
|
87 |
jCheckBoxMandatory.setText(Sextante.getText("Mandatory"));
|
88 |
} |
89 |
} |
90 |
} |
91 |
catch (final Exception e) { |
92 |
Sextante.addErrorToLog(e); |
93 |
} |
94 |
|
95 |
} |
96 |
|
97 |
|
98 |
@Override
|
99 |
protected boolean prepareParameter() { |
100 |
|
101 |
int iType = AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY;
|
102 |
|
103 |
switch (jComboBoxType.getSelectedIndex()) {
|
104 |
case 0: |
105 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY; |
106 |
break;
|
107 |
case 1: |
108 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POINT; |
109 |
break;
|
110 |
case 2: |
111 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_LINE; |
112 |
break;
|
113 |
case 3: |
114 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POLYGON; |
115 |
break;
|
116 |
case 4: |
117 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_RASTER; |
118 |
break;
|
119 |
case 5: |
120 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_BAND; |
121 |
break;
|
122 |
case 6: |
123 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_RASTER_3D; |
124 |
break;
|
125 |
case 7: |
126 |
iType = AdditionalInfoMultipleInput.DATA_TYPE_TABLE; |
127 |
break;
|
128 |
} |
129 |
|
130 |
final String sDescription = jTextFieldDescription.getText(); |
131 |
final boolean bMandatory = jCheckBoxMandatory.isSelected(); |
132 |
|
133 |
if (sDescription.length() != 0) { |
134 |
final AdditionalInfoMultipleInput addInfo = new AdditionalInfoMultipleInput(iType, bMandatory); |
135 |
m_Parameter = new ParameterMultipleInput();
|
136 |
m_Parameter.setParameterAdditionalInfo(addInfo); |
137 |
m_Parameter.setParameterDescription(jTextFieldDescription.getText()); |
138 |
|
139 |
m_Parameter.setColorR(m_Color.getRed()); |
140 |
m_Parameter.setColorG(m_Color.getGreen()); |
141 |
m_Parameter.setColorB(m_Color.getBlue()); |
142 |
m_Parameter.setColorAlpha(m_Color.getAlpha()); |
143 |
|
144 |
return true; |
145 |
} |
146 |
else {
|
147 |
JOptionPane.showMessageDialog(null, Sextante.getText("Invalid_description"), Sextante.getText("Warning"), |
148 |
JOptionPane.WARNING_MESSAGE);
|
149 |
return false; |
150 |
} |
151 |
|
152 |
} |
153 |
|
154 |
|
155 |
@Override
|
156 |
public void setParameter(final Parameter param) { |
157 |
|
158 |
super.setParameter(param);
|
159 |
|
160 |
try {
|
161 |
final AdditionalInfoMultipleInput ai = (AdditionalInfoMultipleInput) param.getParameterAdditionalInfo();
|
162 |
jCheckBoxMandatory.setSelected(ai.getIsMandatory()); |
163 |
jComboBoxType.setSelectedIndex(0);
|
164 |
switch (ai.getDataType()) {
|
165 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_ANY:
|
166 |
jComboBoxType.setSelectedIndex(0);
|
167 |
break;
|
168 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POINT:
|
169 |
jComboBoxType.setSelectedIndex(1);
|
170 |
break;
|
171 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_LINE:
|
172 |
jComboBoxType.setSelectedIndex(2);
|
173 |
break;
|
174 |
case AdditionalInfoMultipleInput.DATA_TYPE_VECTOR_POLYGON:
|
175 |
jComboBoxType.setSelectedIndex(3);
|
176 |
break;
|
177 |
case AdditionalInfoMultipleInput.DATA_TYPE_RASTER:
|
178 |
jComboBoxType.setSelectedIndex(4);
|
179 |
break;
|
180 |
case AdditionalInfoMultipleInput.DATA_TYPE_BAND:
|
181 |
jComboBoxType.setSelectedIndex(5);
|
182 |
break;
|
183 |
case AdditionalInfoMultipleInput.DATA_TYPE_RASTER_3D:
|
184 |
jComboBoxType.setSelectedIndex(6);
|
185 |
break;
|
186 |
case AdditionalInfoMultipleInput.DATA_TYPE_TABLE:
|
187 |
jComboBoxType.setSelectedIndex(7);
|
188 |
break;
|
189 |
} |
190 |
|
191 |
} |
192 |
catch (final NullParameterAdditionalInfoException e) { |
193 |
e.printStackTrace(); |
194 |
} |
195 |
|
196 |
} |
197 |
|
198 |
|
199 |
@Override
|
200 |
public String getParameterDescription() { |
201 |
|
202 |
return Sextante.getText("Multiple_input"); |
203 |
|
204 |
} |
205 |
|
206 |
|
207 |
@Override
|
208 |
public boolean parameterCanBeAdded() { |
209 |
|
210 |
return true; |
211 |
|
212 |
} |
213 |
|
214 |
} |