Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / ConnectivityControlPanel.java @ 30840

History | View | Annotate | Download (22.8 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(_T("Associated_layer") + ":");
179
                        jLblOriginPoint = new JLabel();
180
                        jLblOriginPoint.setBounds(new Rectangle(15, 17, 111, 14));
181
                        jLblOriginPoint.setText(_T("Origin_point") + ":");
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(_T("Calculate"));
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
                try {                        
458
                        if (getJChkBoxUseMaxCost().isSelected()) {
459
                                solver.setMaxCost(Double.parseDouble(getJTxtMaxCost().getText()));
460
                        }
461
                        if (getJChkBoxUseMaxDist().isSelected()) {
462
                                solver.setMaxDistance(Double
463
                                                .parseDouble(getJTxtMaxDist().getText()));
464
                        }
465
                }
466
                catch (NumberFormatException e) {
467
                        JOptionPane.showMessageDialog(this, PluginServices.getText(this,
468
                                        "error_parsering_number:") + e.getMessage());
469
                        return;
470
                }
471
                solver.addListener(selectListener);
472

    
473
                try {
474
                        double x = Double.parseDouble(getJTxtOriginPointX().getText());
475
                        double y = Double.parseDouble(getJTxtOriginPointY().getText());
476
                        double tol = mapCtrl.getViewPort().toMapDistance(FlagListener.pixelTolerance);
477
                        sourceFlag = net.createFlag(x, y, tol);
478
                        if (sourceFlag == null) {
479
                                JOptionPane.showMessageDialog(this, _T("Error positioning point on network."));
480
                                return;                                
481
                        }
482
                        solver.setSourceFlag(sourceFlag);
483
                }
484
                catch (NumberFormatException e) {
485
                        JOptionPane.showMessageDialog(this, _T("Error in origin coordinates:" + e.getMessage()));
486
                        return;
487
                }
488
                long t1 = System.currentTimeMillis();
489
                solver.putDestinationsOnNetwork(net.getFlags());
490
                solver.calculate();
491
                solver.removeDestinationsFromNetwork(net.getFlags());
492
                long t2 = System.currentTimeMillis();
493
                System.out.println("tiempo:" + (t2 - t1));
494

    
495
                GvFlag flags[] = net.getFlags();
496

    
497
                for (int i = 0; i < flags.length; i++) {
498
                        System.out.println("Flag " + i + " " + flags[i].getCost());
499
                }
500
        }
501

    
502
        /**
503
         * This method initializes jBtnClose
504
         * 
505
         * @return javax.swing.JButton
506
         */
507
        private JButton getJBtnClose() {
508
                if (jBtnClose == null) {
509
                        jBtnClose = new JButton();
510
                        jBtnClose.setText("Cerrar");
511
                        jBtnClose.addActionListener(new ActionListener() {
512

    
513
                                public void actionPerformed(ActionEvent e) {
514
                                        close();
515
                                }
516

    
517
                        });
518
                }
519
                return jBtnClose;
520
        }
521

    
522
        protected void close() {
523
                PluginServices.getMDIManager().closeWindow(this);
524
        }
525

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

    
553
        /**
554
         * This method initializes jRadioBtnNormalDirection
555
         * 
556
         * @return javax.swing.JRadioButton
557
         */
558
        private JRadioButton getJRadioBtnNormalDirection() {
559
                if (jRadioBtnNormalDirection == null) {
560
                        jRadioBtnNormalDirection = new JRadioButton();
561
                        jRadioBtnNormalDirection.setBounds(new Rectangle(15, 25, 200, 21));
562
                        jRadioBtnNormalDirection.setSelected(true);
563
                        jRadioBtnNormalDirection.setText(_T("Normal_direction"));
564
                }
565
                return jRadioBtnNormalDirection;
566
        }
567

    
568
        /**
569
         * This method initializes jRadioBtnReverseDirection
570
         * 
571
         * @return javax.swing.JRadioButton
572
         */
573
        private JRadioButton getJRadioBtnReverseDirection() {
574
                if (jRadioBtnReverseDirection == null) {
575
                        jRadioBtnReverseDirection = new JRadioButton();
576
                        jRadioBtnReverseDirection.setBounds(new Rectangle(15, 53, 180, 23));
577
                        jRadioBtnReverseDirection.setText(_T("Reverse_direction"));
578
                        jRadioBtnReverseDirection.setSelected(false);
579
                }
580
                return jRadioBtnReverseDirection;
581
        }
582

    
583
        /**
584
         * This method initializes jChkBoxUseMaxDist
585
         * 
586
         * @return javax.swing.JCheckBox
587
         */
588
        private JCheckBox getJChkBoxUseMaxDist() {
589
                if (jChkBoxUseMaxDist == null) {
590
                        jChkBoxUseMaxDist = new JCheckBox();
591
                        jChkBoxUseMaxDist.setBounds(new Rectangle(15, 85, 168, 21));
592
                        jChkBoxUseMaxDist.setText(_T("Use_max_distance") + ":");
593
                }
594
                return jChkBoxUseMaxDist;
595
        }
596

    
597
        /**
598
         * This method initializes jChkBoxUseMaxCost
599
         * 
600
         * @return javax.swing.JCheckBox
601
         */
602
        private JCheckBox getJChkBoxUseMaxCost() {
603
                if (jChkBoxUseMaxCost == null) {
604
                        jChkBoxUseMaxCost = new JCheckBox();
605
                        jChkBoxUseMaxCost.setBounds(new Rectangle(15, 112, 167, 23));
606
                        jChkBoxUseMaxCost.setText(_T("Use_max_cost") + ":");
607
                }
608
                return jChkBoxUseMaxCost;
609
        }
610

    
611
        /**
612
         * This method initializes jTxtMaxDist
613
         * 
614
         * @return javax.swing.JTextField
615
         */
616
        private JTextField getJTxtMaxDist() {
617
                if (jTxtMaxDist == null) {
618
                        jTxtMaxDist = new JTextField();
619
                        jTxtMaxDist.setBounds(new Rectangle(190, 86, 95, 20));
620
                }
621
                return jTxtMaxDist;
622
        }
623

    
624
        /**
625
         * This method initializes jTxtMaxCost
626
         * 
627
         * @return javax.swing.JTextField
628
         */
629
        private JTextField getJTxtMaxCost() {
630
                if (jTxtMaxCost == null) {
631
                        jTxtMaxCost = new JTextField();
632
                        jTxtMaxCost.setBounds(new Rectangle(190, 112, 95, 20));
633
                }
634
                return jTxtMaxCost;
635
        }
636

    
637
        public WindowInfo getWindowInfo() {
638
                if (wi == null) {
639
                        wi = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE);
640
                        wi.setWidth(345);
641
                        wi.setHeight(345);
642
                        wi.setMinimumSize(new Dimension(345, 345));
643
                        wi.setTitle(PluginServices.getText(this, "connectivity_analysis")
644
                                        + "...");
645
                }
646
                return wi;
647

    
648
        }
649

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

    
686
        public Object getWindowProfile() {
687
                // TODO Auto-generated method stub
688
                return null;
689
        }
690

    
691
        public void windowActivated() {
692
                // TODO Auto-generated method stub
693
                
694
        }
695

    
696
        public void windowClosed() {
697
                this.mapCtrl.setTool(lastSelectedTool);
698
                
699
        }
700

    
701
        public void flagsChanged(int reason) {
702
                if (reason == IFlagListener.FLAG_ADDED) {
703
                        MapContext map = mapCtrl.getMapContext();
704
                        SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
705
                        FLyrVect layer = null;
706

    
707
                        while (it.hasNext()) {
708
                                FLayer aux = it.next();
709
                                if (!aux.isActive())
710
                                        continue;
711
                                Network net = (Network) aux.getProperty("network");
712
                                if (net != null) {
713
                                        GvFlag[] flags = net.getFlags(); 
714
                                        if (flags.length == 1) {
715
                                                NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
716
                                                nf.setGroupingUsed(false);
717
                                                nf.setMaximumFractionDigits(6);
718
                                                String auxX = nf.format(flags[0].getOriginalPoint().getX());
719
                                                String auxY = nf.format(flags[0].getOriginalPoint().getY());
720
                                                getJTxtOriginPointX().setText(auxX);
721
                                                getJTxtOriginPointY().setText(auxY);
722
                                        }
723
                                }
724
                        } // while
725
                }
726
                
727
        }
728
        private String _T(String str) {
729
                return PluginServices.getText(this, str);
730
        }
731

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