svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / gui / GeoProcessingDissolvePanel2.java @ 7474
History | View | Annotate | Download (6.9 KB)
1 |
/*
|
---|---|
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: GeoProcessingDissolvePanel2.java 7474 2006-09-21 18:21:09Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2006-09-21 18:21:09 azabala
|
49 |
* fixed bug in sumarization function dialog
|
50 |
*
|
51 |
* Revision 1.1 2006/08/11 16:28:25 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.geoprocess.impl.dissolve.gui; |
57 |
|
58 |
import java.awt.GridBagConstraints; |
59 |
import java.awt.Insets; |
60 |
import java.awt.event.ItemEvent; |
61 |
import java.util.ArrayList; |
62 |
import java.util.Map; |
63 |
|
64 |
import javax.swing.DefaultComboBoxModel; |
65 |
import javax.swing.JCheckBox; |
66 |
import javax.swing.JComboBox; |
67 |
import javax.swing.JPanel; |
68 |
|
69 |
import com.hardcode.gdbms.engine.data.DataSource; |
70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.cit.gvsig.fmap.DriverException; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
73 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
74 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
75 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
76 |
import com.iver.cit.gvsig.geoprocess.core.fmap.SummarizationFunction; |
77 |
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
78 |
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessGridbagPanel; |
79 |
import com.iver.cit.gvsig.geoprocess.core.gui.NumericFieldFunctionsControl; |
80 |
|
81 |
public class GeoProcessingDissolvePanel2 extends AbstractGeoprocessGridbagPanel |
82 |
implements DissolvePanelIF {
|
83 |
|
84 |
JComboBox dissolveFieldComboBox;
|
85 |
|
86 |
JCheckBox dissolveAdjacentsCheck;
|
87 |
|
88 |
JPanel sumarizationAttrsPanel;
|
89 |
|
90 |
|
91 |
/**
|
92 |
* Constructor
|
93 |
*
|
94 |
* @param layers
|
95 |
*/
|
96 |
public GeoProcessingDissolvePanel2(FLayers layers) {
|
97 |
super(layers, PluginServices.getText(null, |
98 |
"Disolver._Introduccion_de_datos")
|
99 |
+ ":");
|
100 |
} |
101 |
|
102 |
protected void addSpecificDesign() { |
103 |
// FIXME Si dejamos el insets a gusto del programador,
|
104 |
// no saldra alineado con el inset de la clase abstracta
|
105 |
// crear metodos especificos de geoprocessing que creen el Insets
|
106 |
Insets insets = new Insets(5, 5, 5, 5); |
107 |
|
108 |
String dissolveFieldText = PluginServices.getText(this, |
109 |
"Campo_para_disolver")
|
110 |
+ ":";
|
111 |
dissolveFieldComboBox = getDissolveFieldJComboBox(); |
112 |
addComponent(dissolveFieldText, dissolveFieldComboBox, |
113 |
GridBagConstraints.BOTH, insets);
|
114 |
|
115 |
dissolveAdjacentsCheck = new JCheckBox(); |
116 |
dissolveAdjacentsCheck.setText(PluginServices.getText(this,
|
117 |
"Solo_disolver_adyacentes"));
|
118 |
addComponent(dissolveAdjacentsCheck, GridBagConstraints.BOTH, insets);
|
119 |
|
120 |
sumarizationAttrsPanel = getSumarizeAttributesPanel(); |
121 |
addComponent(sumarizationAttrsPanel, GridBagConstraints.HORIZONTAL,
|
122 |
insets); |
123 |
|
124 |
initSelectedItemsJCheckBox(); |
125 |
updateNumSelectedFeaturesLabel(); |
126 |
|
127 |
inputLayerSelectedChange(); |
128 |
|
129 |
} |
130 |
|
131 |
public boolean onlyAdjacentSelected() { |
132 |
return dissolveAdjacentsCheck.isSelected();
|
133 |
} |
134 |
|
135 |
public Map getFieldFunctionMap() { |
136 |
return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
|
137 |
getFieldFunctionMap(); |
138 |
} |
139 |
|
140 |
|
141 |
//TODO Llamar a NumericFieldFunctionControl
|
142 |
public void openSumarizeFunction() { |
143 |
((NumericFieldFunctionsControl)sumarizationAttrsPanel).openSumarizeFunction(); |
144 |
|
145 |
} |
146 |
|
147 |
public boolean isDissolveOnlySelected() { |
148 |
return super.isFirstOnlySelected(); |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Processes layer selection event in input layer combo box
|
153 |
*/
|
154 |
public void inputLayerSelectedChange() { |
155 |
processLayerComboBoxStateChange(null);
|
156 |
} |
157 |
|
158 |
protected void processLayerComboBoxStateChange(ItemEvent e) { |
159 |
// Cambiar el estado del jComboBox1
|
160 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel( |
161 |
getFieldNames()); |
162 |
dissolveFieldComboBox.setModel(defaultModel); |
163 |
((NumericFieldFunctionsControl)sumarizationAttrsPanel). |
164 |
setLayer(getInputLayer()); |
165 |
|
166 |
} |
167 |
|
168 |
public String getDissolveFieldName() { |
169 |
return (String) dissolveFieldComboBox.getSelectedItem(); |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Returns numeric fields' names of the selected input layer. Needed to say
|
174 |
* user where he could apply sumarization functions.
|
175 |
*/
|
176 |
public String[] getInputLayerNumericFields() { |
177 |
String[] solution; |
178 |
FLyrVect layer = getInputLayer(); |
179 |
ArrayList list = new ArrayList(); |
180 |
try {
|
181 |
SelectableDataSource recordset = layer.getRecordset(); |
182 |
int numFields = recordset.getFieldCount();
|
183 |
for (int i = 0; i < numFields; i++) { |
184 |
if (XTypes.isNumeric(recordset.getFieldType(i))) {
|
185 |
list.add(recordset.getFieldName(i)); |
186 |
} |
187 |
}// for
|
188 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
189 |
return null; |
190 |
} catch (DriverException e) {
|
191 |
return null; |
192 |
} |
193 |
solution = new String[list.size()]; |
194 |
list.toArray(solution); |
195 |
return solution;
|
196 |
} |
197 |
|
198 |
|
199 |
public String[] getFieldsToSummarize() { |
200 |
return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
|
201 |
getFieldsToSummarize(); |
202 |
|
203 |
} |
204 |
|
205 |
public SummarizationFunction[] getSumarizationFunctinFor( |
206 |
String numericFieldName) {
|
207 |
return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
|
208 |
getSumarizationFunctinFor(numericFieldName); |
209 |
} |
210 |
|
211 |
private JComboBox getDissolveFieldJComboBox() { |
212 |
if (dissolveFieldComboBox == null) { |
213 |
dissolveFieldComboBox = new JComboBox(); |
214 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel( |
215 |
getFieldNames()); |
216 |
dissolveFieldComboBox.setModel(defaultModel); |
217 |
} |
218 |
return dissolveFieldComboBox;
|
219 |
} |
220 |
|
221 |
private String[] getFieldNames() { |
222 |
AlphanumericData lyr = (AlphanumericData) getInputLayer(); |
223 |
DataSource ds;
|
224 |
String[] fieldNames = null; |
225 |
try {
|
226 |
ds = lyr.getRecordset(); |
227 |
fieldNames = new String[ds.getFieldCount()]; |
228 |
for (int i = 0; i < ds.getFieldCount(); i++) { |
229 |
fieldNames[i] = ds.getFieldName(i); |
230 |
} |
231 |
} catch (DriverException e) {
|
232 |
e.printStackTrace(); |
233 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
234 |
e.printStackTrace(); |
235 |
} |
236 |
return fieldNames;
|
237 |
} |
238 |
|
239 |
private JPanel getSumarizeAttributesPanel() { |
240 |
if (sumarizationAttrsPanel == null) { |
241 |
|
242 |
sumarizationAttrsPanel = new NumericFieldFunctionsControl(getInputLayer());
|
243 |
} |
244 |
return sumarizationAttrsPanel;
|
245 |
} |
246 |
|
247 |
} |