Statistics
| Revision:

root / trunk / extensions / extGraph / src / org / gvsig / graph / gui / ConnectivityControlPanel.java @ 29993

History | View | Annotate | Download (22.5 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 Software Colaborativo (www.scolab.es)   development
26
 */
27

    
28
package org.gvsig.graph.gui;
29

    
30
import java.awt.BorderLayout;
31
import java.awt.Color;
32
import java.awt.Dimension;
33
import java.awt.Font;
34
import java.awt.GridBagConstraints;
35
import java.awt.GridBagLayout;
36
import java.awt.Insets;
37
import java.awt.Point;
38
import java.awt.Rectangle;
39
import java.awt.SystemColor;
40

    
41
import javax.swing.BorderFactory;
42
import javax.swing.ButtonGroup;
43
import javax.swing.ComboBoxModel;
44
import javax.swing.DefaultComboBoxModel;
45
import javax.swing.ImageIcon;
46
import javax.swing.JButton;
47
import javax.swing.JCheckBox;
48
import javax.swing.JComboBox;
49
import javax.swing.JLabel;
50
import javax.swing.JOptionPane;
51
import javax.swing.JPanel;
52
import javax.swing.JRadioButton;
53
import javax.swing.JTextArea;
54
import javax.swing.JTextField;
55
import javax.swing.JToggleButton;
56
import javax.swing.border.EtchedBorder;
57
import javax.swing.border.TitledBorder;
58

    
59
import org.gvsig.exceptions.BaseException;
60
import org.gvsig.graph.core.GraphException;
61
import org.gvsig.graph.core.GvFlag;
62
import org.gvsig.graph.core.IFlagListener;
63
import org.gvsig.graph.core.Network;
64
import org.gvsig.graph.core.NetworkUtils;
65
import org.gvsig.graph.solvers.IDijkstraListener;
66
import org.gvsig.graph.solvers.OneToManySolver;
67
import org.gvsig.graph.solvers.ReverseOneToManySolver;
68
import org.gvsig.graph.solvers.SelectDijkstraListener;
69
import org.gvsig.graph.tools.FlagListener;
70
import org.gvsig.graph.tools.SingleFlagListener;
71

    
72
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
73
import com.iver.andami.PluginServices;
74
import com.iver.andami.ui.mdiManager.IWindow;
75
import com.iver.andami.ui.mdiManager.IWindowListener;
76
import com.iver.andami.ui.mdiManager.WindowInfo;
77
import com.iver.cit.gvsig.fmap.MapContext;
78
import com.iver.cit.gvsig.fmap.MapControl;
79
import com.iver.cit.gvsig.fmap.core.FShape;
80
import com.iver.cit.gvsig.fmap.core.IFeature;
81
import com.iver.cit.gvsig.fmap.layers.FBitSet;
82
import com.iver.cit.gvsig.fmap.layers.FLayer;
83
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
84
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator;
85
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
86

    
87
import java.awt.event.ActionEvent;
88
import java.awt.event.ActionListener;
89
import java.awt.event.ItemEvent;
90
import java.awt.event.ItemListener;
91
import java.awt.event.KeyEvent;
92
import java.text.NumberFormat;
93
import java.util.Locale;
94

    
95
public class ConnectivityControlPanel extends JPanel implements IWindow,
96
                        IWindowListener, IFlagListener {
97

    
98
        private static final long serialVersionUID = 1L;
99
        private JPanel jPanelSouth = null;
100
        private JPanel jPanelCenter = null;
101
        private JPanel jPanelNorth = null;
102
        private JLabel jLblConnectivity = null;
103
        private JLabel jLblIcon = null;
104
        private JTextArea jTextArea = null;
105
        private JLabel jLblOriginPoint = null;
106
        private JTextField jTxtOriginPointX = null;
107
        private JTextField jTxtOriginPointY = null;
108

    
109
        private JToggleButton jToggleButtonSetFlag = null;
110
        private JLabel jLblAssociatedLayer = null;
111
        private JComboBox jCboAssociatedLayer = null;
112
        private JButton jBtnCalculate = null;
113
        private JButton jBtnClose = null;
114
        private JPanel jPanelOptions = null;
115
        private JRadioButton jRadioBtnNormalDirection = null;
116
        private JRadioButton jRadioBtnReverseDirection = null;
117
        private JCheckBox jChkBoxUseMaxDist = null;
118
        private JCheckBox jChkBoxUseMaxCost = null;
119
        private JTextField jTxtMaxDist = null;
120
        private JTextField jTxtMaxCost = null;
121
        private WindowInfo wi;
122
        private MapControl mapCtrl;
123

    
124
        private SelectDijkstraListener selectListener;
125
        private GvFlag sourceFlag;
126
        protected SingleFlagListener flagListener;
127
        private String lastSelectedTool;
128
        
129
        /**
130
         * This is the default constructor
131
         */
132
        public ConnectivityControlPanel() {
133
                super();
134
                initialize();
135
        }
136

    
137
        /**
138
         * This method initializes this
139
         * 
140
         * @return void
141
         */
142
        private void initialize() {
143
                this.setSize(343, 346);
144
                this.setLayout(new BorderLayout());
145
                this.add(getJPanelNorth(), BorderLayout.NORTH);
146
                this.add(getJPanelSouth(), BorderLayout.SOUTH);
147
                this.add(getJPanelCenter(), BorderLayout.CENTER);
148
        }
149

    
150
        /**
151
         * This method initializes jPanelSouth
152
         * 
153
         * @return javax.swing.JPanel
154
         */
155
        private JPanel getJPanelSouth() {
156
                if (jPanelSouth == null) {
157
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
158
                        gridBagConstraints.gridx = 1;
159
                        gridBagConstraints.gridy = 0;
160
                        jPanelSouth = new JPanel();
161
                        jPanelSouth.setLayout(new GridBagLayout());
162
                        jPanelSouth.setPreferredSize(new Dimension(134, 30));
163
                        jPanelSouth.add(getJBtnCalculate(), new GridBagConstraints());
164
                        jPanelSouth.add(getJBtnClose(), gridBagConstraints);
165
                }
166
                return jPanelSouth;
167
        }
168

    
169
        /**
170
         * This method initializes jPanelCenter
171
         * 
172
         * @return javax.swing.JPanel
173
         */
174
        private JPanel getJPanelCenter() {
175
                if (jPanelCenter == null) {
176
                        jLblAssociatedLayer = new JLabel();
177
                        jLblAssociatedLayer.setBounds(new Rectangle(15, 57, 111, 14));
178
                        jLblAssociatedLayer.setText("Capa asociada:");
179
                        jLblOriginPoint = new JLabel();
180
                        jLblOriginPoint.setBounds(new Rectangle(15, 17, 111, 14));
181
                        jLblOriginPoint.setText("Punto or?gen:");
182
                        jPanelCenter = new JPanel();
183
                        jPanelCenter.setLayout(null);
184
                        jPanelCenter.add(jLblOriginPoint, null);
185

    
186
                        JLabel jLblX = new JLabel();
187
                        jLblX.setBounds(new Rectangle(102, 3, 111, 14));
188
                        jLblX.setText("X:");
189
                        JLabel jLblY = new JLabel();
190
                        jLblY.setBounds(new Rectangle(202, 3, 111, 14));
191
                        jLblY.setText("Y:");
192

    
193
                        jPanelCenter.add(jLblX, null);
194
                        jPanelCenter.add(jLblY, null);
195

    
196
                        jPanelCenter.add(getJTxtOriginPointX(), null);
197
                        jPanelCenter.add(getJTxtOriginPointY(), null);
198
                        jPanelCenter.add(getJToggleButtonSetFlag(), null);
199
                        jPanelCenter.add(jLblAssociatedLayer, null);
200
                        jPanelCenter.add(getJCboAssociatedLayer(), null);
201
                        jPanelCenter.add(getJPanelOptions(), null);
202
                }
203
                return jPanelCenter;
204
        }
205

    
206
        /**
207
         * This method initializes jPanelNorth
208
         * 
209
         * @return javax.swing.JPanel
210
         */
211
        private JPanel getJPanelNorth() {
212
                if (jPanelNorth == null) {
213
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
214
                        gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
215
                        gridBagConstraints1.gridx = 0;
216
                        gridBagConstraints1.anchor = GridBagConstraints.SOUTHWEST;
217
                        gridBagConstraints1.weightx = 1.0D;
218
                        gridBagConstraints1.insets = new Insets(2, 5, 0, 0);
219
                        gridBagConstraints1.gridy = 1;
220
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
221
                        gridBagConstraints2.gridx = 1;
222
                        gridBagConstraints2.anchor = GridBagConstraints.EAST;
223
                        gridBagConstraints2.gridy = 1;
224
                        jLblIcon = new JLabel();
225
                        jLblIcon.setText("");
226
                        jLblIcon.setIcon(new ImageIcon(this.getClass().getClassLoader()
227
                                        .getResource("images/wizard_connectivity.png")));
228
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
229
                        gridBagConstraints.gridx = 0;
230
                        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
231
                        gridBagConstraints.gridwidth = 1;
232
                        gridBagConstraints.ipadx = 7;
233
                        gridBagConstraints.gridheight = 0;
234
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
235
                        gridBagConstraints.insets = new Insets(2, 5, 0, 0);
236
                        gridBagConstraints.ipady = 3;
237
                        gridBagConstraints.weightx = 1.0D;
238
                        gridBagConstraints.gridy = 0;
239
                        jLblConnectivity = new JLabel();
240
                        jLblConnectivity.setText(PluginServices.getText(this,
241
                                        "connectivity"));
242
                        jLblConnectivity.setFont(new Font("Dialog", Font.BOLD, 14));
243
                        jPanelNorth = new JPanel();
244
                        jPanelNorth.setLayout(new GridBagLayout());
245
                        jPanelNorth.setPreferredSize(new Dimension(0, 70));
246
                        jPanelNorth.setBackground(SystemColor.text);
247
                        jPanelNorth.setBorder(BorderFactory
248
                                        .createEtchedBorder(EtchedBorder.LOWERED));
249
                        jPanelNorth.add(jLblConnectivity, gridBagConstraints);
250
                        jPanelNorth.add(jLblIcon, gridBagConstraints2);
251
                        jPanelNorth.add(getJTextArea(), gridBagConstraints1);
252
                }
253
                return jPanelNorth;
254
        }
255

    
256
        private JTextArea getJTextArea() {
257
                if (jTextArea == null) {
258
                        jTextArea = new JTextArea();
259
                        jTextArea.setPreferredSize(new Dimension(100, 40));
260
                        jTextArea.setText(PluginServices.getText(this, "connectivity_analysis"));
261
                        jTextArea.setEditable(false);
262
                        jTextArea.setLineWrap(true);
263
                }
264
                return jTextArea;
265
        }
266

    
267
        private JTextField getJTxtOriginPointX() {
268
                if (jTxtOriginPointX == null) {
269
                        jTxtOriginPointX = new JTextField();
270
                        jTxtOriginPointX.setBounds(new Rectangle(100, 16, 92, 20));
271
                        jTxtOriginPointX.setHorizontalAlignment(JTextField.RIGHT);
272
                        
273
                }
274
                return jTxtOriginPointX;
275
        }
276

    
277
        private JTextField getJTxtOriginPointY() {
278
                if (jTxtOriginPointY == null) {
279
                        jTxtOriginPointY = new JTextField();
280
                        jTxtOriginPointY.setBounds(new Rectangle(200, 16, 92, 20));
281
                        jTxtOriginPointY.setHorizontalAlignment(JTextField.RIGHT);
282
                }
283
                return jTxtOriginPointY;
284
        }
285

    
286
        /**
287
         * This method initializes jToggleButtonSetFlag
288
         * 
289
         * @return javax.swing.JToggleButton
290
         */
291
        private JToggleButton getJToggleButtonSetFlag() {
292
                if (jToggleButtonSetFlag == null) {
293
                        jToggleButtonSetFlag = new JToggleButton();
294
                        jToggleButtonSetFlag.setIcon(new ImageIcon(this.getClass()
295
                                        .getClassLoader().getResource(
296
                                                        "images/disconnect_co_004.gif")));
297
                        jToggleButtonSetFlag.setSize(new Dimension(22, 22));
298
                        jToggleButtonSetFlag.setLocation(new Point(295, 15));
299
                        jToggleButtonSetFlag.setToolTipText(PluginServices.getText(this, "set_source_flag"));
300
                        ItemListener itemListener = new ItemListener() {
301
                                public void itemStateChanged(ItemEvent itemEvent) {
302
                                        int state = itemEvent.getStateChange();
303
                                        if (state == ItemEvent.SELECTED) {
304
                                                doSelectTool();
305
                                        } else {                                                
306
                                                System.out.println("Deselected");
307
                                        }
308
                                }
309
                        };
310
                        // Attach Listeners
311
                        jToggleButtonSetFlag.addItemListener(itemListener);
312
                }
313
                return jToggleButtonSetFlag;
314
        }
315

    
316
        protected void doSelectTool() {
317
                System.out.println("Selected");
318
                if (!mapCtrl.hasTool("addSingleFlag")) // We create it for the first time.
319
        {
320
                flagListener = new SingleFlagListener(mapCtrl);
321
                flagListener.setMode(FlagListener.TO_ARC);
322
            mapCtrl.addMapTool("addSingleFlag", new PointBehavior(flagListener));
323
        }
324
                MapContext map = mapCtrl.getMapContext();
325
                SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
326
                FLyrVect layer = null;
327

    
328
                while (it.hasNext()) {
329
                        FLayer aux = it.next();
330
                        if (!aux.isActive())
331
                                continue;
332
                        Network net = (Network) aux.getProperty("network");
333
                        if (net != null) {
334
                                net.addFlagListener(this);
335
                        }
336
                }
337
                
338
        mapCtrl.setTool("addSingleFlag");
339
                
340
        }
341

    
342
        /**
343
         * This method initializes jCboAssociatedLayer
344
         * 
345
         * @return javax.swing.JComboBox
346
         */
347
        private JComboBox getJCboAssociatedLayer() {
348
                if (jCboAssociatedLayer == null) {
349
                        jCboAssociatedLayer = new JComboBox();
350
                        jCboAssociatedLayer.setBounds(new Rectangle(100, 55, 192, 20));
351
                }
352
                return jCboAssociatedLayer;
353
        }
354

    
355
        /**
356
         * This method initializes jBtnCalculate
357
         * 
358
         * @return javax.swing.JButton
359
         */
360
        private JButton getJBtnCalculate() {
361
                if (jBtnCalculate == null) {
362
                        jBtnCalculate = new JButton();
363
                        jBtnCalculate.setText("Calcular");
364
                        jBtnCalculate.addActionListener(new ActionListener() {
365
                                public void actionPerformed(ActionEvent e) {
366
                                        doConnectivityAnalisys();
367
                                }
368
                        });
369

    
370
                }
371
                return jBtnCalculate;
372
        }
373

    
374
        protected void doConnectivityAnalisys() {
375
                MapContext map = mapCtrl.getMapContext();
376
                SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
377
                FLyrVect layer = null;
378

    
379
                while (it.hasNext()) {
380
                        FLayer aux = it.next();
381
                        if (!aux.isActive())
382
                                continue;
383
                        Network net = (Network) aux.getProperty("network");
384
                        if (net != null) {
385
                                GvFlag[] flags = null;
386
                                if (getJCboAssociatedLayer().getSelectedIndex() != 0) {
387
                                        // use associated layer to put flags.
388
                                        String layerName = (String) getJCboAssociatedLayer()
389
                                                        .getSelectedItem();
390
                                        layer = (FLyrVect) map.getLayers().getLayer(
391
                                                        layerName);
392
                                        
393
                                        double tolerance = mapCtrl.getViewPort().toMapDistance(FlagListener.pixelTolerance);
394

    
395
                                        try {
396
                                                flags = NetworkUtils.putFlagsOnNetwork(layer, net,
397
                                                                tolerance);
398
                                        } catch (BaseException e) {
399
                                                // TODO Auto-generated catch block
400
                                                e.printStackTrace();
401
                                        }
402
                                }
403
                                selectListener = new SelectDijkstraListener(net, mapCtrl
404
                                                .getMapContext());
405
                                selectListener.startSelection();
406
                                try {
407
                                        net.getLayer().getRecordset().clearSelection();
408
                                        if (layer != null)
409
                                                layer.getRecordset().clearSelection();
410
                                        
411
                                        if (getJRadioBtnNormalDirection().isSelected()) {
412
                                                OneToManySolver solver = new OneToManySolver();
413
                                                doSolve(net, selectListener, solver);
414
                                        }
415
                                        else {
416
                                                ReverseOneToManySolver solver = new ReverseOneToManySolver();
417
                                                doSolve(net, selectListener, solver);
418
                                        }
419
                                        if (flags != null)
420
                                                for (int i=0; i < flags.length; i++)
421
                                                        net.removeFlag(flags[i]);
422
                                } catch (GraphException e) {
423
                                        // TODO Auto-generated catch block
424
                                        e.printStackTrace();
425
                                } catch (ReadDriverException e) {
426
                                        // TODO Auto-generated catch block
427
                                        e.printStackTrace();
428
                                }
429
                                selectListener.stopSelection();
430
                                if (flags != null) {
431
                                        for (int i = 0; i < flags.length; i++) {
432
                                                if (flags[i].getCost() != -1) {
433
                                                        Integer index = (Integer) flags[i].getProperties().get("rec");
434
                                                        FBitSet bs;
435
                                                        try {
436
                                                                bs = layer.getRecordset().getSelection();
437
                                                                bs.set(index.intValue());
438
                                                        } catch (ReadDriverException e) {
439
                                                                // TODO Auto-generated catch block
440
                                                                e.printStackTrace();
441
                                                        }
442
                                                }
443
                                        }
444
                                }
445
                                mapCtrl.drawMap(true);
446
                                PluginServices.getMainFrame().enableControls();
447
                        }
448
                } // WHILE
449
        }
450

    
451

    
452
        private void doSolve(Network net, IDijkstraListener selectListener, OneToManySolver solver)
453
                        throws GraphException {
454
                
455
                solver.setNetwork(net);
456
                solver.addListener(selectListener);
457
                if (getJChkBoxUseMaxCost().isSelected()) {
458
                        solver.setMaxCost(Double.parseDouble(getJTxtMaxCost().getText()));
459
                }
460
                if (getJChkBoxUseMaxDist().isSelected()) {
461
                        solver.setMaxDistance(Double
462
                                        .parseDouble(getJTxtMaxDist().getText()));
463
                }
464

    
465
                solver.addListener(selectListener);
466

    
467
                try {
468
                        double x = Double.parseDouble(getJTxtOriginPointX().getText());
469
                        double y = Double.parseDouble(getJTxtOriginPointY().getText());
470
                        double tol = mapCtrl.getViewPort().toMapDistance(FlagListener.pixelTolerance);
471
                        sourceFlag = net.createFlag(x, y, tol);
472
                        if (sourceFlag == null) {
473
                                JOptionPane.showMessageDialog(this, "Error al posicionar el punto sobre la red.");
474
                                return;                                
475
                        }
476
                        solver.setSourceFlag(sourceFlag);
477
                }
478
                catch (NumberFormatException e) {
479
                        JOptionPane.showMessageDialog(this, "Error en las coordenadas del punto de or?gen:" + e.getMessage());
480
                        return;
481
                }
482
                long t1 = System.currentTimeMillis();
483
                solver.putDestinationsOnNetwork(net.getFlags());
484
                solver.calculate();
485
                solver.removeDestinationsFromNetwork(net.getFlags());
486
                long t2 = System.currentTimeMillis();
487
                System.out.println("tiempo:" + (t2 - t1));
488

    
489
                GvFlag flags[] = net.getFlags();
490

    
491
                for (int i = 0; i < flags.length; i++) {
492
                        System.out.println("Flag " + i + " " + flags[i].getCost());
493
                }
494
        }
495

    
496
        /**
497
         * This method initializes jBtnClose
498
         * 
499
         * @return javax.swing.JButton
500
         */
501
        private JButton getJBtnClose() {
502
                if (jBtnClose == null) {
503
                        jBtnClose = new JButton();
504
                        jBtnClose.setText("Cerrar");
505
                        jBtnClose.addActionListener(new ActionListener() {
506

    
507
                                public void actionPerformed(ActionEvent e) {
508
                                        close();
509
                                }
510

    
511
                        });
512
                }
513
                return jBtnClose;
514
        }
515

    
516
        protected void close() {
517
                PluginServices.getMDIManager().closeWindow(this);
518
        }
519

    
520
        /**
521
         * This method initializes jPanelOptions
522
         * 
523
         * @return javax.swing.JPanel
524
         */
525
        private JPanel getJPanelOptions() {
526
                if (jPanelOptions == null) {
527
                        jPanelOptions = new JPanel();
528
                        jPanelOptions.setLayout(null);
529
                        jPanelOptions.setBounds(new Rectangle(15, 87, 315, 140));
530
                        jPanelOptions.setBorder(BorderFactory.createTitledBorder(null,
531
                                        "Options", TitledBorder.DEFAULT_JUSTIFICATION,
532
                                        TitledBorder.DEFAULT_POSITION, new Font("Tahoma",
533
                                                        Font.PLAIN, 11), Color.black));
534
                        ButtonGroup group = new ButtonGroup();
535
                        group.add(getJRadioBtnNormalDirection());
536
                        group.add(getJRadioBtnReverseDirection());
537
                        jPanelOptions.add(getJRadioBtnNormalDirection(), null);
538
                        jPanelOptions.add(getJRadioBtnReverseDirection(), null);
539
                        jPanelOptions.add(getJChkBoxUseMaxDist(), null);
540
                        jPanelOptions.add(getJChkBoxUseMaxCost(), null);
541
                        jPanelOptions.add(getJTxtMaxDist(), null);
542
                        jPanelOptions.add(getJTxtMaxCost(), null);
543
                }
544
                return jPanelOptions;
545
        }
546

    
547
        /**
548
         * This method initializes jRadioBtnNormalDirection
549
         * 
550
         * @return javax.swing.JRadioButton
551
         */
552
        private JRadioButton getJRadioBtnNormalDirection() {
553
                if (jRadioBtnNormalDirection == null) {
554
                        jRadioBtnNormalDirection = new JRadioButton();
555
                        jRadioBtnNormalDirection.setBounds(new Rectangle(15, 25, 200, 21));
556
                        jRadioBtnNormalDirection.setSelected(true);
557
                        jRadioBtnNormalDirection.setText("Sentido normal");
558
                }
559
                return jRadioBtnNormalDirection;
560
        }
561

    
562
        /**
563
         * This method initializes jRadioBtnReverseDirection
564
         * 
565
         * @return javax.swing.JRadioButton
566
         */
567
        private JRadioButton getJRadioBtnReverseDirection() {
568
                if (jRadioBtnReverseDirection == null) {
569
                        jRadioBtnReverseDirection = new JRadioButton();
570
                        jRadioBtnReverseDirection.setBounds(new Rectangle(15, 53, 180, 23));
571
                        jRadioBtnReverseDirection.setText("Sentido inverso");
572
                        jRadioBtnReverseDirection.setSelected(false);
573
                }
574
                return jRadioBtnReverseDirection;
575
        }
576

    
577
        /**
578
         * This method initializes jChkBoxUseMaxDist
579
         * 
580
         * @return javax.swing.JCheckBox
581
         */
582
        private JCheckBox getJChkBoxUseMaxDist() {
583
                if (jChkBoxUseMaxDist == null) {
584
                        jChkBoxUseMaxDist = new JCheckBox();
585
                        jChkBoxUseMaxDist.setBounds(new Rectangle(15, 85, 168, 21));
586
                        jChkBoxUseMaxDist.setText("Usar distancia m?xima:");
587
                }
588
                return jChkBoxUseMaxDist;
589
        }
590

    
591
        /**
592
         * This method initializes jChkBoxUseMaxCost
593
         * 
594
         * @return javax.swing.JCheckBox
595
         */
596
        private JCheckBox getJChkBoxUseMaxCost() {
597
                if (jChkBoxUseMaxCost == null) {
598
                        jChkBoxUseMaxCost = new JCheckBox();
599
                        jChkBoxUseMaxCost.setBounds(new Rectangle(15, 112, 167, 23));
600
                        jChkBoxUseMaxCost.setText("Usar coste m?ximo:");
601
                }
602
                return jChkBoxUseMaxCost;
603
        }
604

    
605
        /**
606
         * This method initializes jTxtMaxDist
607
         * 
608
         * @return javax.swing.JTextField
609
         */
610
        private JTextField getJTxtMaxDist() {
611
                if (jTxtMaxDist == null) {
612
                        jTxtMaxDist = new JTextField();
613
                        jTxtMaxDist.setBounds(new Rectangle(190, 86, 95, 20));
614
                }
615
                return jTxtMaxDist;
616
        }
617

    
618
        /**
619
         * This method initializes jTxtMaxCost
620
         * 
621
         * @return javax.swing.JTextField
622
         */
623
        private JTextField getJTxtMaxCost() {
624
                if (jTxtMaxCost == null) {
625
                        jTxtMaxCost = new JTextField();
626
                        jTxtMaxCost.setBounds(new Rectangle(190, 112, 95, 20));
627
                }
628
                return jTxtMaxCost;
629
        }
630

    
631
        public WindowInfo getWindowInfo() {
632
                if (wi == null) {
633
                        wi = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE);
634
                        wi.setWidth(345);
635
                        wi.setHeight(345);
636
                        wi.setMinimumSize(new Dimension(345, 345));
637
                        wi.setTitle(PluginServices.getText(this, "connectivity_analisys")
638
                                        + "...");
639
                }
640
                return wi;
641

    
642
        }
643

    
644
        public void setMapControl(MapControl mc) throws ReadDriverException {
645
                this.mapCtrl = mc;
646
                this.lastSelectedTool = mc.getCurrentTool();
647
                SingleLayerIterator it = new SingleLayerIterator(mc.getMapContext()
648
                                .getLayers());
649
                DefaultComboBoxModel model = (DefaultComboBoxModel) getJCboAssociatedLayer()
650
                                .getModel();
651
                model.removeAllElements();
652
                model.addElement(PluginServices.getText(this, "none"));
653
                while (it.hasNext()) {
654
                        FLayer aux = it.next();
655
                        if (aux instanceof FLyrVect) {
656
                                FLyrVect lv = (FLyrVect) aux;
657
                                if (lv.getShapeType() == FShape.POINT) {
658
                                        model.addElement(lv.getName());
659
                                }
660
                                if (!aux.isActive())
661
                                        continue;
662
                                Network net = (Network) aux.getProperty("network");
663
                                if (net != null) {
664
                                        GvFlag[] flags = net.getFlags(); 
665
                                        if (flags.length == 1) {
666
                                                NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
667
                                                nf.setGroupingUsed(false);
668
                                                nf.setMaximumFractionDigits(6);
669
                                                String auxX = nf.format(flags[0].getOriginalPoint().getX());
670
                                                String auxY = nf.format(flags[0].getOriginalPoint().getY());
671
                                                getJTxtOriginPointX().setText(auxX);
672
                                                getJTxtOriginPointY().setText(auxY);
673
                                        }
674
                                }
675
                                
676
                        }
677
                }
678
        }
679

    
680
        public Object getWindowProfile() {
681
                // TODO Auto-generated method stub
682
                return null;
683
        }
684

    
685
        public void windowActivated() {
686
                // TODO Auto-generated method stub
687
                
688
        }
689

    
690
        public void windowClosed() {
691
                this.mapCtrl.setTool(lastSelectedTool);
692
                
693
        }
694

    
695
        public void flagsChanged(int reason) {
696
                if (reason == IFlagListener.FLAG_ADDED) {
697
                        MapContext map = mapCtrl.getMapContext();
698
                        SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
699
                        FLyrVect layer = null;
700

    
701
                        while (it.hasNext()) {
702
                                FLayer aux = it.next();
703
                                if (!aux.isActive())
704
                                        continue;
705
                                Network net = (Network) aux.getProperty("network");
706
                                if (net != null) {
707
                                        GvFlag[] flags = net.getFlags(); 
708
                                        if (flags.length == 1) {
709
                                                NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
710
                                                nf.setGroupingUsed(false);
711
                                                nf.setMaximumFractionDigits(6);
712
                                                String auxX = nf.format(flags[0].getOriginalPoint().getX());
713
                                                String auxY = nf.format(flags[0].getOriginalPoint().getY());
714
                                                getJTxtOriginPointX().setText(auxX);
715
                                                getJTxtOriginPointY().setText(auxY);
716
                                        }
717
                                }
718
                        } // while
719
                }
720
                
721
        }
722

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