root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / gui / GeoProcessingDissolvePanel2.java @ 6877
History | View | Annotate | Download (7.3 KB)
1 | 6749 | azabala | /*
|
---|---|---|---|
2 | * Created on 03-ago-2006
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | /* CVS MESSAGES:
|
||
45 | *
|
||
46 | * $Id$
|
||
47 | * $Log$
|
||
48 | * Revision 1.1 2006-08-11 16:28:25 azabala
|
||
49 | * *** empty log message ***
|
||
50 | *
|
||
51 | *
|
||
52 | */
|
||
53 | package com.iver.cit.gvsig.geoprocess.impl.dissolve.gui; |
||
54 | |||
55 | import java.awt.Dimension; |
||
56 | import java.awt.GridBagConstraints; |
||
57 | import java.awt.GridBagLayout; |
||
58 | import java.awt.Insets; |
||
59 | import java.awt.event.ActionEvent; |
||
60 | import java.awt.event.ActionListener; |
||
61 | import java.awt.event.ItemEvent; |
||
62 | import java.util.ArrayList; |
||
63 | import java.util.HashMap; |
||
64 | import java.util.Map; |
||
65 | import java.util.Set; |
||
66 | |||
67 | import javax.swing.DefaultComboBoxModel; |
||
68 | import javax.swing.JCheckBox; |
||
69 | import javax.swing.JComboBox; |
||
70 | import javax.swing.JLabel; |
||
71 | import javax.swing.JList; |
||
72 | import javax.swing.JPanel; |
||
73 | import javax.swing.JScrollPane; |
||
74 | |||
75 | import org.gvsig.gui.beans.swing.JButton; |
||
76 | |||
77 | import com.hardcode.gdbms.engine.data.DataSource; |
||
78 | import com.iver.andami.PluginServices; |
||
79 | import com.iver.cit.gvsig.fmap.DriverException; |
||
80 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
81 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
82 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
83 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
84 | import com.iver.cit.gvsig.geoprocess.core.fmap.SummarizationFunction; |
||
85 | import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
||
86 | import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessGridbagPanel; |
||
87 | import com.iver.cit.gvsig.geoprocess.core.gui.NumericFieldFunctionsControl; |
||
88 | import com.iver.cit.gvsig.geoprocess.core.gui.NumericFieldListModel; |
||
89 | import com.iver.cit.gvsig.geoprocess.core.gui.SumFuncListModel; |
||
90 | import com.iver.cit.gvsig.geoprocess.core.gui.SumarizeFunctionsDialog; |
||
91 | |||
92 | public class GeoProcessingDissolvePanel2 extends AbstractGeoprocessGridbagPanel |
||
93 | implements DissolvePanelIF {
|
||
94 | |||
95 | JComboBox dissolveFieldComboBox;
|
||
96 | |||
97 | JCheckBox dissolveAdjacentsCheck;
|
||
98 | |||
99 | JPanel sumarizationAttrsPanel;
|
||
100 | |||
101 | |||
102 | /**
|
||
103 | * Constructor
|
||
104 | *
|
||
105 | * @param layers
|
||
106 | */
|
||
107 | public GeoProcessingDissolvePanel2(FLayers layers) {
|
||
108 | super(layers, PluginServices.getText(null, |
||
109 | "Disolver._Introduccion_de_datos")
|
||
110 | + ":");
|
||
111 | } |
||
112 | |||
113 | protected void addSpecificDesign() { |
||
114 | // FIXME Si dejamos el insets a gusto del programador,
|
||
115 | // no saldra alineado con el inset de la clase abstracta
|
||
116 | // crear metodos especificos de geoprocessing que creen el Insets
|
||
117 | Insets insets = new Insets(5, 5, 5, 5); |
||
118 | |||
119 | String dissolveFieldText = PluginServices.getText(this, |
||
120 | "Campo_para_disolver")
|
||
121 | + ":";
|
||
122 | dissolveFieldComboBox = getDissolveFieldJComboBox(); |
||
123 | addComponent(dissolveFieldText, dissolveFieldComboBox, |
||
124 | GridBagConstraints.BOTH, insets);
|
||
125 | |||
126 | dissolveAdjacentsCheck = new JCheckBox(); |
||
127 | dissolveAdjacentsCheck.setText(PluginServices.getText(this,
|
||
128 | "Solo_disolver_adyacentes"));
|
||
129 | addComponent(dissolveAdjacentsCheck, GridBagConstraints.BOTH, insets);
|
||
130 | |||
131 | sumarizationAttrsPanel = getSumarizeAttributesPanel(); |
||
132 | addComponent(sumarizationAttrsPanel, GridBagConstraints.HORIZONTAL,
|
||
133 | insets); |
||
134 | |||
135 | initSelectedItemsJCheckBox(); |
||
136 | updateNumSelectedFeaturesLabel(); |
||
137 | |||
138 | inputLayerSelectedChange(); |
||
139 | |||
140 | } |
||
141 | |||
142 | public boolean onlyAdjacentSelected() { |
||
143 | return dissolveAdjacentsCheck.isSelected();
|
||
144 | } |
||
145 | |||
146 | public Map getFieldFunctionMap() { |
||
147 | return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
|
||
148 | getFieldFunctionMap(); |
||
149 | } |
||
150 | |||
151 | |||
152 | //TODO Llamar a NumericFieldFunctionControl
|
||
153 | public void openSumarizeFunction() { |
||
154 | ((NumericFieldFunctionsControl)sumarizationAttrsPanel).openSumarizeFunction(); |
||
155 | |||
156 | } |
||
157 | |||
158 | public boolean isDissolveOnlySelected() { |
||
159 | return super.isFirstOnlySelected(); |
||
160 | } |
||
161 | |||
162 | /**
|
||
163 | * Processes layer selection event in input layer combo box
|
||
164 | */
|
||
165 | public void inputLayerSelectedChange() { |
||
166 | processLayerComboBoxStateChange(null);
|
||
167 | } |
||
168 | |||
169 | protected void processLayerComboBoxStateChange(ItemEvent e) { |
||
170 | // Cambiar el estado del jComboBox1
|
||
171 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel( |
||
172 | getFieldNames()); |
||
173 | dissolveFieldComboBox.setModel(defaultModel); |
||
174 | ((NumericFieldFunctionsControl)sumarizationAttrsPanel). |
||
175 | setLayer(getInputLayer()); |
||
176 | |||
177 | } |
||
178 | |||
179 | public String getDissolveFieldName() { |
||
180 | return (String) dissolveFieldComboBox.getSelectedItem(); |
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | * Returns numeric fields' names of the selected input layer. Needed to say
|
||
185 | * user where he could apply sumarization functions.
|
||
186 | */
|
||
187 | public String[] getInputLayerNumericFields() { |
||
188 | String[] solution; |
||
189 | FLyrVect layer = getInputLayer(); |
||
190 | ArrayList list = new ArrayList(); |
||
191 | try {
|
||
192 | SelectableDataSource recordset = layer.getRecordset(); |
||
193 | int numFields = recordset.getFieldCount();
|
||
194 | for (int i = 0; i < numFields; i++) { |
||
195 | if (XTypes.isNumeric(recordset.getFieldType(i))) {
|
||
196 | list.add(recordset.getFieldName(i)); |
||
197 | } |
||
198 | }// for
|
||
199 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
200 | return null; |
||
201 | } catch (DriverException e) {
|
||
202 | return null; |
||
203 | } |
||
204 | solution = new String[list.size()]; |
||
205 | list.toArray(solution); |
||
206 | return solution;
|
||
207 | } |
||
208 | |||
209 | |||
210 | public String[] getFieldsToSummarize() { |
||
211 | return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
|
||
212 | getFieldsToSummarize(); |
||
213 | |||
214 | } |
||
215 | |||
216 | public SummarizationFunction[] getSumarizationFunctinFor( |
||
217 | String numericFieldName) {
|
||
218 | return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
|
||
219 | getSumarizationFunctinFor(numericFieldName); |
||
220 | } |
||
221 | |||
222 | private JComboBox getDissolveFieldJComboBox() { |
||
223 | if (dissolveFieldComboBox == null) { |
||
224 | dissolveFieldComboBox = new JComboBox(); |
||
225 | DefaultComboBoxModel defaultModel = new DefaultComboBoxModel( |
||
226 | getFieldNames()); |
||
227 | dissolveFieldComboBox.setModel(defaultModel); |
||
228 | } |
||
229 | return dissolveFieldComboBox;
|
||
230 | } |
||
231 | |||
232 | private String[] getFieldNames() { |
||
233 | AlphanumericData lyr = (AlphanumericData) getInputLayer(); |
||
234 | DataSource ds;
|
||
235 | String[] fieldNames = null; |
||
236 | try {
|
||
237 | ds = lyr.getRecordset(); |
||
238 | fieldNames = new String[ds.getFieldCount()]; |
||
239 | for (int i = 0; i < ds.getFieldCount(); i++) { |
||
240 | fieldNames[i] = ds.getFieldName(i); |
||
241 | } |
||
242 | } catch (DriverException e) {
|
||
243 | e.printStackTrace(); |
||
244 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
245 | e.printStackTrace(); |
||
246 | } |
||
247 | return fieldNames;
|
||
248 | } |
||
249 | |||
250 | private JPanel getSumarizeAttributesPanel() { |
||
251 | if (sumarizationAttrsPanel == null) { |
||
252 | |||
253 | sumarizationAttrsPanel = new NumericFieldFunctionsControl(getInputLayer());
|
||
254 | } |
||
255 | return sumarizationAttrsPanel;
|
||
256 | } |
||
257 | |||
258 | } |