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