root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / dissolve / DissolveParametersPanel.java @ 59
History | View | Annotate | Download (7.7 KB)
1 |
package es.unex.sextante.vectorTools.dissolve; |
---|---|
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.JComboBox; |
9 |
import javax.swing.JLabel; |
10 |
import javax.swing.JScrollPane; |
11 |
import javax.swing.JTable; |
12 |
import javax.swing.ScrollPaneConstants; |
13 |
|
14 |
import es.unex.sextante.core.GeoAlgorithm; |
15 |
import es.unex.sextante.core.ObjectAndDescription; |
16 |
import es.unex.sextante.core.OutputObjectsSet; |
17 |
import es.unex.sextante.core.ParametersSet; |
18 |
import es.unex.sextante.core.Sextante; |
19 |
import es.unex.sextante.dataObjects.IVectorLayer; |
20 |
import es.unex.sextante.exceptions.WrongInputException; |
21 |
import es.unex.sextante.exceptions.WrongParameterIDException; |
22 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
23 |
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel; |
24 |
import es.unex.sextante.gui.core.SextanteGUI; |
25 |
import es.unex.sextante.gui.exceptions.LayerCannotBeOverwrittenException; |
26 |
import es.unex.sextante.outputs.IOutputChannel; |
27 |
import es.unex.sextante.outputs.Output; |
28 |
import es.unex.sextante.outputs.OverwriteOutputChannel; |
29 |
|
30 |
public class DissolveParametersPanel |
31 |
extends
|
32 |
GeoAlgorithmParametersPanel { |
33 |
|
34 |
private GeoAlgorithm m_Algorithm;
|
35 |
private JLabel jLabelGroupings; |
36 |
private JComboBox jComboBoxField; |
37 |
private JTable jTableGroupings; |
38 |
private JComboBox jComboBoxLayers; |
39 |
private JLabel jLabelField; |
40 |
private JLabel jLabelLayer; |
41 |
private JScrollPane jScrollPaneFields; |
42 |
private OutputChannelSelectionPanel outputChannelSelectionPanel;
|
43 |
|
44 |
|
45 |
public DissolveParametersPanel() {
|
46 |
|
47 |
super();
|
48 |
|
49 |
} |
50 |
|
51 |
|
52 |
@Override
|
53 |
public void init(final GeoAlgorithm algorithm) { |
54 |
|
55 |
m_Algorithm = algorithm; |
56 |
|
57 |
initGUI(); |
58 |
|
59 |
} |
60 |
|
61 |
|
62 |
@Override
|
63 |
public void assignParameters() throws WrongInputException, LayerCannotBeOverwrittenException { |
64 |
|
65 |
final ObjectAndDescription oad = (ObjectAndDescription) jComboBoxLayers.getSelectedItem();
|
66 |
final IVectorLayer layer = (IVectorLayer) oad.getObject();
|
67 |
final ParametersSet params = m_Algorithm.getParameters();
|
68 |
try {
|
69 |
params.getParameter(DissolveAlgorithm.LAYER).setParameterValue(layer); |
70 |
params.getParameter(DissolveAlgorithm.GROUPING_FIELD).setParameterValue(jComboBoxField.getSelectedIndex()); |
71 |
final DissolveTableModel model = (DissolveTableModel) jTableGroupings.getModel();
|
72 |
params.getParameter(DissolveAlgorithm.GROUPING_FUNCTIONS).setParameterValue(model.getAsString()); |
73 |
} |
74 |
catch (final WrongParameterIDException e) { |
75 |
throw new WrongInputException(); |
76 |
} |
77 |
|
78 |
|
79 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
80 |
Output out; |
81 |
IOutputChannel channel; |
82 |
try {
|
83 |
out = ooSet.getOutput(DissolveAlgorithm.RESULT); |
84 |
channel = outputChannelSelectionPanel.getOutputChannel(); |
85 |
} |
86 |
catch (final Exception e) { |
87 |
throw new WrongInputException(); |
88 |
} |
89 |
|
90 |
if (channel instanceof OverwriteOutputChannel) { |
91 |
final OverwriteOutputChannel ooc = (OverwriteOutputChannel) channel;
|
92 |
if (!ooc.getLayer().canBeEdited()) {
|
93 |
throw new LayerCannotBeOverwrittenException(); |
94 |
} |
95 |
} |
96 |
|
97 |
out.setOutputChannel(channel); |
98 |
|
99 |
|
100 |
} |
101 |
|
102 |
|
103 |
private void initGUI() { |
104 |
try {
|
105 |
{ |
106 |
final TableLayout thisLayout = new TableLayout(new double[][] { |
107 |
{ 5.0, TableLayoutConstants.FILL, TableLayoutConstants.FILL, 5.0 }, |
108 |
{ 5.0, 25.0, 5.0, 25.0, 5.0, 25.0, TableLayoutConstants.FILL, 5.0, 20.0, 5.0 } }); |
109 |
thisLayout.setHGap(5);
|
110 |
thisLayout.setVGap(5);
|
111 |
this.setLayout(thisLayout);
|
112 |
this.setPreferredSize(new java.awt.Dimension(469, 257)); |
113 |
{ |
114 |
jLabelGroupings = new JLabel(); |
115 |
this.add(jLabelGroupings, "1, 5"); |
116 |
jLabelGroupings.setText(Sextante.getText("Summary_statistics"));
|
117 |
} |
118 |
{ |
119 |
jScrollPaneFields = new JScrollPane(); |
120 |
jScrollPaneFields.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
121 |
this.add(jScrollPaneFields, "1, 6, 2, 6"); |
122 |
{ |
123 |
jTableGroupings = new JTable(); |
124 |
jScrollPaneFields.setViewportView(jTableGroupings); |
125 |
} |
126 |
} |
127 |
{ |
128 |
jLabelLayer = new JLabel(); |
129 |
this.add(jLabelLayer, "1, 1"); |
130 |
jLabelLayer.setText(Sextante.getText("Layer"));
|
131 |
} |
132 |
{ |
133 |
jLabelField = new JLabel(); |
134 |
this.add(jLabelField, "1, 3"); |
135 |
jLabelField.setText(Sextante.getText("Field"));
|
136 |
} |
137 |
{ |
138 |
jComboBoxField = new JComboBox(); |
139 |
this.add(jComboBoxField, "2, 3"); |
140 |
} |
141 |
{ |
142 |
final ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel(getLayers()); |
143 |
jComboBoxLayers = new JComboBox(); |
144 |
this.add(jComboBoxLayers, "2, 1"); |
145 |
jComboBoxLayers.setModel(jComboBoxLayersModel); |
146 |
jComboBoxLayers.addItemListener(new java.awt.event.ItemListener() {
|
147 |
public void itemStateChanged(final java.awt.event.ItemEvent e) { |
148 |
setFields(); |
149 |
setTableModel(); |
150 |
} |
151 |
}); |
152 |
jComboBoxLayers.setSelectedIndex(0);
|
153 |
setFields(); |
154 |
setTableModel(); |
155 |
} |
156 |
{ |
157 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
158 |
final Output out = ooSet.getOutput(DissolveAlgorithm.RESULT);
|
159 |
outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
|
160 |
this.add(outputChannelSelectionPanel, "2,8"); |
161 |
this.add(new JLabel(Sextante.getText("Result")), "1,8"); |
162 |
} |
163 |
} |
164 |
} |
165 |
catch (final Exception e) { |
166 |
Sextante.addErrorToLog(e); |
167 |
} |
168 |
} |
169 |
|
170 |
|
171 |
protected void setFields() { |
172 |
|
173 |
final ComboBoxModel jComboBoxFieldModel = new DefaultComboBoxModel(getFields()); |
174 |
jComboBoxField.setModel(jComboBoxFieldModel); |
175 |
|
176 |
} |
177 |
|
178 |
|
179 |
private void setTableModel() { |
180 |
|
181 |
final ObjectAndDescription oad = (ObjectAndDescription) jComboBoxLayers.getSelectedItem();
|
182 |
final IVectorLayer layer = (IVectorLayer) oad.getObject();
|
183 |
final DissolveTableModel tableModel = new DissolveTableModel(layer); |
184 |
jTableGroupings.setModel(tableModel); |
185 |
|
186 |
} |
187 |
|
188 |
|
189 |
private String[] getFields() { |
190 |
|
191 |
final ObjectAndDescription oad = (ObjectAndDescription) jComboBoxLayers.getSelectedItem();
|
192 |
final IVectorLayer layer = (IVectorLayer) oad.getObject();
|
193 |
return getFields(layer);
|
194 |
|
195 |
} |
196 |
|
197 |
|
198 |
private String[] getFields(final IVectorLayer layer) { |
199 |
|
200 |
return layer.getFieldNames();
|
201 |
|
202 |
} |
203 |
|
204 |
|
205 |
private ObjectAndDescription[] getLayers() { |
206 |
|
207 |
final IVectorLayer[] layers = SextanteGUI.getInputFactory().getVectorLayers(IVectorLayer.SHAPE_TYPE_POLYGON); |
208 |
final ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
209 |
for (int i = 0; i < layers.length; i++) { |
210 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
211 |
} |
212 |
return oad;
|
213 |
|
214 |
} |
215 |
|
216 |
|
217 |
@Override
|
218 |
public void setOutputValue(final String sOutputName, |
219 |
final String sValue) { |
220 |
|
221 |
outputChannelSelectionPanel.setText(sValue); |
222 |
|
223 |
} |
224 |
|
225 |
|
226 |
@Override
|
227 |
public void setParameterValue(final String parameterName, |
228 |
final String value) { |
229 |
// TODO Auto-generated method stub
|
230 |
|
231 |
} |
232 |
|
233 |
} |