Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / wizard / NetWizard.java @ 26861

History | View | Annotate | Download (8.67 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: NetWizard.java 26861 2009-02-20 12:44:40Z fpenarrubia $
45
* $Log$
46
* Revision 1.9  2006-12-04 17:13:39  fjp
47
* *** empty log message ***
48
*
49
* Revision 1.8  2006/11/09 13:30:40  azabala
50
* *** empty log message ***
51
*
52
* Revision 1.7  2006/11/09 12:51:12  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.6  2006/11/09 09:01:05  azabala
56
* *** empty log message ***
57
*
58
* Revision 1.5  2006/11/08 20:14:42  azabala
59
* *** empty log message ***
60
*
61
* Revision 1.4  2006/10/25 19:13:55  azabala
62
* *** empty log message ***
63
*
64
* Revision 1.3  2006/10/24 08:04:41  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.2  2006/10/20 12:02:50  jaume
68
* GUI
69
*
70
* Revision 1.1  2006/10/19 15:12:10  jaume
71
* *** empty log message ***
72
*
73
*
74
*/
75
package org.gvsig.graph.gui.wizard;
76

    
77
import java.io.File;
78
import java.sql.Types;
79
import java.text.NumberFormat;
80
import java.text.ParseException;
81
import java.util.ArrayList;
82
import java.util.Locale;
83

    
84
import javax.swing.ImageIcon;
85
import javax.swing.JOptionPane;
86

    
87
import com.iver.andami.PluginServices;
88
import com.iver.andami.ui.mdiManager.IWindow;
89
import com.iver.andami.ui.mdiManager.WindowInfo;
90
import com.iver.andami.ui.wizard.WizardAndami;
91
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
92

    
93
public class NetWizard extends WizardAndami implements IWindow{
94
//    public final static String[] COST_UNITS = {
95
//            PluginServices.getText(NetWizard.class, "seconds" ),
96
//            PluginServices.getText(NetWizard.class, "hours" ),
97
//        PluginServices.getText(NetWizard.class, "minutes" ),
98
//                                                "hh:mm:ss" ,
99
//        PluginServices.getText(NetWizard.class, "millimeters" ),
100
//        PluginServices.getText(NetWizard.class, "meters" ),
101
//        PluginServices.getText(NetWizard.class, "inches" ),
102
//        PluginServices.getText(NetWizard.class, "feet" ),
103
//        PluginServices.getText(NetWizard.class, "yards" ),
104
//        PluginServices.getText(NetWizard.class, "miles" ),
105
//        PluginServices.getText(NetWizard.class, "nautic_miles" ),
106
//        PluginServices.getText(NetWizard.class, "monetary" ), // unidades monetarias
107
//        PluginServices.getText(NetWizard.class, "unknown_longitude_units" ),
108
//        PluginServices.getText(NetWizard.class, "unknown_time_units" ),
109
//        PluginServices.getText(NetWizard.class, "unknown_units" ),
110
//    }; // TODO push it to the corresponding geoprocess class
111
    private FLyrVect lyr;
112
    private WindowInfo wi;
113
    private String[] numericLayerFieldNames;
114
    private String fieldLength;
115
    private Boolean usingCosts;
116
    private double unitFactor;
117
        private String[] layerFieldNames;
118
        private String fieldType;
119
        private String fieldSense;
120
        private String fieldCost;
121
        
122
        /**
123
         * flag that tells us if user pressed finish button
124
         * or cancel button
125
         * */
126
        private boolean wasFinishPressed = false;
127
        
128
        
129
        private boolean cleanOriginalLayer = false;
130
        private boolean applySnapTolerance = false;
131
        private double snapTolerance = 0d;
132
        private NetPage1 netPage1;
133

    
134
    public NetWizard(ImageIcon logo, FLyrVect lyr) {
135
        super(logo);
136
        this.lyr = lyr;
137
        netPage1 = new NetPage1(this);
138
        getWizardComponents().addWizardPanel(new NetPage0(this));
139
        getWizardComponents().addWizardPanel(netPage1);
140
//        getWizardComponents().addWizardPanel(new NetPage2(this));
141
//        getWizardComponents().addWizardPanel(new NetPage3(this));
142
//        getWizardComponents().addWizardPanel(new NetPage4(this));
143
        getWizardComponents().setFinishAction(new NetFinishAction(this));
144
        getWizardComponents().setCancelAction(new NetCancelAction(this));
145
    }
146
    
147
    
148
    public FLyrVect getLayer(){
149
            return lyr;
150
    }
151

    
152
    public WindowInfo getWindowInfo() {
153
        if (wi==null) {
154
            wi = new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MODALDIALOG);
155
            wi.setWidth(720);
156
            wi.setHeight(370);
157
            wi.setTitle(PluginServices.getText(this, "create_network") + "...");
158
        }
159
        return wi;
160
    }
161
    
162
    public void setCleanOriginalLayer(boolean value){
163
            this.cleanOriginalLayer = value;
164
    }
165
    
166
    public boolean getCleanOriginalLayer(){
167
            return cleanOriginalLayer;
168
    }
169
    
170
    public void setApplySnapTolerance(boolean value){
171
            this.applySnapTolerance = value;
172
    }
173
    
174
    public boolean getApplySnapTolerance(){
175
            return applySnapTolerance;
176
    }
177
    
178
    public void setSnapTolerance(double value){
179
            this.snapTolerance = value;
180
    }
181
    
182
    public double getSnapTolerance(){
183
            return snapTolerance;
184
    }
185
    
186
    
187
    public void setWasFinishPressed(boolean wasFinish){
188
            this.wasFinishPressed = wasFinish;
189
    }
190
    
191
    public boolean wasFinishPressed(){
192
            return wasFinishPressed;
193
    }
194

    
195
    public String[] getNumericLayerFieldNames() {
196
        if (numericLayerFieldNames == null) {
197
            try {
198
                String[] aux = lyr.getRecordset().getFieldNames();
199
                ArrayList temp = new ArrayList();
200
                for (int i = 0; i < aux.length; i++) {
201
                    switch (lyr.getRecordset().getFieldType(i)) {
202
                    case Types.BIGINT:
203
                    case Types.DECIMAL:
204
                    case Types.DOUBLE:
205
                    case Types.FLOAT:
206
                    case Types.INTEGER:
207
                    case Types.NUMERIC:
208
                    case Types.REAL:
209
                    case Types.SMALLINT:
210
                    case Types.TINYINT:
211
                        temp.add(aux[i]);
212
                    }
213
                }
214
                numericLayerFieldNames = (String[]) temp.toArray(new String[0]);
215
            } catch (Exception e) {
216
                return new String[] {PluginServices.getText(this, "invalid_layer")+"!"};
217
            }
218
        }
219
        return numericLayerFieldNames;
220
    }
221

    
222
    public String[] getLayerFieldNames() {
223
            if (layerFieldNames == null) {
224
            try {
225
                    layerFieldNames = lyr.getRecordset().getFieldNames();
226
            } catch (Exception e) {
227
                    return new String[] {PluginServices.getText(this, "invalid_layer")+"!"};
228
            }
229
            }
230
            return layerFieldNames;
231
    }
232

    
233
    public void setLengthField(String lengthField) {
234
        this.fieldLength = lengthField;
235
    }
236

    
237
        public void setTypeField(String fieldType) {
238
                this.fieldType = fieldType;
239
        }
240

    
241
        public void setCostField(String fieldCost) {
242
        this.fieldCost = fieldCost;
243
    }
244

    
245
        public void setSenseField(String fieldSense) {
246
                this.fieldSense = fieldSense;
247
        }
248

    
249
    public void setUnitFactor(double d) {
250
        this.unitFactor = d;
251
    }
252
    public double getUnitFactor() {
253
//            NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH); // use always . as decimal separator
254
//            Number aux;
255
//                try {
256
//                        aux = nf.parse(unitFactor);
257
//                        return aux.doubleValue();
258
//                } catch (ParseException e) {
259
//                        JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Bad number format in unitFactor"));
260
//                        e.printStackTrace();
261
//                }
262
                return unitFactor;
263
    }
264

    
265
    
266
    public void setUsingCosts(Boolean costs) {
267
        this.usingCosts = costs;
268
    }
269

    
270
    public Boolean isUsingCosts() {
271
        return usingCosts;
272
    }
273

    
274
        public String getFieldType() {
275
                return this.fieldType;
276
        }
277

    
278
        public String getFieldLength() {
279
                return this.fieldLength;
280
        }
281

    
282
        public String getFieldSense() {
283
                return this.fieldSense;
284
        }
285

    
286
        public String getFieldCost() {
287
                return this.fieldCost;
288
        }
289

    
290

    
291
        public String getSenseDigitalization() {
292
                return netPage1.getSenseDigitalization();
293
        }
294

    
295

    
296
        public String getSenseReverseDigitalization() {
297
                return netPage1.getSenseReverseDigitalization();
298
        }
299

    
300

    
301
        public File getNetworkFile() {
302
                return new File(netPage1.getTxtFile());
303
        }
304

    
305

    
306
}