svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / NumericFieldFunctionsControl.java @ 10626
History | View | Annotate | Download (9.05 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-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: NumericFieldFunctionsControl.java 10626 2007-03-06 16:55:54Z caballero $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2007-03-06 16:47:58 caballero
|
49 |
* Exceptions
|
50 |
*
|
51 |
* Revision 1.1 2006/08/11 16:11:38 azabala
|
52 |
* first version in cvs
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.geoprocess.core.gui; |
57 |
|
58 |
import java.awt.Dimension; |
59 |
import java.awt.GridBagConstraints; |
60 |
import java.awt.GridBagLayout; |
61 |
import java.awt.event.ActionEvent; |
62 |
import java.awt.event.ActionListener; |
63 |
import java.util.ArrayList; |
64 |
import java.util.HashMap; |
65 |
import java.util.Map; |
66 |
import java.util.Set; |
67 |
|
68 |
import javax.swing.BorderFactory; |
69 |
import javax.swing.JLabel; |
70 |
import javax.swing.JList; |
71 |
import javax.swing.JPanel; |
72 |
import javax.swing.JScrollPane; |
73 |
import javax.swing.ListSelectionModel; |
74 |
import javax.swing.border.EtchedBorder; |
75 |
|
76 |
import org.gvsig.gui.beans.swing.JButton; |
77 |
|
78 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
79 |
import com.iver.andami.PluginServices; |
80 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
81 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
82 |
import com.iver.cit.gvsig.geoprocess.core.fmap.SummarizationFunction; |
83 |
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes; |
84 |
import com.iver.cit.gvsig.geoprocess.core.gui.NumericFieldListModel.NumericFieldListEntry; |
85 |
|
86 |
/**
|
87 |
* Control to select sumarization functions for a given
|
88 |
* numeric field of a layer
|
89 |
* @author azabala
|
90 |
*
|
91 |
*/
|
92 |
public class NumericFieldFunctionsControl extends JPanel { |
93 |
|
94 |
private FLyrVect inputLayer;
|
95 |
|
96 |
|
97 |
private JList numericFieldList; |
98 |
private JList sumarizeFunctionsList; |
99 |
private SumarizeFunctionsDialog sumarizeFuncDialog;
|
100 |
private Map nField_sumFuntionList; |
101 |
|
102 |
|
103 |
|
104 |
public NumericFieldFunctionsControl(FLyrVect inputLayer){
|
105 |
super();
|
106 |
initialize(); |
107 |
setLayer(inputLayer); |
108 |
} |
109 |
|
110 |
|
111 |
|
112 |
public void initialize(){ |
113 |
setLayout(new GridBagLayout()); |
114 |
setBorder(BorderFactory.
|
115 |
createEtchedBorder(EtchedBorder.RAISED));
|
116 |
|
117 |
GridBagConstraints buttonConstraints =
|
118 |
new GridBagConstraints(); |
119 |
buttonConstraints.gridy = 1;
|
120 |
buttonConstraints.gridx = 1;
|
121 |
buttonConstraints.ipadx = 4;
|
122 |
buttonConstraints.ipady = 2;
|
123 |
buttonConstraints.weightx = 1f;
|
124 |
buttonConstraints.fill = GridBagConstraints.NONE;
|
125 |
|
126 |
GridBagConstraints attrsLabelConstraints = new GridBagConstraints(); |
127 |
attrsLabelConstraints.insets = new java.awt.Insets(7, 11, 4, 106); |
128 |
attrsLabelConstraints.gridx = 0;
|
129 |
attrsLabelConstraints.gridy = 0;
|
130 |
attrsLabelConstraints.ipadx = 50;
|
131 |
attrsLabelConstraints.ipady = 2;
|
132 |
attrsLabelConstraints.gridwidth = 2;
|
133 |
|
134 |
GridBagConstraints functionsLabelConstraints = new GridBagConstraints(); |
135 |
functionsLabelConstraints.insets = new java.awt.Insets(7, 4, 4, 10); |
136 |
functionsLabelConstraints.gridy = 0;
|
137 |
functionsLabelConstraints.ipadx = 50;
|
138 |
functionsLabelConstraints.ipady = 2;
|
139 |
functionsLabelConstraints.gridx = 2;
|
140 |
|
141 |
GridBagConstraints functionScrollConstraints = new GridBagConstraints(); |
142 |
functionScrollConstraints.fill = java.awt.GridBagConstraints.BOTH; |
143 |
functionScrollConstraints.gridx = 2;
|
144 |
functionScrollConstraints.gridy = 1;
|
145 |
functionScrollConstraints.ipadx = 120;
|
146 |
functionScrollConstraints.ipady = 19;
|
147 |
functionScrollConstraints.weightx = 0.75;
|
148 |
functionScrollConstraints.weighty = 1.0;
|
149 |
functionScrollConstraints.insets = new java.awt.Insets(5, 24, 1, 10); |
150 |
|
151 |
GridBagConstraints numericAttrScrollConstraints = new GridBagConstraints(); |
152 |
numericAttrScrollConstraints.fill = java.awt.GridBagConstraints.BOTH; |
153 |
numericAttrScrollConstraints.gridx = 0;
|
154 |
numericAttrScrollConstraints.gridy = 1;
|
155 |
numericAttrScrollConstraints.ipadx = 120;
|
156 |
numericAttrScrollConstraints.ipady = 19;
|
157 |
numericAttrScrollConstraints.weightx = 0.75;
|
158 |
numericAttrScrollConstraints.weighty = 1.0;
|
159 |
numericAttrScrollConstraints.insets = new java.awt.Insets(5, 12, 1, |
160 |
9);
|
161 |
|
162 |
JScrollPane numericAttrsScrollPane = new JScrollPane(); |
163 |
numericFieldList = new JList(); |
164 |
numericFieldList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
165 |
numericAttrsScrollPane.setViewportView(numericFieldList); |
166 |
numericAttrsScrollPane.setEnabled(false);
|
167 |
numericAttrsScrollPane.setPreferredSize(new Dimension(150, 150)); |
168 |
numericAttrsScrollPane.setMinimumSize(new Dimension(100, 100)); |
169 |
add(numericAttrsScrollPane, |
170 |
numericAttrScrollConstraints); |
171 |
|
172 |
JScrollPane sumarizationFunctionScrollPane = new JScrollPane(); |
173 |
sumarizeFunctionsList = new JList(); |
174 |
sumarizeFunctionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
175 |
|
176 |
sumarizationFunctionScrollPane |
177 |
.setViewportView(sumarizeFunctionsList); |
178 |
sumarizationFunctionScrollPane.setPreferredSize(new Dimension(150, |
179 |
150));
|
180 |
sumarizationFunctionScrollPane.setMinimumSize(new Dimension(100, |
181 |
100));
|
182 |
add(sumarizationFunctionScrollPane, |
183 |
functionScrollConstraints); |
184 |
|
185 |
JLabel functionsLabel = new JLabel(PluginServices.getText(this, |
186 |
"Funciones_Sumarizacion"));
|
187 |
add(functionsLabel, |
188 |
functionsLabelConstraints); |
189 |
|
190 |
JLabel attrsLabel = new JLabel(PluginServices.getText(this, |
191 |
"Atributos_Numericos"));
|
192 |
|
193 |
add(attrsLabel, attrsLabelConstraints); |
194 |
|
195 |
JButton sumFunctionSelectionJButton = new JButton(); |
196 |
sumFunctionSelectionJButton.setText(PluginServices.getText(this,
|
197 |
"Escoger_Fun_Resumen"));
|
198 |
sumFunctionSelectionJButton.addActionListener(new ActionListener() { |
199 |
public void actionPerformed(ActionEvent arg0) { |
200 |
openSumarizeFunction(); |
201 |
} |
202 |
}); |
203 |
add(sumFunctionSelectionJButton, |
204 |
buttonConstraints); |
205 |
|
206 |
} |
207 |
|
208 |
public void openSumarizeFunction() { |
209 |
if (sumarizeFuncDialog == null) { |
210 |
sumarizeFuncDialog = new SumarizeFunctionsDialog();
|
211 |
sumarizeFuncDialog.pack(); |
212 |
} |
213 |
sumarizeFuncDialog.setSize(205, 181); |
214 |
sumarizeFuncDialog.resetCheckbox(); |
215 |
sumarizeFuncDialog.setVisible(true);
|
216 |
SummarizationFunction[] functions = sumarizeFuncDialog.getFunctions();
|
217 |
|
218 |
NumericFieldListEntry fieldName = (NumericFieldListEntry) numericFieldList.getSelectedValue(); |
219 |
// if it returns "", there arent any fields (disable button if list is empty??)
|
220 |
if(fieldName.getKey() != null ){ |
221 |
if(!fieldName.getKey().equals("")) |
222 |
nField_sumFuntionList.put(fieldName.getKey(), functions); |
223 |
} |
224 |
// refresh list and listModel
|
225 |
String[] numericFields = getInputLayerNumericFields(); |
226 |
SumFuncListModel functionListModel = new SumFuncListModel(
|
227 |
nField_sumFuntionList, numericFields); |
228 |
sumarizeFunctionsList.setModel(functionListModel); |
229 |
this.sumarizeFunctionsList.setSelectedIndex(0); |
230 |
} |
231 |
|
232 |
public Map getFieldFunctionMap() { |
233 |
return this.nField_sumFuntionList; |
234 |
} |
235 |
|
236 |
public String[] getFieldsToSummarize() { |
237 |
String[] solution = null; |
238 |
Set keySet = nField_sumFuntionList.keySet();
|
239 |
solution = new String[keySet.size()]; |
240 |
keySet.toArray(solution); |
241 |
return solution;
|
242 |
} |
243 |
|
244 |
public SummarizationFunction[] getSumarizationFunctinFor( |
245 |
String numericFieldName) {
|
246 |
return (SummarizationFunction[]) nField_sumFuntionList |
247 |
.get(numericFieldName); |
248 |
} |
249 |
|
250 |
public void setLayer(FLyrVect inputLayer){ |
251 |
this.inputLayer = inputLayer;
|
252 |
String[] numericFields = getInputLayerNumericFields(); |
253 |
NumericFieldListModel numericListModel = new NumericFieldListModel(
|
254 |
numericFields); |
255 |
this.numericFieldList.setModel(numericListModel);
|
256 |
this.numericFieldList.setSelectedIndex(0); |
257 |
|
258 |
this.nField_sumFuntionList = new HashMap(); |
259 |
SumFuncListModel functionListModel = new SumFuncListModel(
|
260 |
this.nField_sumFuntionList, numericFields);
|
261 |
sumarizeFunctionsList.setModel(functionListModel); |
262 |
sumarizeFunctionsList.setSelectedIndex(0);
|
263 |
} |
264 |
|
265 |
/**
|
266 |
* Returns numeric fields' names of the selected input layer. Needed to say
|
267 |
* user where he could apply sumarization functions.
|
268 |
*/
|
269 |
public String[] getInputLayerNumericFields() { |
270 |
String[] solution = null; |
271 |
if(inputLayer == null) |
272 |
return null; |
273 |
ArrayList list = new ArrayList(); |
274 |
try {
|
275 |
SelectableDataSource recordset = inputLayer.getRecordset(); |
276 |
int numFields = recordset.getFieldCount();
|
277 |
for (int i = 0; i < numFields; i++) { |
278 |
if (XTypes.isNumeric(recordset.getFieldType(i))) {
|
279 |
list.add(recordset.getFieldName(i)); |
280 |
} |
281 |
}// for
|
282 |
} catch (ReadDriverException e) {
|
283 |
return null; |
284 |
} |
285 |
solution = new String[list.size()]; |
286 |
list.toArray(solution); |
287 |
return solution;
|
288 |
} |
289 |
|
290 |
} |
291 |
|