Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1009 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / GeoProcessingOverlayPanel2.java @ 12649

History | View | Annotate | Download (7.49 KB)

1
/*
2
 * Created on 01-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: GeoProcessingOverlayPanel2.java 12649 2007-07-17 12:20:01Z  $
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.Color;
56
import java.awt.GridBagConstraints;
57
import java.awt.Insets;
58
import java.awt.event.ItemEvent;
59
import java.awt.event.ItemListener;
60

    
61
import javax.swing.ButtonGroup;
62
import javax.swing.DefaultComboBoxModel;
63
import javax.swing.JCheckBox;
64
import javax.swing.JComboBox;
65
import javax.swing.JFormattedTextField;
66
import javax.swing.JLabel;
67
import javax.swing.JRadioButton;
68
import javax.swing.JSpinner;
69
import javax.swing.JTextField;
70
import javax.swing.SpinnerListModel;
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.drivers.DriverIOException;
76
import com.iver.cit.gvsig.fmap.layers.FBitSet;
77
import com.iver.cit.gvsig.fmap.layers.FLayers;
78
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
79
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
80
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
81
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
82
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
83
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
84
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
85

    
86
public class GeoProcessingOverlayPanel2 extends AbstractGeoprocessGridbagPanel
87
                implements OverlayPanelIF {
88

    
89
        private JComboBox secondLayerComboBox;
90

    
91
        private JCheckBox secondLayerSelectedCheckBox;
92

    
93
        private JLabel secondLayerNumSelectedLabel;
94

    
95
        /**
96
         * Constructor.
97
         * 
98
         */
99
        public GeoProcessingOverlayPanel2(FLayers layers, String titleText) {
100
                super(layers, titleText);
101
        }
102

    
103
        protected void addSpecificDesign() {
104
                Insets insets = new Insets(5, 5, 5, 5);
105
                String secondLayerText = PluginServices.getText(this,
106
                                "Cobertura_de_recorte")
107
                                + ":";
108
                secondLayerComboBox = getSecondLayerComboBox();
109
                addComponent(secondLayerText, 
110
                                        secondLayerComboBox, 
111
                                        GridBagConstraints.BOTH,
112
                                                insets);
113
                
114
                secondLayerSelectedCheckBox = new JCheckBox();        
115
                secondLayerSelectedCheckBox.addItemListener(new ItemListener(){
116
                        public void itemStateChanged(ItemEvent arg0) {
117
                                updateNumSelectedSecondLabel();
118
                        }});
119
                secondLayerSelectedCheckBox.setText(PluginServices.
120
                                getText(this, "Usar_solamente_los_elementos_seleccionados"));
121
                addComponent(secondLayerSelectedCheckBox, 
122
                                GridBagConstraints.BOTH, 
123
                                insets);
124

    
125
                String secondLayerNumSelectedText = 
126
                        PluginServices.getText(this,
127
                                "Numero_de_elementos_seleccionados")
128
                                + ":";
129
                secondLayerNumSelectedLabel = new JLabel("00");
130
                addComponent(secondLayerNumSelectedText, 
131
                                        secondLayerNumSelectedLabel, 
132
                                                insets);
133

    
134
                initSelectedItemsJCheckBox();
135
                updateNumSelectedFeaturesLabel();
136
                initSelectedItems2JCheckBox();
137
                updateNumSelectedSecondLabel();
138
        }
139

    
140
        protected JComboBox getSecondLayerComboBox() {
141
                JComboBox solution = new JComboBox();
142
                DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(
143
                                getLayerNames());
144
                solution.setModel(defaultModel);
145
                solution.addItemListener(new java.awt.event.ItemListener() {
146
                        public void itemStateChanged(ItemEvent e) {
147
                                if (e.getStateChange() == ItemEvent.SELECTED) {
148
                                        initSelectedItems2JCheckBox();
149
                                        updateNumSelectedSecondLabel();
150
                                        processLayer2ComboBoxStateChange(e);
151
                                }
152
                        }// itemStateChange
153
                });
154
                return solution;
155
        }
156
        
157
        
158
        protected void initSelectedItems2JCheckBox(){
159
                String selectedLayer = 
160
                        (String) secondLayerComboBox.getSelectedItem();
161
                FLyrVect overlayLayer = 
162
                        (FLyrVect) layers.getLayer(selectedLayer);
163
                FBitSet fBitSet = null;
164
                try {
165
                        fBitSet = overlayLayer.getRecordset().getSelection();
166
                } catch (DriverException e) {
167
                        // TODO Auto-generated catch block
168
                        e.printStackTrace();
169
                }
170
                
171
                if (fBitSet.cardinality() == 0) {
172
                        secondLayerSelectedCheckBox.setEnabled(false);
173
                        secondLayerSelectedCheckBox.setSelected(false);
174
                } else {
175
                        secondLayerSelectedCheckBox.setEnabled(true);
176
                        secondLayerSelectedCheckBox.setSelected(true);
177
                }
178
                secondLayerSelectedCheckBox.setSelected(false);
179
        }
180

    
181
        /**
182
         * updates the label's text with the number of features
183
         * to operate with in the second layer
184
         *
185
         */
186
        protected void updateNumSelectedSecondLabel() {
187
                if (secondLayerSelectedCheckBox.isSelected()) {
188
                        FLyrVect inputSelectable = 
189
                                (FLyrVect) (layers.getLayer(
190
                                                (String) secondLayerComboBox.
191
                                                getSelectedItem()));
192
                        FBitSet fBitSet = null;
193
                        try {
194
                                fBitSet = inputSelectable.
195
                                                        getRecordset().
196
                                                        getSelection();
197
                        } catch (DriverException e) {
198
                                // TODO Auto-generated catch block
199
                                e.printStackTrace();
200
                        }
201
                        secondLayerNumSelectedLabel.
202
                                setText(new Integer(fBitSet.
203
                                                        cardinality()).
204
                                                        toString());
205
                } else {
206
                        ReadableVectorial va = 
207
                                ((SingleLayer) (layers.getLayer(
208
                                                (String) secondLayerComboBox.
209
                                                getSelectedItem()))).getSource();
210
                        try {
211
                                secondLayerNumSelectedLabel.setText(new Integer(va
212
                                                .getShapeCount()).toString());
213
                        } catch (DriverIOException e) {
214
                                // TODO Auto-generated catch block
215
                                e.printStackTrace();
216
                        }
217
                }//else
218
        }
219

    
220
        
221
        //cambiar esto para que lo implemente la clase padre,
222
        //y que las hijas simplemente sobreescriban y llamen a super()
223
        /**
224
         * Processess events selection in first layer combo box
225
         * (adding additional logic to abstract base class
226
         */
227
        protected void processLayerComboBoxStateChange(ItemEvent e) {
228
        }
229
        
230
        /**
231
         * Subclasses those want to overwrite logic of this component
232
         * must overwrites this method
233
         * @param e
234
         */
235
        protected void processLayer2ComboBoxStateChange(ItemEvent e) {
236
        }
237
        
238
        
239
        public FLyrVect getSecondLayer() {
240
                String clippingLayer = 
241
                        (String) secondLayerComboBox.getSelectedItem();
242
                try {
243
                        return (FLyrVect) layers.getLayer(clippingLayer);
244
                } catch (Exception e) {
245
                        return null;
246
                } 
247
        }
248

    
249
        public boolean onlyFirstLayerSelected() {
250
                return super.isFirstOnlySelected();
251
        }
252

    
253
        public boolean onlySecondLayerSelected() {
254
                return secondLayerSelectedCheckBox.isSelected();
255
        }
256

    
257
        public void openResultFileDialog() {
258
                super.openResultFile();
259
        }
260

    
261
        public void firstLayerSelectionChecked(boolean checked) {
262
                initSelectedItemsJCheckBox();
263
                updateNumSelectedFeaturesLabel();
264
        }
265

    
266
        public void secondLayerSelectionChecked(boolean checked) {
267
                initSelectedItems2JCheckBox();
268
                updateNumSelectedSecondLabel();
269
        }
270

    
271
}