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