svn-gvsig-desktop / trunk / extensions / extGraph / src / org / gvsig / graph / gui / ConnectivityControlPanel.java @ 39203
History | View | Annotate | Download (24 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.Component; |
33 |
import java.awt.Dimension; |
34 |
import java.awt.Font; |
35 |
import java.awt.GridBagConstraints; |
36 |
import java.awt.GridBagLayout; |
37 |
import java.awt.Insets; |
38 |
import java.awt.Point; |
39 |
import java.awt.Rectangle; |
40 |
import java.awt.SystemColor; |
41 |
import java.awt.event.ActionEvent; |
42 |
import java.awt.event.ActionListener; |
43 |
import java.awt.event.ItemEvent; |
44 |
import java.awt.event.ItemListener; |
45 |
import java.text.NumberFormat; |
46 |
import java.util.Locale; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.ButtonGroup; |
50 |
import javax.swing.DefaultComboBoxModel; |
51 |
import javax.swing.ImageIcon; |
52 |
import javax.swing.JButton; |
53 |
import javax.swing.JCheckBox; |
54 |
import javax.swing.JComboBox; |
55 |
import javax.swing.JLabel; |
56 |
import javax.swing.JOptionPane; |
57 |
import javax.swing.JPanel; |
58 |
import javax.swing.JRadioButton; |
59 |
import javax.swing.JTextArea; |
60 |
import javax.swing.JTextField; |
61 |
import javax.swing.JToggleButton; |
62 |
import javax.swing.border.EtchedBorder; |
63 |
import javax.swing.border.TitledBorder; |
64 |
|
65 |
import org.gvsig.exceptions.BaseException; |
66 |
import org.gvsig.graph.core.GraphException; |
67 |
import org.gvsig.graph.core.GvFlag; |
68 |
import org.gvsig.graph.core.IFlagListener; |
69 |
import org.gvsig.graph.core.Network; |
70 |
import org.gvsig.graph.core.NetworkUtils; |
71 |
import org.gvsig.graph.solvers.IDijkstraListener; |
72 |
import org.gvsig.graph.solvers.OneToManySolver; |
73 |
import org.gvsig.graph.solvers.ReverseOneToManySolver; |
74 |
import org.gvsig.graph.solvers.SelectDijkstraListener; |
75 |
import org.gvsig.graph.tools.FlagListener; |
76 |
import org.gvsig.graph.tools.SingleFlagListener; |
77 |
|
78 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
79 |
import com.iver.andami.PluginServices; |
80 |
import com.iver.andami.ui.mdiManager.IWindow; |
81 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
82 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
83 |
import com.iver.cit.gvsig.fmap.MapContext; |
84 |
import com.iver.cit.gvsig.fmap.MapControl; |
85 |
import com.iver.cit.gvsig.fmap.core.FShape; |
86 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
87 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
88 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
89 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
90 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
91 |
|
92 |
public class ConnectivityControlPanel extends JPanel implements IWindow, |
93 |
IWindowListener, IFlagListener { |
94 |
|
95 |
private static final long serialVersionUID = 1L; |
96 |
private JPanel jPanelSouth = null; |
97 |
private JPanel jPanelCenter = null; |
98 |
private JPanel jPanelNorth = null; |
99 |
private JLabel jLblConnectivity = null; |
100 |
private JLabel jLblIcon = null; |
101 |
private JTextArea jTextArea = null; |
102 |
private JLabel jLblOriginPoint = null; |
103 |
private JTextField jTxtOriginPointX = null; |
104 |
private JTextField jTxtOriginPointY = null; |
105 |
|
106 |
private JToggleButton jToggleButtonSetFlag = null; |
107 |
private JLabel jLblAssociatedLayer = null; |
108 |
private JComboBox jCboAssociatedLayer = null; |
109 |
private JButton jBtnCalculate = null; |
110 |
private JButton jBtnClose = null; |
111 |
private JPanel jPanelOptions = null; |
112 |
private JRadioButton jRadioBtnNormalDirection = null; |
113 |
private JRadioButton jRadioBtnReverseDirection = null; |
114 |
private JCheckBox jChkBoxUseMaxDist = null; |
115 |
private JCheckBox jChkBoxUseMaxCost = null; |
116 |
private JTextField jTxtMaxDist = null; |
117 |
private JTextField jTxtMaxCost = null; |
118 |
private WindowInfo wi;
|
119 |
private MapControl mapCtrl;
|
120 |
|
121 |
private SelectDijkstraListener selectListener;
|
122 |
private GvFlag sourceFlag;
|
123 |
protected SingleFlagListener flagListener;
|
124 |
private String lastSelectedTool; |
125 |
private JLabel jLblTolerance = null; |
126 |
private JTextField jTxtTolerance = null; |
127 |
|
128 |
/**
|
129 |
* This is the default constructor
|
130 |
*/
|
131 |
public ConnectivityControlPanel() {
|
132 |
super();
|
133 |
initialize(); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* This method initializes this
|
138 |
*
|
139 |
* @return void
|
140 |
*/
|
141 |
private void initialize() { |
142 |
this.setSize(343, 406); |
143 |
this.setLayout(new BorderLayout()); |
144 |
this.add(getJPanelNorth(), BorderLayout.NORTH); |
145 |
this.add(getJPanelSouth(), BorderLayout.SOUTH); |
146 |
this.add(getJPanelCenter(), BorderLayout.CENTER); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* This method initializes jPanelSouth
|
151 |
*
|
152 |
* @return javax.swing.JPanel
|
153 |
*/
|
154 |
private JPanel getJPanelSouth() { |
155 |
if (jPanelSouth == null) { |
156 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
157 |
gridBagConstraints.gridx = 1;
|
158 |
gridBagConstraints.gridy = 0;
|
159 |
jPanelSouth = new JPanel(); |
160 |
jPanelSouth.setLayout(new GridBagLayout()); |
161 |
jPanelSouth.setPreferredSize(new Dimension(134, 30)); |
162 |
jPanelSouth.add(getJBtnCalculate(), new GridBagConstraints()); |
163 |
jPanelSouth.add(getJBtnClose(), gridBagConstraints); |
164 |
} |
165 |
return jPanelSouth;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* This method initializes jPanelCenter
|
170 |
*
|
171 |
* @return javax.swing.JPanel
|
172 |
*/
|
173 |
private JPanel getJPanelCenter() { |
174 |
if (jPanelCenter == null) { |
175 |
jLblTolerance = new JLabel(); |
176 |
jLblTolerance.setBounds(new Rectangle(17, 90, 76, 19)); |
177 |
jLblTolerance.setText(_T("Tolerance") + ":"); |
178 |
jLblAssociatedLayer = new JLabel(); |
179 |
jLblAssociatedLayer.setBounds(new Rectangle(15, 57, 111, 14)); |
180 |
jLblAssociatedLayer.setText(_T("Associated_layer") + ":"); |
181 |
jLblOriginPoint = new JLabel(); |
182 |
jLblOriginPoint.setBounds(new Rectangle(15, 17, 111, 14)); |
183 |
jLblOriginPoint.setText(_T("Origin_point") + ":"); |
184 |
jPanelCenter = new JPanel(); |
185 |
jPanelCenter.setLayout(null);
|
186 |
jPanelCenter.add(jLblOriginPoint, null);
|
187 |
|
188 |
JLabel jLblX = new JLabel(); |
189 |
jLblX.setBounds(new Rectangle(118, 2, 111, 14)); |
190 |
jLblX.setText("X:");
|
191 |
JLabel jLblY = new JLabel(); |
192 |
jLblY.setBounds(new Rectangle(218, 2, 111, 14)); |
193 |
jLblY.setText("Y:");
|
194 |
|
195 |
jPanelCenter.add(jLblX, null);
|
196 |
jPanelCenter.add(jLblY, null);
|
197 |
|
198 |
jPanelCenter.add(getJTxtOriginPointX(), null);
|
199 |
jPanelCenter.add(getJTxtOriginPointY(), null);
|
200 |
jPanelCenter.add(getJToggleButtonSetFlag(), null);
|
201 |
jPanelCenter.add(jLblAssociatedLayer, null);
|
202 |
jPanelCenter.add(getJCboAssociatedLayer(), null);
|
203 |
jPanelCenter.add(getJPanelOptions(), null);
|
204 |
jPanelCenter.add(jLblTolerance, null);
|
205 |
jPanelCenter.add(getJTxtTolerance(), null);
|
206 |
} |
207 |
return jPanelCenter;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* This method initializes jPanelNorth
|
212 |
*
|
213 |
* @return javax.swing.JPanel
|
214 |
*/
|
215 |
private JPanel getJPanelNorth() { |
216 |
if (jPanelNorth == null) { |
217 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
218 |
gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
|
219 |
gridBagConstraints1.gridx = 0;
|
220 |
gridBagConstraints1.anchor = GridBagConstraints.SOUTHWEST;
|
221 |
gridBagConstraints1.weightx = 1.0D;
|
222 |
gridBagConstraints1.insets = new Insets(2, 5, 0, 0); |
223 |
gridBagConstraints1.gridy = 1;
|
224 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
225 |
gridBagConstraints2.gridx = 1;
|
226 |
gridBagConstraints2.anchor = GridBagConstraints.EAST;
|
227 |
gridBagConstraints2.gridy = 1;
|
228 |
jLblIcon = new JLabel(); |
229 |
jLblIcon.setText("");
|
230 |
jLblIcon.setIcon(new ImageIcon(this.getClass().getClassLoader() |
231 |
.getResource("images/wizard_connectivity.png")));
|
232 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
233 |
gridBagConstraints.gridx = 0;
|
234 |
gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
|
235 |
gridBagConstraints.gridwidth = 1;
|
236 |
gridBagConstraints.ipadx = 7;
|
237 |
gridBagConstraints.gridheight = 0;
|
238 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
239 |
gridBagConstraints.insets = new Insets(2, 5, 0, 0); |
240 |
gridBagConstraints.ipady = 3;
|
241 |
gridBagConstraints.weightx = 1.0D;
|
242 |
gridBagConstraints.gridy = 0;
|
243 |
jLblConnectivity = new JLabel(); |
244 |
jLblConnectivity.setText(PluginServices.getText(this,
|
245 |
"connectivity"));
|
246 |
jLblConnectivity.setFont(new Font("Dialog", Font.BOLD, 14)); |
247 |
jPanelNorth = new JPanel(); |
248 |
jPanelNorth.setLayout(new GridBagLayout()); |
249 |
jPanelNorth.setPreferredSize(new Dimension(0, 70)); |
250 |
jPanelNorth.setBackground(SystemColor.text);
|
251 |
jPanelNorth.setBorder(BorderFactory
|
252 |
.createEtchedBorder(EtchedBorder.LOWERED));
|
253 |
jPanelNorth.add(jLblConnectivity, gridBagConstraints); |
254 |
jPanelNorth.add(jLblIcon, gridBagConstraints2); |
255 |
jPanelNorth.add(getJTextArea(), gridBagConstraints1); |
256 |
} |
257 |
return jPanelNorth;
|
258 |
} |
259 |
|
260 |
private JTextArea getJTextArea() { |
261 |
if (jTextArea == null) { |
262 |
jTextArea = new JTextArea(); |
263 |
jTextArea.setPreferredSize(new Dimension(100, 40)); |
264 |
jTextArea.setText(PluginServices.getText(this, "connectivity_analysis")); |
265 |
jTextArea.setEditable(false);
|
266 |
jTextArea.setLineWrap(true);
|
267 |
} |
268 |
return jTextArea;
|
269 |
} |
270 |
|
271 |
private JTextField getJTxtOriginPointX() { |
272 |
if (jTxtOriginPointX == null) { |
273 |
jTxtOriginPointX = new JTextField(); |
274 |
jTxtOriginPointX.setBounds(new Rectangle(112, 16, 92, 20)); |
275 |
jTxtOriginPointX.setHorizontalAlignment(JTextField.RIGHT);
|
276 |
|
277 |
} |
278 |
return jTxtOriginPointX;
|
279 |
} |
280 |
|
281 |
private JTextField getJTxtOriginPointY() { |
282 |
if (jTxtOriginPointY == null) { |
283 |
jTxtOriginPointY = new JTextField(); |
284 |
jTxtOriginPointY.setBounds(new Rectangle(216, 16, 92, 20)); |
285 |
jTxtOriginPointY.setHorizontalAlignment(JTextField.RIGHT);
|
286 |
} |
287 |
return jTxtOriginPointY;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* This method initializes jToggleButtonSetFlag
|
292 |
*
|
293 |
* @return javax.swing.JToggleButton
|
294 |
*/
|
295 |
private JToggleButton getJToggleButtonSetFlag() { |
296 |
if (jToggleButtonSetFlag == null) { |
297 |
jToggleButtonSetFlag = new JToggleButton(); |
298 |
jToggleButtonSetFlag.setIcon(new ImageIcon(this.getClass() |
299 |
.getClassLoader().getResource( |
300 |
"images/disconnect_co_004.gif")));
|
301 |
jToggleButtonSetFlag.setSize(new Dimension(22, 22)); |
302 |
jToggleButtonSetFlag.setLocation(new Point(311, 16)); |
303 |
jToggleButtonSetFlag.setToolTipText(PluginServices.getText(this, "set_source_flag")); |
304 |
ItemListener itemListener = new ItemListener() { |
305 |
public void itemStateChanged(ItemEvent itemEvent) { |
306 |
int state = itemEvent.getStateChange();
|
307 |
if (state == ItemEvent.SELECTED) { |
308 |
doSelectTool(); |
309 |
} else {
|
310 |
System.out.println("Deselected"); |
311 |
} |
312 |
} |
313 |
}; |
314 |
// Attach Listeners
|
315 |
jToggleButtonSetFlag.addItemListener(itemListener); |
316 |
} |
317 |
return jToggleButtonSetFlag;
|
318 |
} |
319 |
|
320 |
protected void doSelectTool() { |
321 |
System.out.println("Selected"); |
322 |
if (!mapCtrl.hasTool("addSingleFlag")) // We create it for the first time. |
323 |
{ |
324 |
flagListener = new SingleFlagListener(mapCtrl);
|
325 |
flagListener.setMode(FlagListener.TO_ARC); |
326 |
mapCtrl.addMapTool("addSingleFlag", new PointBehavior(flagListener)); |
327 |
} |
328 |
MapContext map = mapCtrl.getMapContext(); |
329 |
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
330 |
FLyrVect layer = null;
|
331 |
|
332 |
while (it.hasNext()) {
|
333 |
FLayer aux = it.next(); |
334 |
if (!aux.isActive())
|
335 |
continue;
|
336 |
Network net = (Network) aux.getProperty("network");
|
337 |
if (net != null) { |
338 |
net.addFlagListener(this);
|
339 |
} |
340 |
} |
341 |
|
342 |
mapCtrl.setTool("addSingleFlag");
|
343 |
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* This method initializes jCboAssociatedLayer
|
348 |
*
|
349 |
* @return javax.swing.JComboBox
|
350 |
*/
|
351 |
private JComboBox getJCboAssociatedLayer() { |
352 |
if (jCboAssociatedLayer == null) { |
353 |
jCboAssociatedLayer = new JComboBox(); |
354 |
jCboAssociatedLayer.setBounds(new Rectangle(112, 54, 192, 20)); |
355 |
} |
356 |
return jCboAssociatedLayer;
|
357 |
} |
358 |
|
359 |
/**
|
360 |
* This method initializes jBtnCalculate
|
361 |
*
|
362 |
* @return javax.swing.JButton
|
363 |
*/
|
364 |
private JButton getJBtnCalculate() { |
365 |
if (jBtnCalculate == null) { |
366 |
jBtnCalculate = new JButton(); |
367 |
jBtnCalculate.setText(_T("Calculate"));
|
368 |
jBtnCalculate.addActionListener(new ActionListener() { |
369 |
public void actionPerformed(ActionEvent e) { |
370 |
doConnectivityAnalisys(); |
371 |
} |
372 |
}); |
373 |
|
374 |
} |
375 |
return jBtnCalculate;
|
376 |
} |
377 |
|
378 |
protected void doConnectivityAnalisys() { |
379 |
MapContext map = mapCtrl.getMapContext(); |
380 |
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
381 |
FLyrVect layer = null;
|
382 |
|
383 |
while (it.hasNext()) {
|
384 |
FLayer aux = it.next(); |
385 |
if (!aux.isActive())
|
386 |
continue;
|
387 |
Network net = (Network) aux.getProperty("network");
|
388 |
if (net != null) { |
389 |
GvFlag[] flags = null; |
390 |
if (getJCboAssociatedLayer().getSelectedIndex() != 0) { |
391 |
// use associated layer to put flags.
|
392 |
String layerName = (String) getJCboAssociatedLayer() |
393 |
.getSelectedItem(); |
394 |
layer = (FLyrVect) map.getLayers().getLayer( |
395 |
layerName); |
396 |
|
397 |
double tolerance = Double.parseDouble(getJTxtTolerance().getText()); |
398 |
|
399 |
try {
|
400 |
PluginServices.getMainFrame().getStatusBar().setInfoText(_T("putting_flags_on_network"));
|
401 |
PluginServices.getMDIManager().setWaitCursor(); |
402 |
flags = NetworkUtils.putFlagsOnNetwork(layer, net, |
403 |
tolerance); |
404 |
PluginServices.getMDIManager().restoreCursor(); |
405 |
PluginServices.getMainFrame().getStatusBar().setInfoText(_T("ready"));
|
406 |
} catch (BaseException e) {
|
407 |
PluginServices.getMDIManager().restoreCursor(); |
408 |
// TODO Auto-generated catch block
|
409 |
e.printStackTrace(); |
410 |
JOptionPane.showMessageDialog((Component) PluginServices.getMDIManager().getActiveWindow(), |
411 |
e.getMessage()); |
412 |
return;
|
413 |
} |
414 |
} |
415 |
selectListener = new SelectDijkstraListener(net, mapCtrl
|
416 |
.getMapContext()); |
417 |
selectListener.startSelection(); |
418 |
try {
|
419 |
net.getLayer().getRecordset().clearSelection(); |
420 |
if (layer != null) |
421 |
layer.getRecordset().clearSelection(); |
422 |
|
423 |
if (getJRadioBtnNormalDirection().isSelected()) {
|
424 |
OneToManySolver solver = new OneToManySolver();
|
425 |
doSolve(net, selectListener, solver); |
426 |
} |
427 |
else {
|
428 |
ReverseOneToManySolver solver = new ReverseOneToManySolver();
|
429 |
doSolve(net, selectListener, solver); |
430 |
} |
431 |
// if (flags != null)
|
432 |
// for (int i=0; i < flags.length; i++)
|
433 |
// net.removeFlag(flags[i]);
|
434 |
} catch (GraphException e) {
|
435 |
// TODO Auto-generated catch block
|
436 |
e.printStackTrace(); |
437 |
} catch (ReadDriverException e) {
|
438 |
// TODO Auto-generated catch block
|
439 |
e.printStackTrace(); |
440 |
} |
441 |
selectListener.stopSelection(); |
442 |
if (flags != null) { |
443 |
for (int i = 0; i < flags.length; i++) { |
444 |
if (flags[i].getCost() != -1) { |
445 |
Integer index = (Integer) flags[i].getProperties().get("rec"); |
446 |
FBitSet bs; |
447 |
try {
|
448 |
bs = layer.getRecordset().getSelection(); |
449 |
bs.set(index.intValue()); |
450 |
} catch (ReadDriverException e) {
|
451 |
// TODO Auto-generated catch block
|
452 |
e.printStackTrace(); |
453 |
} |
454 |
} |
455 |
} |
456 |
} |
457 |
mapCtrl.drawMap(true);
|
458 |
PluginServices.getMainFrame().enableControls(); |
459 |
} |
460 |
} // WHILE
|
461 |
} |
462 |
|
463 |
|
464 |
private void doSolve(Network net, IDijkstraListener selectListener, OneToManySolver solver) |
465 |
throws GraphException {
|
466 |
|
467 |
solver.setNetwork(net); |
468 |
solver.addListener(selectListener); |
469 |
try {
|
470 |
if (getJChkBoxUseMaxCost().isSelected()) {
|
471 |
solver.setMaxCost(Double.parseDouble(getJTxtMaxCost().getText()));
|
472 |
} |
473 |
if (getJChkBoxUseMaxDist().isSelected()) {
|
474 |
solver.setMaxDistance(Double
|
475 |
.parseDouble(getJTxtMaxDist().getText())); |
476 |
} |
477 |
} |
478 |
catch (NumberFormatException e) { |
479 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, |
480 |
"error_parsering_number:") + e.getMessage());
|
481 |
return;
|
482 |
} |
483 |
solver.addListener(selectListener); |
484 |
|
485 |
try {
|
486 |
double x = Double.parseDouble(getJTxtOriginPointX().getText()); |
487 |
double y = Double.parseDouble(getJTxtOriginPointY().getText()); |
488 |
double tol = mapCtrl.getViewPort().toMapDistance(FlagListener.pixelTolerance);
|
489 |
sourceFlag = net.createFlag(x, y, tol); |
490 |
if (sourceFlag == null) { |
491 |
JOptionPane.showMessageDialog(this, _T("Error positioning point on network.")); |
492 |
return;
|
493 |
} |
494 |
solver.setSourceFlag(sourceFlag); |
495 |
} |
496 |
catch (NumberFormatException e) { |
497 |
JOptionPane.showMessageDialog(this, _T("Error in origin coordinates:" + e.getMessage())); |
498 |
return;
|
499 |
} |
500 |
long t1 = System.currentTimeMillis(); |
501 |
solver.putDestinationsOnNetwork(net.getFlags()); |
502 |
solver.calculate(); |
503 |
solver.removeDestinationsFromNetwork(net.getFlags()); |
504 |
long t2 = System.currentTimeMillis(); |
505 |
System.out.println("tiempo:" + (t2 - t1)); |
506 |
|
507 |
GvFlag flags[] = net.getFlags();
|
508 |
|
509 |
for (int i = 0; i < flags.length; i++) { |
510 |
System.out.println("Flag " + i + " " + flags[i].getCost()); |
511 |
} |
512 |
} |
513 |
|
514 |
/**
|
515 |
* This method initializes jBtnClose
|
516 |
*
|
517 |
* @return javax.swing.JButton
|
518 |
*/
|
519 |
private JButton getJBtnClose() { |
520 |
if (jBtnClose == null) { |
521 |
jBtnClose = new JButton(); |
522 |
jBtnClose.setText(_T("Close"));
|
523 |
jBtnClose.addActionListener(new ActionListener() { |
524 |
|
525 |
public void actionPerformed(ActionEvent e) { |
526 |
close(); |
527 |
} |
528 |
|
529 |
}); |
530 |
} |
531 |
return jBtnClose;
|
532 |
} |
533 |
|
534 |
protected void close() { |
535 |
PluginServices.getMDIManager().closeWindow(this);
|
536 |
} |
537 |
|
538 |
/**
|
539 |
* This method initializes jPanelOptions
|
540 |
*
|
541 |
* @return javax.swing.JPanel
|
542 |
*/
|
543 |
private JPanel getJPanelOptions() { |
544 |
if (jPanelOptions == null) { |
545 |
jPanelOptions = new JPanel(); |
546 |
jPanelOptions.setLayout(null);
|
547 |
jPanelOptions.setBounds(new Rectangle(14, 135, 315, 154)); |
548 |
jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, |
549 |
_T("Options"), TitledBorder.DEFAULT_JUSTIFICATION, |
550 |
TitledBorder.DEFAULT_POSITION, new Font("Tahoma", |
551 |
Font.PLAIN, 11), Color.black)); |
552 |
ButtonGroup group = new ButtonGroup(); |
553 |
group.add(getJRadioBtnNormalDirection()); |
554 |
group.add(getJRadioBtnReverseDirection()); |
555 |
jPanelOptions.add(getJRadioBtnNormalDirection(), null);
|
556 |
jPanelOptions.add(getJRadioBtnReverseDirection(), null);
|
557 |
jPanelOptions.add(getJChkBoxUseMaxDist(), null);
|
558 |
jPanelOptions.add(getJChkBoxUseMaxCost(), null);
|
559 |
jPanelOptions.add(getJTxtMaxDist(), null);
|
560 |
jPanelOptions.add(getJTxtMaxCost(), null);
|
561 |
} |
562 |
return jPanelOptions;
|
563 |
} |
564 |
|
565 |
/**
|
566 |
* This method initializes jRadioBtnNormalDirection
|
567 |
*
|
568 |
* @return javax.swing.JRadioButton
|
569 |
*/
|
570 |
private JRadioButton getJRadioBtnNormalDirection() { |
571 |
if (jRadioBtnNormalDirection == null) { |
572 |
jRadioBtnNormalDirection = new JRadioButton(); |
573 |
jRadioBtnNormalDirection.setBounds(new Rectangle(15, 25, 200, 21)); |
574 |
jRadioBtnNormalDirection.setSelected(true);
|
575 |
jRadioBtnNormalDirection.setText(_T("Normal_direction"));
|
576 |
} |
577 |
return jRadioBtnNormalDirection;
|
578 |
} |
579 |
|
580 |
/**
|
581 |
* This method initializes jRadioBtnReverseDirection
|
582 |
*
|
583 |
* @return javax.swing.JRadioButton
|
584 |
*/
|
585 |
private JRadioButton getJRadioBtnReverseDirection() { |
586 |
if (jRadioBtnReverseDirection == null) { |
587 |
jRadioBtnReverseDirection = new JRadioButton(); |
588 |
jRadioBtnReverseDirection.setBounds(new Rectangle(15, 53, 180, 23)); |
589 |
jRadioBtnReverseDirection.setText(_T("Reverse_direction"));
|
590 |
jRadioBtnReverseDirection.setSelected(false);
|
591 |
} |
592 |
return jRadioBtnReverseDirection;
|
593 |
} |
594 |
|
595 |
/**
|
596 |
* This method initializes jChkBoxUseMaxDist
|
597 |
*
|
598 |
* @return javax.swing.JCheckBox
|
599 |
*/
|
600 |
private JCheckBox getJChkBoxUseMaxDist() { |
601 |
if (jChkBoxUseMaxDist == null) { |
602 |
jChkBoxUseMaxDist = new JCheckBox(); |
603 |
jChkBoxUseMaxDist.setBounds(new Rectangle(15, 85, 168, 21)); |
604 |
jChkBoxUseMaxDist.setText(_T("Use_max_distance") + ":"); |
605 |
} |
606 |
return jChkBoxUseMaxDist;
|
607 |
} |
608 |
|
609 |
/**
|
610 |
* This method initializes jChkBoxUseMaxCost
|
611 |
*
|
612 |
* @return javax.swing.JCheckBox
|
613 |
*/
|
614 |
private JCheckBox getJChkBoxUseMaxCost() { |
615 |
if (jChkBoxUseMaxCost == null) { |
616 |
jChkBoxUseMaxCost = new JCheckBox(); |
617 |
jChkBoxUseMaxCost.setBounds(new Rectangle(15, 112, 167, 23)); |
618 |
jChkBoxUseMaxCost.setText(_T("Use_max_cost") + ":"); |
619 |
} |
620 |
return jChkBoxUseMaxCost;
|
621 |
} |
622 |
|
623 |
/**
|
624 |
* This method initializes jTxtMaxDist
|
625 |
*
|
626 |
* @return javax.swing.JTextField
|
627 |
*/
|
628 |
private JTextField getJTxtMaxDist() { |
629 |
if (jTxtMaxDist == null) { |
630 |
jTxtMaxDist = new JTextField(); |
631 |
jTxtMaxDist.setBounds(new Rectangle(190, 86, 95, 20)); |
632 |
} |
633 |
return jTxtMaxDist;
|
634 |
} |
635 |
|
636 |
/**
|
637 |
* This method initializes jTxtMaxCost
|
638 |
*
|
639 |
* @return javax.swing.JTextField
|
640 |
*/
|
641 |
private JTextField getJTxtMaxCost() { |
642 |
if (jTxtMaxCost == null) { |
643 |
jTxtMaxCost = new JTextField(); |
644 |
jTxtMaxCost.setBounds(new Rectangle(190, 112, 95, 20)); |
645 |
} |
646 |
return jTxtMaxCost;
|
647 |
} |
648 |
|
649 |
public WindowInfo getWindowInfo() {
|
650 |
if (wi == null) { |
651 |
wi = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE);
|
652 |
wi.setWidth(365);
|
653 |
wi.setHeight(406);
|
654 |
wi.setMinimumSize(new Dimension(345, 406)); |
655 |
wi.setTitle(PluginServices.getText(this, "connectivity_analysis") |
656 |
+ "...");
|
657 |
} |
658 |
return wi;
|
659 |
|
660 |
} |
661 |
|
662 |
public void setMapControl(MapControl mc) throws ReadDriverException { |
663 |
this.mapCtrl = mc;
|
664 |
this.lastSelectedTool = mc.getCurrentTool();
|
665 |
SingleLayerIterator it = new SingleLayerIterator(mc.getMapContext()
|
666 |
.getLayers()); |
667 |
DefaultComboBoxModel model = (DefaultComboBoxModel) getJCboAssociatedLayer() |
668 |
.getModel(); |
669 |
model.removeAllElements(); |
670 |
model.addElement(PluginServices.getText(this, "none")); |
671 |
while (it.hasNext()) {
|
672 |
FLayer aux = it.next(); |
673 |
if (aux instanceof FLyrVect) { |
674 |
FLyrVect lv = (FLyrVect) aux; |
675 |
if (!lv.isAvailable())
|
676 |
continue;
|
677 |
if (lv.getShapeType() == FShape.POINT) {
|
678 |
model.addElement(lv.getName()); |
679 |
} |
680 |
if (!aux.isActive())
|
681 |
continue;
|
682 |
Network net = (Network) aux.getProperty("network");
|
683 |
if (net != null) { |
684 |
GvFlag[] flags = net.getFlags();
|
685 |
if (flags.length == 1) { |
686 |
NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); |
687 |
nf.setGroupingUsed(false);
|
688 |
nf.setMaximumFractionDigits(6);
|
689 |
String auxX = nf.format(flags[0].getOriginalPoint().getX()); |
690 |
String auxY = nf.format(flags[0].getOriginalPoint().getY()); |
691 |
getJTxtOriginPointX().setText(auxX); |
692 |
getJTxtOriginPointY().setText(auxY); |
693 |
} |
694 |
} |
695 |
|
696 |
} |
697 |
} |
698 |
} |
699 |
|
700 |
public Object getWindowProfile() { |
701 |
// TODO Auto-generated method stub
|
702 |
return null; |
703 |
} |
704 |
|
705 |
public void windowActivated() { |
706 |
// TODO Auto-generated method stub
|
707 |
|
708 |
} |
709 |
|
710 |
public void windowClosed() { |
711 |
this.mapCtrl.setTool(lastSelectedTool);
|
712 |
|
713 |
} |
714 |
|
715 |
public void flagsChanged(int reason) { |
716 |
if (reason == IFlagListener.FLAG_ADDED) {
|
717 |
MapContext map = mapCtrl.getMapContext(); |
718 |
SingleLayerIterator it = new SingleLayerIterator(map.getLayers());
|
719 |
FLyrVect layer = null;
|
720 |
|
721 |
while (it.hasNext()) {
|
722 |
FLayer aux = it.next(); |
723 |
if (!aux.isActive())
|
724 |
continue;
|
725 |
Network net = (Network) aux.getProperty("network");
|
726 |
if (net != null) { |
727 |
GvFlag[] flags = net.getFlags();
|
728 |
if (flags.length == 1) { |
729 |
NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); |
730 |
nf.setGroupingUsed(false);
|
731 |
nf.setMaximumFractionDigits(6);
|
732 |
String auxX = nf.format(flags[0].getOriginalPoint().getX()); |
733 |
String auxY = nf.format(flags[0].getOriginalPoint().getY()); |
734 |
getJTxtOriginPointX().setText(auxX); |
735 |
getJTxtOriginPointY().setText(auxY); |
736 |
} |
737 |
} |
738 |
} // while
|
739 |
} |
740 |
|
741 |
} |
742 |
private String _T(String str) { |
743 |
return PluginServices.getText(this, str); |
744 |
} |
745 |
|
746 |
/**
|
747 |
* This method initializes jTxtTolerance
|
748 |
*
|
749 |
* @return javax.swing.JTextField
|
750 |
*/
|
751 |
private JTextField getJTxtTolerance() { |
752 |
if (jTxtTolerance == null) { |
753 |
jTxtTolerance = new JTextField(); |
754 |
jTxtTolerance.setBounds(new Rectangle(112, 89, 78, 20)); |
755 |
jTxtTolerance.setHorizontalAlignment(JTextField.RIGHT);
|
756 |
jTxtTolerance.setText("10");
|
757 |
} |
758 |
return jTxtTolerance;
|
759 |
} |
760 |
|
761 |
} // @jve:decl-index=0:visual-constraint="10,10"
|