Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / cad / panels / ChooseGeometryType.java @ 40557

History | View | Annotate | Download (8.83 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.editing.gui.cad.panels;
25

    
26

    
27
import javax.swing.ButtonGroup;
28
import javax.swing.JLabel;
29
import javax.swing.JPanel;
30
import javax.swing.JRadioButton;
31
import javax.swing.JTextField;
32
import javax.swing.event.CaretEvent;
33
import javax.swing.event.CaretListener;
34

    
35
import jwizardcomponent.JWizardComponents;
36
import jwizardcomponent.JWizardPanel;
37

    
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.fmap.dal.exception.DataException;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.geom.Geometry;
42

    
43

    
44
/**
45
 * @author fjp
46
 *
47
 * Panel para que el usuario seleccione el driver que va a utilizar para
48
 * crear un tema desde cero.
49
 *
50
 */
51
public class ChooseGeometryType extends JWizardPanel {
52

    
53
        private JLabel lblSelecGeometryType = null;
54
        private JPanel jPanelGeometryTypeOptions = null;
55
        private JRadioButton jRadioButtonPoint = null;
56
        private JRadioButton jRadioButtonLine = null;
57
        private JRadioButton jRadioButtonPolygon = null;
58
        private JRadioButton jRadioButtonMulti = null;
59
        private JRadioButton jRadioButtonMultiPoint = null;
60
        private JTextField jTextFieldLayerName = null;
61
        private JLabel jLabelLayerName = null;
62
        private String driverName;
63

    
64
        private class MyInputEventListener implements CaretListener
65
        {
66
                public void caretUpdate(CaretEvent arg0) {
67
                        if (jTextFieldLayerName.getText().length() > 0)
68
                                setNextButtonEnabled(true);
69
                        else
70
                                setNextButtonEnabled(false);
71

    
72
                }
73

    
74
        }
75

    
76
        public ChooseGeometryType(JWizardComponents wizardComponents) {
77
                super(wizardComponents);
78
                initialize();
79
                // TODO Auto-generated constructor stub
80
        }
81

    
82
        /**
83
         * This method initializes this
84
         *
85
         */
86
        private void initialize() {
87
        jLabelLayerName = new JLabel();
88
        jLabelLayerName.setBounds(new java.awt.Rectangle(14,9,321,22));
89
        jLabelLayerName.setText(PluginServices.getText(this,"enter_layer_name"));
90
        lblSelecGeometryType = new JLabel();
91
        lblSelecGeometryType.setText(PluginServices.getText(this,"select_geometry_type"));
92
        lblSelecGeometryType.setBounds(new java.awt.Rectangle(13,63,329,15));
93
        this.setLayout(null);
94
        this.setSize(new java.awt.Dimension(358,263));
95
        this.add(lblSelecGeometryType, null);
96
        this.add(getJPanelGeometryTypeOptions(), null);
97
        this.add(getJTextFieldLayerName(), null);
98
        this.add(jLabelLayerName, null);
99

    
100
        }
101

    
102
        /**
103
         * This method initializes jPanelGeometryTypeOptions
104
         *
105
         * @return javax.swing.JPanel
106
         */
107
        private JPanel getJPanelGeometryTypeOptions() {
108
                if (jPanelGeometryTypeOptions == null) {
109
                        jPanelGeometryTypeOptions = new JPanel();
110
                        jPanelGeometryTypeOptions.setLayout(null);
111
                        jPanelGeometryTypeOptions.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"Geometry_types"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
112
                        jPanelGeometryTypeOptions.setPreferredSize(new java.awt.Dimension(300,400));
113
                        jPanelGeometryTypeOptions.setBounds(new java.awt.Rectangle(14,82,326,172));
114
                        jPanelGeometryTypeOptions.add(getJRadioButtonPoint(), null);
115
                        jPanelGeometryTypeOptions.add(getJRadioButtonLine(), null);
116
                        jPanelGeometryTypeOptions.add(getJRadioButtonPolygon(), null);
117
                        jPanelGeometryTypeOptions.add(getJRadioButtonMulti(), null);
118
                        jPanelGeometryTypeOptions.add(getJRadioButtonMultiPoint(), null);
119

    
120
                    //Group the radio buttons.
121
                    ButtonGroup group = new ButtonGroup();
122
                    group.add(getJRadioButtonPoint());
123
                    group.add(getJRadioButtonLine());
124
                    group.add(getJRadioButtonPolygon());
125
                    group.add(getJRadioButtonMulti());
126
                    group.add(getJRadioButtonMultiPoint());
127

    
128
                }
129
                return jPanelGeometryTypeOptions;
130
        }
131

    
132
        /**
133
         * This method initializes jRadioButtonPoint
134
         *
135
         * @return javax.swing.JRadioButton
136
         */
137
        private JRadioButton getJRadioButtonPoint() {
138
                if (jRadioButtonPoint == null) {
139
                        jRadioButtonPoint = new JRadioButton();
140
                        jRadioButtonPoint.setText(PluginServices.getText(this,"point_type"));
141
                        jRadioButtonPoint.setBounds(new java.awt.Rectangle(19,31,297,23));
142
                }
143
                return jRadioButtonPoint;
144
        }
145

    
146
        /**
147
         * This method initializes jRadioButtonLine
148
         *
149
         * @return javax.swing.JRadioButton
150
         */
151
        private JRadioButton getJRadioButtonLine() {
152
                if (jRadioButtonLine == null) {
153
                        jRadioButtonLine = new JRadioButton();
154
                        jRadioButtonLine.setText(PluginServices.getText(this,"line_type"));
155
                        jRadioButtonLine.setSelected(true);
156
                        jRadioButtonLine.setBounds(new java.awt.Rectangle(19,81,297,23));
157
                }
158
                return jRadioButtonLine;
159
        }
160

    
161
        /**
162
         * This method initializes jRadioButtonPolygon
163
         *
164
         * @return javax.swing.JRadioButton
165
         */
166
        private JRadioButton getJRadioButtonPolygon() {
167
                if (jRadioButtonPolygon == null) {
168
                        jRadioButtonPolygon = new JRadioButton();
169
                        jRadioButtonPolygon.setText(PluginServices.getText(this,"polygon_type"));
170
                        jRadioButtonPolygon.setBounds(new java.awt.Rectangle(19,106,297,23));
171
                }
172
                return jRadioButtonPolygon;
173
        }
174

    
175
        /**
176
         * This method initializes jRadioButtonMulti
177
         *
178
         * @return javax.swing.JRadioButton
179
         */
180
        private JRadioButton getJRadioButtonMulti() {
181
                if (jRadioButtonMulti == null) {
182
                        jRadioButtonMulti = new JRadioButton();
183
                        jRadioButtonMulti.setText(PluginServices.getText(this,"multi_type"));
184
                        jRadioButtonMulti.setBounds(new java.awt.Rectangle(19,131,297,23));
185
                }
186
                return jRadioButtonMulti;
187
        }
188

    
189
        /**
190
         * This method initializes jRadioButton
191
         *
192
         * @return javax.swing.JRadioButton
193
         */
194
        private JRadioButton getJRadioButtonMultiPoint() {
195
                if (jRadioButtonMultiPoint == null) {
196
                        jRadioButtonMultiPoint = new JRadioButton();
197
                        jRadioButtonMultiPoint.setText(PluginServices.getText(this,"multipoint_type"));
198
                        jRadioButtonMultiPoint.setBounds(new java.awt.Rectangle(19,56,297,23));
199
                }
200
                return jRadioButtonMultiPoint;
201
        }
202

    
203
        /**
204
         * En funci?n de qu? tipo de driver sea, habilitamos o deshabilitamos
205
         * las opciones. Por ejemplo, si es de tipo shp, deshabilitamos
206
         * multi_type
207
         * @param writer
208
         */
209
        public void setFeatureStore(FeatureStore store) {
210
                // En funci?n de qu? tipo de driver sea, habilitamos o deshabilitamos
211
                // las opciones. Por ejemplo, si es de tipo shp, deshabilitamos
212
                // multi_type
213
//                IWriteable aux = (IWriteable) store.;
214
//                ISpatialWriter writer = (ISpatialWriter) aux.getWriter();
215
//                System.out.println("Writer seleccionado:" + writer.getName());
216
//                driverName = store.getName();
217
                try {
218
                        getJRadioButtonPoint().setEnabled(store.canWriteGeometry(Geometry.TYPES.POINT));
219
                        getJRadioButtonMultiPoint().setEnabled(store.canWriteGeometry(Geometry.TYPES.MULTIPOINT));
220
                        getJRadioButtonLine().setEnabled(store.canWriteGeometry(Geometry.TYPES.CURVE));
221
                        getJRadioButtonPolygon().setEnabled(store.canWriteGeometry(Geometry.TYPES.SURFACE));
222
                        getJRadioButtonMulti().setEnabled(store.canWriteGeometry(Geometry.TYPES.GEOMETRY));
223
                } catch (DataException e) {
224
                        e.printStackTrace();
225
                }
226

    
227
        }
228

    
229
        public int getSelectedGeometryType()
230
        {
231
                if (getJRadioButtonPoint().isSelected())
232
                        return Geometry.TYPES.POINT;
233
                if (getJRadioButtonMultiPoint().isSelected())
234
                        return Geometry.TYPES.MULTIPOINT;
235
                if (getJRadioButtonLine().isSelected())
236
                        return Geometry.TYPES.CURVE;
237
                if (getJRadioButtonPolygon().isSelected())
238
                        return Geometry.TYPES.SURFACE;
239
                if (getJRadioButtonMulti().isSelected())
240
                        return Geometry.TYPES.GEOMETRY;
241

    
242
                return -1;
243
        }
244

    
245
        /**
246
         * This method initializes jTextLayerName
247
         *
248
         * @return javax.swing.JTextField
249
         */
250
        private JTextField getJTextFieldLayerName() {
251
                if (jTextFieldLayerName == null) {
252
                        jTextFieldLayerName = new JTextField();
253
                        jTextFieldLayerName.setBounds(new java.awt.Rectangle(13,36,323,20));
254
                        jTextFieldLayerName.setText("layer1"); //PluginServices.getText(this,"new_layer"));
255
                        jTextFieldLayerName.setHorizontalAlignment(javax.swing.JTextField.LEFT);
256
                        jTextFieldLayerName.addCaretListener(new MyInputEventListener());
257
                }
258
                return jTextFieldLayerName;
259
        }
260

    
261
        public String getLayerName() {
262
                return getJTextFieldLayerName().getText();
263
        }
264

    
265
        public String getSelectedDriver() {
266
                return driverName;
267
        }
268

    
269

    
270

    
271
}  //  @jve:decl-index=0:visual-constraint="10,10"