Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1010 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / gui / GeoProcessingDissolvePanel2.java @ 12804

History | View | Annotate | Download (6.98 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 8765 2006-11-15 00:08:29Z jjdelcerro $
47
 * $Log$
48
 * Revision 1.1.2.2  2006-11-15 00:08:17  jjdelcerro
49
 * *** empty log message ***
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.engine.data.DataSource;
73
import com.iver.andami.PluginServices;
74
import com.iver.cit.gvsig.fmap.DriverException;
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 (com.hardcode.gdbms.engine.data.driver.DriverException e) {
192
                        return null;
193
                } catch (DriverException e) {
194
                        return null;
195
                }
196
                solution = new String[list.size()];
197
                list.toArray(solution);
198
                return solution;
199
        }
200
        
201

    
202
        public String[] getFieldsToSummarize() {
203
                return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
204
                                                                                getFieldsToSummarize();
205
                
206
        }
207

    
208
        public SummarizationFunction[] getSumarizationFunctinFor(
209
                        String numericFieldName) {
210
                return ((NumericFieldFunctionsControl)sumarizationAttrsPanel).
211
                                        getSumarizationFunctinFor(numericFieldName);
212
        }
213

    
214
        private JComboBox getDissolveFieldJComboBox() {
215
                if (dissolveFieldComboBox == null) {
216
                        dissolveFieldComboBox = new JComboBox();
217
                        DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(
218
                                        getFieldNames());
219
                        dissolveFieldComboBox.setModel(defaultModel);
220
                }
221
                return dissolveFieldComboBox;
222
        }
223

    
224
        private String[] getFieldNames() {
225
                AlphanumericData lyr = (AlphanumericData) getInputLayer();
226
                DataSource ds;
227
                String[] fieldNames = null;
228
                try {
229
                        ds = lyr.getRecordset();
230
                        fieldNames = new String[ds.getFieldCount()];
231
                        for (int i = 0; i < ds.getFieldCount(); i++) {
232
                                fieldNames[i] = ds.getFieldName(i);
233
                        }
234
                } catch (DriverException e) {
235
                        e.printStackTrace();
236
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
237
                        e.printStackTrace();
238
                }
239
                return fieldNames;
240
        }
241

    
242
        private JPanel getSumarizeAttributesPanel() {
243
                if (sumarizationAttrsPanel == null) {
244
                        
245
                        sumarizationAttrsPanel = new NumericFieldFunctionsControl(getInputLayer());
246
                }
247
                return sumarizationAttrsPanel;
248
        }
249

    
250
}