svn-gvsig-desktop / tags / PilotoRedes_Build_4 / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / gui / RouteControlPanel.java @ 12191
History | View | Annotate | Download (34.8 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: RouteControlPanel.java 12191 2007-06-18 10:14:09Z $
|
45 |
* $Log$
|
46 |
* Revision 1.25.2.4 2007-06-14 10:02:25 fjp
|
47 |
* Pliego de redes a publicar SIN el cuadro de di?logo setVelocities (bueno, con , pero invisible)
|
48 |
*
|
49 |
* Revision 1.25.2.3 2007/05/24 11:33:36 fjp
|
50 |
* Para que puedas a?adir los puntos que est?n cerca de la red. Los que no lo est?n, lanzan un error informando de qu? punto no est? cerca de la red.
|
51 |
*
|
52 |
* Revision 1.25.2.2 2007/05/15 07:08:21 fjp
|
53 |
* Para calcular matrices de distancias
|
54 |
*
|
55 |
* Revision 1.25 2006/11/14 18:32:32 fjp
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.24 2006/11/14 16:12:01 fjp
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.23 2006/11/14 09:23:30 fjp
|
62 |
* cargar paradas desde cualquier tema de puntos
|
63 |
*
|
64 |
* Revision 1.22 2006/11/10 13:57:04 fjp
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.21 2006/11/09 21:08:32 azabala
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.20 2006/11/09 12:51:12 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.19 2006/11/09 11:00:43 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.18 2006/11/09 10:59:53 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.17 2006/11/09 10:27:50 fjp
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.16 2006/11/09 10:24:11 fjp
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.15 2006/11/09 09:16:35 fjp
|
86 |
* Ya va!!
|
87 |
*
|
88 |
* Revision 1.14 2006/11/08 20:14:52 azabala
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.13 2006/11/08 19:32:22 azabala
|
92 |
* saveroute and saveflags modifications
|
93 |
*
|
94 |
* Revision 1.12 2006/11/08 18:16:28 fjp
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.11 2006/11/08 16:48:19 fjp
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.10 2006/11/08 16:00:39 fjp
|
101 |
* Por terminar el enlace flags-cuadro de di?logo
|
102 |
*
|
103 |
* Revision 1.9 2006/11/08 13:18:46 fjp
|
104 |
* Por terminar el enlace flags-cuadro de di?logo
|
105 |
*
|
106 |
* Revision 1.8 2006/11/07 19:49:38 azabala
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.7 2006/11/06 13:13:53 azabala
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.6 2006/11/06 10:29:32 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.5 2006/11/03 19:39:29 azabala
|
116 |
* *** empty log message ***
|
117 |
*
|
118 |
* Revision 1.4 2006/10/27 18:26:22 azabala
|
119 |
* added implementation of load stages method
|
120 |
*
|
121 |
* Revision 1.3 2006/10/27 12:41:09 jaume
|
122 |
* GUI
|
123 |
*
|
124 |
* Revision 1.2 2006/10/26 16:31:21 jaume
|
125 |
* GUI
|
126 |
*
|
127 |
* Revision 1.1 2006/10/25 10:50:41 jaume
|
128 |
* movement of classes and gui stuff
|
129 |
*
|
130 |
* Revision 1.4 2006/10/24 08:04:41 jaume
|
131 |
* *** empty log message ***
|
132 |
*
|
133 |
* Revision 1.3 2006/10/23 16:00:20 jaume
|
134 |
* *** empty log message ***
|
135 |
*
|
136 |
* Revision 1.2 2006/10/23 08:05:39 jaume
|
137 |
* GUI
|
138 |
*
|
139 |
* Revision 1.1 2006/10/20 12:02:50 jaume
|
140 |
* GUI
|
141 |
*
|
142 |
*
|
143 |
*/
|
144 |
package com.iver.cit.gvsig.graph.gui; |
145 |
|
146 |
import java.awt.BorderLayout; |
147 |
import java.awt.Component; |
148 |
import java.awt.Dimension; |
149 |
import java.awt.FlowLayout; |
150 |
import java.awt.Font; |
151 |
import java.awt.GridLayout; |
152 |
import java.awt.event.ActionEvent; |
153 |
import java.awt.event.ActionListener; |
154 |
import java.awt.geom.Rectangle2D; |
155 |
import java.text.NumberFormat; |
156 |
import java.util.ArrayList; |
157 |
import java.util.Hashtable; |
158 |
import java.util.List; |
159 |
|
160 |
import javax.swing.ImageIcon; |
161 |
import javax.swing.JComboBox; |
162 |
import javax.swing.JLabel; |
163 |
import javax.swing.JOptionPane; |
164 |
import javax.swing.JPanel; |
165 |
import javax.swing.JScrollPane; |
166 |
import javax.swing.JTable; |
167 |
import javax.swing.ListSelectionModel; |
168 |
import javax.swing.event.ListSelectionEvent; |
169 |
import javax.swing.event.ListSelectionListener; |
170 |
import javax.swing.event.TableModelEvent; |
171 |
import javax.swing.event.TableModelListener; |
172 |
import javax.swing.table.AbstractTableModel; |
173 |
import javax.swing.table.TableColumnModel; |
174 |
import javax.swing.table.TableModel; |
175 |
|
176 |
import org.cresques.cts.IProjection; |
177 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
178 |
import org.gvsig.gui.beans.swing.JBlank; |
179 |
import org.gvsig.gui.beans.swing.JButton; |
180 |
|
181 |
import com.hardcode.gdbms.engine.values.Value; |
182 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
183 |
import com.iver.andami.PluginServices; |
184 |
import com.iver.andami.messages.NotificationManager; |
185 |
import com.iver.andami.ui.mdiManager.IWindow; |
186 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
187 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
188 |
import com.iver.cit.gvsig.fmap.DriverException; |
189 |
import com.iver.cit.gvsig.fmap.MapContext; |
190 |
import com.iver.cit.gvsig.fmap.MapControl; |
191 |
import com.iver.cit.gvsig.fmap.ViewPort; |
192 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
193 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
194 |
import com.iver.cit.gvsig.fmap.core.FShape; |
195 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
196 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
197 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
198 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
199 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
200 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
201 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
202 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
203 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
204 |
import com.iver.cit.gvsig.fmap.layers.LayerListenerAdapter; |
205 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
206 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
207 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
208 |
import com.iver.cit.gvsig.graph.GraphException; |
209 |
import com.iver.cit.gvsig.graph.NetworkUtils; |
210 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
211 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
212 |
import com.iver.cit.gvsig.graph.core.IFlagListener; |
213 |
import com.iver.cit.gvsig.graph.core.Network; |
214 |
import com.iver.cit.gvsig.graph.solvers.FlagsMemoryDriver; |
215 |
import com.iver.cit.gvsig.graph.solvers.Route; |
216 |
import com.iver.cit.gvsig.graph.solvers.RouteMemoryDriver; |
217 |
import com.iver.cit.gvsig.graph.tools.FlagListener; |
218 |
import com.iver.cit.gvsig.project.documents.gui.FOpenDialog; |
219 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
220 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
221 |
import com.iver.cit.gvsig.util.GvSession; |
222 |
import com.vividsolutions.jts.geom.Coordinate; |
223 |
import com.vividsolutions.jts.geom.Geometry; |
224 |
import com.vividsolutions.jts.geom.MultiPoint; |
225 |
import com.vividsolutions.jts.geom.Point; |
226 |
|
227 |
public class RouteControlPanel extends JPanel implements SingletonWindow, |
228 |
ActionListener, IFlagListener {
|
229 |
WindowInfo wi; |
230 |
|
231 |
private JPanel westPanel = null; |
232 |
|
233 |
private JScrollPane scrlStages = null; |
234 |
|
235 |
private JTable tblStages = null; |
236 |
|
237 |
private GridBagLayoutPanel eastPanel = null; |
238 |
|
239 |
private MyTableModel tableModel = new MyTableModel(); // @jve:decl-index=0:visual-constraint="" |
240 |
|
241 |
private JButton btnLoadStage = null; |
242 |
|
243 |
private JButton btnSaveStage = null; |
244 |
|
245 |
private JButton btnSetVelocities = null; |
246 |
|
247 |
private Network network;
|
248 |
|
249 |
private ArrayList routeFlags; |
250 |
|
251 |
private JLabel lblCost; |
252 |
|
253 |
private JLabel lblFlagAmout; |
254 |
|
255 |
private JButton btnPullDownStage; |
256 |
|
257 |
private JButton btnPushUpStage; |
258 |
|
259 |
private JButton btnRemoveStage; |
260 |
|
261 |
private JPanel southPanel; |
262 |
|
263 |
private final String[] colName = new String[] { |
264 |
PluginServices.getText(this, "enable"), |
265 |
PluginServices.getText(this, "stage"), |
266 |
PluginServices.getText(this, "cost"), }; |
267 |
|
268 |
private JButton btnCenterOnFlag; |
269 |
|
270 |
private JButton btnSaveRoute; |
271 |
|
272 |
private MapControl mapCtrl;
|
273 |
|
274 |
private class MyTableModel extends AbstractTableModel { |
275 |
public int getColumnCount() { |
276 |
return 3; |
277 |
} |
278 |
|
279 |
public int getRowCount() { |
280 |
return _getFlags().size();
|
281 |
} |
282 |
|
283 |
public Object getValueAt(int rowIndex, int columnIndex) { |
284 |
GvFlag flag = (GvFlag) _getFlags().get(rowIndex); |
285 |
switch (columnIndex) {
|
286 |
case 0: |
287 |
return new Boolean(flag.isEnabled()); |
288 |
case 1: |
289 |
return flag.getDescription();
|
290 |
case 2: |
291 |
return new Double(flag.getCost()); |
292 |
} |
293 |
|
294 |
return null; |
295 |
} |
296 |
|
297 |
public Class getColumnClass(int columnIndex) { |
298 |
switch (columnIndex)
|
299 |
{ |
300 |
case 0: |
301 |
return Boolean.class; |
302 |
case 1: |
303 |
return String.class; |
304 |
case 2: |
305 |
return Double.class; |
306 |
|
307 |
} |
308 |
return super.getColumnClass(columnIndex); |
309 |
} |
310 |
|
311 |
public String getColumnName(int column) { |
312 |
return colName[column];
|
313 |
} |
314 |
|
315 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
316 |
if (columnIndex == 2) |
317 |
return false; |
318 |
return true; |
319 |
|
320 |
} |
321 |
|
322 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
323 |
GvFlag flag = (GvFlag) _getFlags().get(rowIndex); |
324 |
switch (columnIndex)
|
325 |
{ |
326 |
case 0: |
327 |
Boolean bAux = (Boolean) aValue; |
328 |
flag.setEnabled(bAux.booleanValue()); |
329 |
PluginServices.getMainFrame().enableControls(); |
330 |
return;
|
331 |
case 1: |
332 |
String strAux = (String) aValue; |
333 |
flag.setDescription(strAux); |
334 |
return;
|
335 |
|
336 |
// case 2: // No es editable
|
337 |
// Double dblAux = (Double) aValue;
|
338 |
// flag.setCost(dblAux.doubleValue());
|
339 |
// return;
|
340 |
|
341 |
} |
342 |
|
343 |
} |
344 |
|
345 |
} |
346 |
|
347 |
/**
|
348 |
* This method initializes
|
349 |
*
|
350 |
*/
|
351 |
public RouteControlPanel(Network network) {
|
352 |
super();
|
353 |
this.network = network;
|
354 |
// GvFlag[] flags = network.getFlags();
|
355 |
// List vflags = _getFlags();
|
356 |
// for (int i = 0; i < flags.length; i++) {
|
357 |
// vflags.add(flags[i]);
|
358 |
// }
|
359 |
initialize(); |
360 |
} |
361 |
|
362 |
/**
|
363 |
* Method to remove all flags (use
|
364 |
* */
|
365 |
public void refresh(){ |
366 |
// GvFlag[] flags = network.getFlags();
|
367 |
// List vflags = _getFlags();
|
368 |
// List tempFlags = Arrays.asList(flags);
|
369 |
// vflags.addAll(tempFlags);
|
370 |
lblFlagAmout.setText(String.valueOf(_getFlags()
|
371 |
.size())); |
372 |
updateTotalCost(); |
373 |
ListSelectionModel rowSM = tblStages.getSelectionModel();
|
374 |
if (_getFlags().size() == 0) |
375 |
getBtnCenterOnFlag().setEnabled(false);
|
376 |
else
|
377 |
getBtnCenterOnFlag().setEnabled(!rowSM.isSelectionEmpty()); |
378 |
getTblStages().revalidate(); |
379 |
System.out.println("Actualizo tabla"); |
380 |
|
381 |
} |
382 |
private void processLayer(FLayer layer) { |
383 |
if (layer.isActive()) {
|
384 |
if (layer instanceof FLyrVect) { |
385 |
Network net = (Network) layer |
386 |
.getProperty("network");
|
387 |
if (net != null) { |
388 |
network = net; |
389 |
network.addFlagListener(this);
|
390 |
refresh(); |
391 |
}// if
|
392 |
}// if
|
393 |
}// if
|
394 |
|
395 |
} |
396 |
|
397 |
public void setMapControl(MapControl mapCtrl, Network net) { |
398 |
if (mapCtrl != null) { |
399 |
this.mapCtrl = mapCtrl;
|
400 |
LayerListenerAdapter listener = new LayerListenerAdapter() {
|
401 |
public void activationChanged(LayerEvent e) { |
402 |
processLayer(e.getSource()); |
403 |
} |
404 |
}; |
405 |
mapCtrl.getMapContext().getLayers().addLayerListener(listener); |
406 |
mapCtrl.getMapContext().getLayers().addLayerCollectionListener( |
407 |
listener); |
408 |
if (net != null) { |
409 |
network = net; |
410 |
network.addFlagListener(this);
|
411 |
} |
412 |
} |
413 |
} |
414 |
|
415 |
public RouteControlPanel() {
|
416 |
super();
|
417 |
initialize(); |
418 |
} |
419 |
|
420 |
public void setCostUnits(String unitsName) { |
421 |
colName[2] = unitsName;
|
422 |
getTblStages().repaint(); |
423 |
} |
424 |
|
425 |
/**
|
426 |
* This method initializes this
|
427 |
*
|
428 |
*/
|
429 |
private void initialize() { |
430 |
BorderLayout borderLayout = new BorderLayout(); |
431 |
borderLayout.setHgap(10);
|
432 |
borderLayout.setVgap(10);
|
433 |
JPanel cont = new JPanel(borderLayout); |
434 |
// cont.setPreferredSize(new Dimension(490, 320));
|
435 |
this.setPreferredSize(new Dimension(460, 280)); |
436 |
cont.add(getWestPanel(), BorderLayout.CENTER);
|
437 |
cont.add(getEastPanel(), BorderLayout.EAST);
|
438 |
cont.add(getSouthPanel(), BorderLayout.SOUTH);
|
439 |
this.setLayout(new FlowLayout(FlowLayout.LEADING, 10, 10)); |
440 |
this.add(cont);
|
441 |
updateFlags(); |
442 |
} |
443 |
|
444 |
private void updateFlags() { |
445 |
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
446 |
updateTotalCost(); |
447 |
getTblStages().repaint(); |
448 |
} |
449 |
|
450 |
private JPanel getSouthPanel() { |
451 |
if (southPanel == null) { |
452 |
southPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
453 |
southPanel.add(getBtnRemoveStage()); |
454 |
southPanel.add(new JBlank(50, 20)); |
455 |
southPanel.add(getBtnPushUpStage()); |
456 |
southPanel.add(getBtnPullDownStage()); |
457 |
southPanel.add(new JLabel(PluginServices.getText(this, |
458 |
"flag_amount")));
|
459 |
lblFlagAmout = new JLabel(); |
460 |
lblFlagAmout.setFont(lblFlagAmout.getFont().deriveFont(Font.BOLD));
|
461 |
southPanel.add(lblFlagAmout); |
462 |
} |
463 |
return southPanel;
|
464 |
} |
465 |
|
466 |
public Object getWindowModel() { |
467 |
return this.getClass(); |
468 |
} |
469 |
|
470 |
public WindowInfo getWindowInfo() {
|
471 |
if (wi == null) { |
472 |
wi = new WindowInfo(WindowInfo.MODELESSDIALOG
|
473 |
| WindowInfo.MAXIMIZABLE |
474 |
| WindowInfo.ICONIFIABLE | WindowInfo.PALETTE); |
475 |
wi.setWidth((int) this.getPreferredSize().getWidth()); |
476 |
wi.setHeight((int) this.getPreferredSize().getHeight()); |
477 |
wi.setTitle(PluginServices.getText(this, "route_control_panel")); |
478 |
} |
479 |
return wi;
|
480 |
} |
481 |
|
482 |
/**
|
483 |
* This method initializes westPanel
|
484 |
*
|
485 |
* @return javax.swing.JPanel
|
486 |
*/
|
487 |
private JPanel getWestPanel() { |
488 |
if (westPanel == null) { |
489 |
westPanel = new JPanel(new BorderLayout(5, 5)); |
490 |
lblCost = new JLabel(); |
491 |
lblCost.setFont(lblCost.getFont().deriveFont(Font.BOLD));
|
492 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
493 |
aux.addComponent(PluginServices.getText(this, "total_route_cost") |
494 |
+ ":", lblCost);
|
495 |
aux.addComponent(getScrlStages()); |
496 |
|
497 |
westPanel.add(aux); |
498 |
} |
499 |
return westPanel;
|
500 |
} |
501 |
|
502 |
private JButton getBtnPullDownStage() { |
503 |
if (btnPullDownStage == null) { |
504 |
btnPullDownStage = new JButton(new ImageIcon(this.getClass() |
505 |
.getClassLoader().getResource("images/down-arrow.png")));
|
506 |
// btnPullDownStage.setName("btnPullDownStage");
|
507 |
btnPullDownStage.addActionListener(this);
|
508 |
} |
509 |
return btnPullDownStage;
|
510 |
} |
511 |
|
512 |
private JButton getBtnPushUpStage() { |
513 |
if (btnPushUpStage == null) { |
514 |
btnPushUpStage = new JButton(new ImageIcon(this.getClass() |
515 |
.getClassLoader().getResource("images/up-arrow.png")));
|
516 |
// btnPushUpStage.setName("btnPushUpStage");
|
517 |
btnPushUpStage.addActionListener(this);
|
518 |
} |
519 |
return btnPushUpStage;
|
520 |
} |
521 |
|
522 |
private JButton getBtnRemoveStage() { |
523 |
if (btnRemoveStage == null) { |
524 |
btnRemoveStage = new JButton(new ImageIcon(this.getClass() |
525 |
.getClassLoader().getResource("images/delete.png")));
|
526 |
// btnRemoveStage.setName("btnRemoveStage");
|
527 |
btnRemoveStage.addActionListener(this);
|
528 |
} |
529 |
return btnRemoveStage;
|
530 |
} |
531 |
|
532 |
/**
|
533 |
* This method initializes scrlStages
|
534 |
*
|
535 |
* @return javax.swing.JScrollPane
|
536 |
*/
|
537 |
private JScrollPane getScrlStages() { |
538 |
if (scrlStages == null) { |
539 |
scrlStages = new JScrollPane(); |
540 |
scrlStages.setViewportView(getTblStages()); |
541 |
scrlStages.setPreferredSize(new Dimension(270, 200)); |
542 |
} |
543 |
return scrlStages;
|
544 |
} |
545 |
|
546 |
/**
|
547 |
* @deprecated
|
548 |
* @param flag
|
549 |
*/
|
550 |
public void addFlag(GvFlag flag) { |
551 |
_getFlags().add(flag); |
552 |
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
553 |
updateTotalCost(); |
554 |
getTblStages().repaint(); |
555 |
} |
556 |
|
557 |
private void updateTotalCost() { |
558 |
GvFlag[] flags = getFlags();
|
559 |
double cost = 0; |
560 |
for (int i = 0; i < flags.length; i++) { |
561 |
if (!flags[i].isEnabled())
|
562 |
continue;
|
563 |
if (flags[i].getCost() >= Double.MAX_VALUE) |
564 |
{ |
565 |
lblCost.setText(PluginServices.getText(this, "no_se_puede_pasar_por_todas_las_paradas")); |
566 |
return;
|
567 |
} |
568 |
if (flags[i].getCost() < 0) |
569 |
{ |
570 |
lblCost.setText(PluginServices.getText(this, "solucion_no_valida")); |
571 |
return;
|
572 |
} |
573 |
|
574 |
cost += flags[i].getCost(); |
575 |
} |
576 |
NumberFormat nf = NumberFormat.getInstance(); |
577 |
nf.setMaximumFractionDigits(2);
|
578 |
lblCost.setText(nf.format(cost) + getCostUnitName()); |
579 |
} |
580 |
|
581 |
private String getCostUnitName() { |
582 |
if (colName[2].equals(PluginServices.getText(this, "cost"))) |
583 |
return ""; |
584 |
return colName[2]; |
585 |
} |
586 |
|
587 |
public void removeFlag(GvFlag flag) { |
588 |
removeFlag(_getFlags().indexOf(flag)); |
589 |
} |
590 |
|
591 |
public void removeFlag(int index) { |
592 |
_getFlags().remove(index); |
593 |
lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
594 |
getTblStages().repaint(); |
595 |
} |
596 |
|
597 |
/**
|
598 |
* This method initializes tblStages
|
599 |
*
|
600 |
* @return javax.swing.JTable
|
601 |
*/
|
602 |
private JTable getTblStages() { |
603 |
if (tblStages == null) { |
604 |
tblStages = new JTable(); |
605 |
tblStages |
606 |
.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); |
607 |
tblStages.setModel(getTableModel()); |
608 |
TableColumnModel cm = tblStages.getColumnModel();
|
609 |
|
610 |
int tablePreferredWidth = (int) tblStages.getPreferredSize() |
611 |
.getWidth(); |
612 |
int colSize = tblStages.getFontMetrics(tblStages.getFont())
|
613 |
.stringWidth(tblStages.getModel().getColumnName(0)) * 2; |
614 |
cm.getColumn(0).setPreferredWidth((int) (colSize)); |
615 |
cm.getColumn(0).setMinWidth((int) (colSize)); |
616 |
cm.getColumn(0).setMaxWidth((int) (colSize)); |
617 |
tablePreferredWidth -= colSize; |
618 |
cm.getColumn(1)
|
619 |
.setPreferredWidth((int) (tablePreferredWidth * 0.7)); |
620 |
cm.getColumn(2)
|
621 |
.setPreferredWidth((int) (tablePreferredWidth * 0.3)); |
622 |
|
623 |
// Ask to be notified of selection changes.
|
624 |
ListSelectionModel rowSM = tblStages.getSelectionModel();
|
625 |
rowSM.addListSelectionListener(new ListSelectionListener() { |
626 |
public void valueChanged(ListSelectionEvent e) { |
627 |
//Ignore extra messages.
|
628 |
if (e.getValueIsAdjusting())
|
629 |
return;
|
630 |
|
631 |
ListSelectionModel lsm =
|
632 |
(ListSelectionModel)e.getSource();
|
633 |
getBtnCenterOnFlag().setEnabled(!lsm.isSelectionEmpty()); |
634 |
} |
635 |
}); |
636 |
|
637 |
tblStages.getModel().addTableModelListener(new TableModelListener() { |
638 |
|
639 |
public void tableChanged(TableModelEvent e) { |
640 |
System.out.println("Table model changed"); |
641 |
// getBtnCenterOnFlag().setEnabled(false);
|
642 |
} |
643 |
|
644 |
}); |
645 |
|
646 |
|
647 |
} |
648 |
return tblStages;
|
649 |
} |
650 |
|
651 |
protected int getFlagCount() { |
652 |
return _getFlags().size();
|
653 |
} |
654 |
|
655 |
private List _getFlags() { |
656 |
// if (routeFlags == null) {
|
657 |
// routeFlags = new ArrayList();
|
658 |
// }
|
659 |
// return routeFlags;
|
660 |
|
661 |
return network.getOriginaFlags();
|
662 |
} |
663 |
|
664 |
protected boolean isSelected(int row) { |
665 |
return ((GvFlag) _getFlags().get(row)).isEnabled();
|
666 |
} |
667 |
|
668 |
/**
|
669 |
* This method initializes eastPanel
|
670 |
*
|
671 |
* @return javax.swing.JPanel
|
672 |
*/
|
673 |
private JPanel getEastPanel() { |
674 |
if (eastPanel == null) { |
675 |
GridLayout layout = new GridLayout(); |
676 |
layout.setColumns(1);
|
677 |
layout.setVgap(5);
|
678 |
JPanel aux = new JPanel(); |
679 |
aux.add(getBtnLoadStage()); |
680 |
aux.add(getBtnSaveStage()); |
681 |
aux.add(getBtnSaveRoute()); |
682 |
aux.add(getBtnCenterOnFlag()); |
683 |
aux.add(getBtnSetVelocities()); |
684 |
layout.setRows(aux.getComponentCount()); |
685 |
aux.setLayout(layout); |
686 |
eastPanel = new GridBagLayoutPanel();
|
687 |
eastPanel.addComponent(aux); |
688 |
} |
689 |
return eastPanel;
|
690 |
} |
691 |
|
692 |
private JButton getBtnCenterOnFlag() { |
693 |
if (btnCenterOnFlag == null) { |
694 |
btnCenterOnFlag = new JButton(); |
695 |
btnCenterOnFlag.setText(PluginServices.getText(this,
|
696 |
"center_on_flag"));
|
697 |
btnCenterOnFlag.setEnabled(false);
|
698 |
btnCenterOnFlag.addActionListener(this);
|
699 |
} |
700 |
return btnCenterOnFlag;
|
701 |
} |
702 |
|
703 |
private JButton getBtnSetVelocities() { |
704 |
if (btnSetVelocities == null) { |
705 |
btnSetVelocities = new JButton(); |
706 |
btnSetVelocities.setText(PluginServices.getText(this,
|
707 |
"set_velocities"));
|
708 |
// btnSetVelocities.setEnabled(false);
|
709 |
|
710 |
// TODO: PONERLO VISIBLE CUANDO SE CORRIJA LO DE ABRIR EL
|
711 |
// DIALOGO Y LEER LAS VELOCIDADES QUE HAB?A ANTES.
|
712 |
btnSetVelocities.setVisible(false);
|
713 |
btnSetVelocities.addActionListener(this);
|
714 |
} |
715 |
return btnSetVelocities;
|
716 |
} |
717 |
|
718 |
private JButton getBtnSaveRoute() { |
719 |
if (btnSaveRoute == null) { |
720 |
btnSaveRoute = new JButton(); |
721 |
btnSaveRoute.setText(PluginServices.getText(this, "save_route")); |
722 |
btnSaveRoute.addActionListener(this);
|
723 |
} |
724 |
return btnSaveRoute;
|
725 |
} |
726 |
|
727 |
/**
|
728 |
* This method initializes defaultTableModel
|
729 |
*
|
730 |
* @return javax.swing.table.DefaultTableModel
|
731 |
*/
|
732 |
private TableModel getTableModel() { |
733 |
return tableModel;
|
734 |
} |
735 |
|
736 |
/**
|
737 |
* This method initializes btnLoadStage
|
738 |
*
|
739 |
* @return javax.swing.JButton
|
740 |
*/
|
741 |
private JButton getBtnLoadStage() { |
742 |
if (btnLoadStage == null) { |
743 |
btnLoadStage = new JButton(); |
744 |
btnLoadStage.setText(PluginServices.getText(this, "load_stages")); |
745 |
btnLoadStage.addActionListener(this);
|
746 |
} |
747 |
return btnLoadStage;
|
748 |
} |
749 |
|
750 |
/**
|
751 |
* This method initializes btnSaveStages
|
752 |
*
|
753 |
* @return javax.swing.JButton
|
754 |
*/
|
755 |
private JButton getBtnSaveStage() { |
756 |
if (btnSaveStage == null) { |
757 |
btnSaveStage = new JButton(); |
758 |
btnSaveStage.setText(PluginServices.getText(this, "save_stages")); |
759 |
btnSaveStage.addActionListener(this);
|
760 |
} |
761 |
return btnSaveStage;
|
762 |
} |
763 |
|
764 |
class FormatSelectionPanel extends JPanel implements IWindow { |
765 |
|
766 |
JComboBox formats;
|
767 |
WindowInfo wi = null;
|
768 |
|
769 |
public FormatSelectionPanel(String introductoryText) { |
770 |
super(new BorderLayout()); |
771 |
String[] formatos = { "SHP", "DXF", "POSTGIS", "GML" }; |
772 |
formats = new JComboBox(formatos); |
773 |
GridBagLayoutPanel contentPanel = |
774 |
new GridBagLayoutPanel();
|
775 |
contentPanel.addComponent(new JLabel(introductoryText)); |
776 |
contentPanel.addComponent(formats); |
777 |
JButton okButton = new JButton(PluginServices.getText(null, |
778 |
"Aceptar"));
|
779 |
okButton.addActionListener(new ActionListener() { |
780 |
public void actionPerformed(ActionEvent arg0) { |
781 |
close(); |
782 |
} |
783 |
}); |
784 |
contentPanel.addComponent(okButton); |
785 |
|
786 |
add(contentPanel); |
787 |
} |
788 |
|
789 |
void close() {
|
790 |
PluginServices.getMDIManager().closeWindow(this);
|
791 |
} |
792 |
|
793 |
public String getSelectedFormat() { |
794 |
return (String) formats.getSelectedItem(); |
795 |
} |
796 |
|
797 |
public WindowInfo getWindowInfo() {
|
798 |
if (wi == null) { |
799 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.PALETTE);
|
800 |
wi.setTitle(PluginServices |
801 |
.getText(null, "Seleccion_de_formato"));// Internacionalizar |
802 |
// esto
|
803 |
wi.setWidth(300);
|
804 |
wi.setHeight(55);
|
805 |
} |
806 |
return wi;
|
807 |
} |
808 |
|
809 |
} |
810 |
|
811 |
public void actionPerformed(ActionEvent e) { |
812 |
Component c = (Component) e.getSource(); |
813 |
if (c.equals(getBtnLoadStage())) {
|
814 |
loadStages(); |
815 |
} else if (c.equals(getBtnSaveStage())) { |
816 |
saveStage(); |
817 |
} else if (c.equals(getBtnPushUpStage())) { |
818 |
int[] selected = tblStages.getSelectedRows(); |
819 |
if (selected.length == 0 || selected[0] == 0) |
820 |
return;
|
821 |
tblStages.clearSelection(); |
822 |
for (int i = 0; i < selected.length; i++) { |
823 |
Object aux = _getFlags().get(selected[i] - 1); |
824 |
_getFlags().set(selected[i] - 1, _getFlags().get(selected[i]));
|
825 |
_getFlags().set(selected[i], aux); |
826 |
selected[i]--; |
827 |
tblStages.addRowSelectionInterval(selected[i], selected[i]); |
828 |
} |
829 |
invalidateSolution(); |
830 |
} else if (c.equals(getBtnPullDownStage())) { |
831 |
// pull down
|
832 |
int[] selected = tblStages.getSelectedRows(); |
833 |
if (selected.length == 0 |
834 |
|| selected[selected.length - 1] >= _getFlags().size() - 1) |
835 |
return;
|
836 |
|
837 |
// move rows
|
838 |
tblStages.clearSelection(); |
839 |
for (int i = selected.length - 1; i >= 0; i--) { |
840 |
Object aux = _getFlags().get(selected[i] + 1); |
841 |
_getFlags().set(selected[i] + 1, _getFlags().get(selected[i]));
|
842 |
_getFlags().set(selected[i], aux); |
843 |
selected[i]++; |
844 |
tblStages.addRowSelectionInterval(selected[i], selected[i]); |
845 |
} |
846 |
invalidateSolution(); |
847 |
|
848 |
} else if (c.equals(getBtnRemoveStage())) { |
849 |
removeStage(); |
850 |
} else if (c.equals(getBtnSaveRoute())) { |
851 |
saveRoute(); |
852 |
} else if (c.equals(getBtnSetVelocities())) { |
853 |
setVelocities(); |
854 |
} else if (c.equals(getBtnCenterOnFlag())) { |
855 |
// Center on first selected flag.
|
856 |
int[] selected = tblStages.getSelectedRows(); |
857 |
if (selected.length == 0) |
858 |
return;
|
859 |
GvFlag flag = (GvFlag) _getFlags().get(selected[0]);
|
860 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
861 |
if(! (window instanceof IView)) |
862 |
return;
|
863 |
IView view = (IView) window; |
864 |
ViewPort vp = view.getMapControl().getViewPort(); |
865 |
Rectangle2D extent = vp.getAdjustedExtent();
|
866 |
double xNC = flag.getOriginalPoint().getX();
|
867 |
double yNC = flag.getOriginalPoint().getY();
|
868 |
double width = extent.getWidth();
|
869 |
double height = extent.getHeight();
|
870 |
|
871 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
872 |
|
873 |
r.width = width; |
874 |
r.height = height; |
875 |
r.x = xNC - width/2;
|
876 |
r.y = yNC - height/2;
|
877 |
|
878 |
vp.setExtent(r); |
879 |
|
880 |
|
881 |
|
882 |
} |
883 |
repaint(); |
884 |
} |
885 |
|
886 |
private void setVelocities() { |
887 |
if(network == null){ |
888 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
889 |
if(! (window instanceof IView)) |
890 |
return;
|
891 |
IView view = (View) window;
|
892 |
MapControl mapControl = view.getMapControl(); |
893 |
MapContext map = mapControl.getMapContext(); |
894 |
FLayers layers = map.getLayers(); |
895 |
SingleLayerIterator it = new SingleLayerIterator(layers);
|
896 |
while (it.hasNext() && network == null) { |
897 |
FLayer aux = it.next(); |
898 |
if (!aux.isActive())
|
899 |
continue;
|
900 |
network = (Network) aux.getProperty("network");
|
901 |
} |
902 |
} |
903 |
if (network == null) |
904 |
return;
|
905 |
|
906 |
ArrayList lstTipoTramo = network.getEdgeTypes();
|
907 |
try
|
908 |
{ |
909 |
String msg = PluginServices.getText(this, "msg_set_velocities"); |
910 |
MultiInputDlg dlg = new MultiInputDlg(msg, lstTipoTramo);
|
911 |
String col1 = PluginServices.getText(this, "col_arc_type"); |
912 |
String col2 = PluginServices.getText(this, "col_km_per_hour"); |
913 |
dlg.setColumnNames(col1, col2); |
914 |
dlg.setModal(true);
|
915 |
dlg.setVisible(true);
|
916 |
if (dlg.isCanceled())
|
917 |
return;
|
918 |
|
919 |
ArrayList veloKm = dlg.getRightValues(); //{120, 110, 90, 80, 70, 60, 50, 40}; |
920 |
Hashtable veloMeters = new Hashtable(veloKm.size()); |
921 |
for (int i=0; i<veloKm.size(); i++) |
922 |
{ |
923 |
Object key = lstTipoTramo.get(i);
|
924 |
veloMeters.put(key, new Double(Double.parseDouble((String) veloKm.get(i)) / 3.6)); |
925 |
} |
926 |
|
927 |
for (int i=0; i < network.getGraph().numEdges(); i++) |
928 |
{ |
929 |
GvEdge edge = network.getGraph().getEdgeByID(i); |
930 |
|
931 |
Integer key = new Integer(edge.getType()); |
932 |
Double vel = (Double) veloMeters.get(key); |
933 |
edge.setWeight(edge.getDistance() / vel.doubleValue()); // segundos
|
934 |
} |
935 |
|
936 |
} |
937 |
catch(Exception e) |
938 |
{ |
939 |
e.printStackTrace(); |
940 |
} |
941 |
|
942 |
|
943 |
} |
944 |
|
945 |
private void invalidateSolution() { |
946 |
for (int i=0; i < _getFlags().size(); i++) |
947 |
{ |
948 |
GvFlag flag = (GvFlag) _getFlags().get(i); |
949 |
flag.setCost(-1.0);
|
950 |
} |
951 |
updateTotalCost(); |
952 |
} |
953 |
|
954 |
private void saveStage(){ |
955 |
if(network == null){ |
956 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
957 |
if(! (window instanceof IView)) |
958 |
return;
|
959 |
IView view = (View) window;
|
960 |
MapControl mapControl = view.getMapControl(); |
961 |
MapContext map = mapControl.getMapContext(); |
962 |
FLayers layers = map.getLayers(); |
963 |
SingleLayerIterator it = new SingleLayerIterator(layers);
|
964 |
while (it.hasNext() && network == null) { |
965 |
FLayer aux = it.next(); |
966 |
if (!aux.isActive())
|
967 |
continue;
|
968 |
network = (Network) aux.getProperty("network");
|
969 |
} |
970 |
} |
971 |
if (network == null) |
972 |
return;
|
973 |
|
974 |
List features = new ArrayList(); |
975 |
GvFlag[] flags = network.getFlags();
|
976 |
for(int i = 0; i < flags.length; i++){ |
977 |
GvFlag flag = flags[i]; |
978 |
// Solo se guardan los flags habilitados
|
979 |
if (!flag.isEnabled())
|
980 |
continue;
|
981 |
FPoint2D point = new FPoint2D(flag.getOriginalPoint());
|
982 |
Value[] values = new Value[6]; |
983 |
values[GvFlag.ID_FLAG_INDEX] = ValueFactory.createValue(flag.getIdFlag()); |
984 |
values[GvFlag.ID_ARC_INDEX] = ValueFactory.createValue(flag.getIdArc()); |
985 |
values[GvFlag.DESCRIPTION_INDEX] = ValueFactory.createValue(flag.getDescription()); |
986 |
values[GvFlag.DIREC_INDEX] = ValueFactory.createValue(flag.getDirec()); |
987 |
values[GvFlag.PCT_INDEX] = ValueFactory.createValue(flag.getPct()); |
988 |
values[GvFlag.COST_INDEX] = ValueFactory.createValue(flag.getCost()); |
989 |
IGeometry geo = ShapeFactory.createPoint2D(point); |
990 |
DefaultFeature feature = new DefaultFeature(geo, values, new Integer(flag.getIdFlag()).toString() ); |
991 |
features.add(feature); |
992 |
} |
993 |
|
994 |
FlagsMemoryDriver driver = new FlagsMemoryDriver(features);
|
995 |
IProjection projection = FOpenDialog.getLastProjection(); |
996 |
FLyrVect routeLayer = (FLyrVect) LayerFactory.createLayer("Flags",
|
997 |
driver, projection); |
998 |
|
999 |
FormatSelectionPanel selectionPanel = |
1000 |
new FormatSelectionPanel(PluginServices.
|
1001 |
getText(null,
|
1002 |
"Seleccione_un_formato_para_guardar_los_flags"));
|
1003 |
PluginServices.getMDIManager().addWindow(selectionPanel); |
1004 |
|
1005 |
String format = selectionPanel.getSelectedFormat();
|
1006 |
com.iver.cit.gvsig.ExportTo export = new com.iver.cit.gvsig.ExportTo(); |
1007 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
1008 |
if(! (window instanceof IView)) |
1009 |
return;
|
1010 |
IView view = (View) window;
|
1011 |
MapControl mapControl = view.getMapControl(); |
1012 |
MapContext context = mapControl.getMapContext(); |
1013 |
try {
|
1014 |
if (format.equalsIgnoreCase("SHP")) { |
1015 |
export.saveToShp(context, routeLayer);
|
1016 |
} else if (format.equalsIgnoreCase("DXF")) { |
1017 |
export.saveToDxf(context, routeLayer);
|
1018 |
} else if (format.equalsIgnoreCase("GML")) { |
1019 |
export.saveToGml(context, routeLayer);
|
1020 |
} else if (format.equalsIgnoreCase("POSTGIS")) { |
1021 |
export.saveToPostGIS(context, routeLayer);
|
1022 |
} |
1023 |
} catch (EditionException e1) {
|
1024 |
// TODO Auto-generated catch block
|
1025 |
e1.printStackTrace(); |
1026 |
} catch (DriverIOException e1) {
|
1027 |
// TODO Auto-generated catch block
|
1028 |
e1.printStackTrace(); |
1029 |
} |
1030 |
|
1031 |
} |
1032 |
private void saveRoute() { |
1033 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
1034 |
if(! (window instanceof IView)) |
1035 |
return;
|
1036 |
IView view = (View) window;
|
1037 |
MapControl mapControl = view.getMapControl(); |
1038 |
List routes = (List) GvSession.getInstance().get(mapControl, "Route"); |
1039 |
if(routes == null || routes.size() == 0){ |
1040 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Ruta_borrada_o_inexistente"), |
1041 |
PluginServices.getText(this, "Ruta_no_encontrada"), |
1042 |
JOptionPane.ERROR_MESSAGE);
|
1043 |
return;
|
1044 |
} |
1045 |
Route lastRoute = (Route) routes.get(routes.size() - 1);
|
1046 |
RouteMemoryDriver driver = new RouteMemoryDriver(lastRoute.getFeatureList());
|
1047 |
IProjection projection = FOpenDialog.getLastProjection(); |
1048 |
FLyrVect routeLayer = (FLyrVect) LayerFactory.createLayer("Route",
|
1049 |
driver, projection); |
1050 |
|
1051 |
FormatSelectionPanel selectionPanel = new FormatSelectionPanel(PluginServices.getText(null, |
1052 |
"Seleccione_un_formato_para_guardar_la_ruta"));
|
1053 |
PluginServices.getMDIManager().addWindow(selectionPanel); |
1054 |
|
1055 |
String format = selectionPanel.getSelectedFormat();
|
1056 |
com.iver.cit.gvsig.ExportTo export = new com.iver.cit.gvsig.ExportTo(); |
1057 |
MapContext context = mapControl.getMapContext(); |
1058 |
try {
|
1059 |
if (format.equalsIgnoreCase("SHP")) { |
1060 |
export.saveToShp(context, routeLayer);
|
1061 |
} else if (format.equalsIgnoreCase("DXF")) { |
1062 |
export.saveToDxf(context, routeLayer);
|
1063 |
} else if (format.equalsIgnoreCase("GML")) { |
1064 |
export.saveToGml(context, routeLayer);
|
1065 |
} else if (format.equalsIgnoreCase("POSTGIS")) { |
1066 |
export.saveToPostGIS(context, routeLayer);
|
1067 |
} |
1068 |
} catch (EditionException e1) {
|
1069 |
// TODO Auto-generated catch block
|
1070 |
e1.printStackTrace(); |
1071 |
} catch (DriverIOException e1) {
|
1072 |
// TODO Auto-generated catch block
|
1073 |
e1.printStackTrace(); |
1074 |
} |
1075 |
} |
1076 |
|
1077 |
/**
|
1078 |
* Converts a point layer loaded in the active view's toc in a collection of
|
1079 |
* flags of the active network
|
1080 |
*
|
1081 |
*/
|
1082 |
private void loadStages() { |
1083 |
|
1084 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
1085 |
if(! (window instanceof IView)) |
1086 |
return;
|
1087 |
IView view = (IView) window; |
1088 |
MapControl mapControl = view.getMapControl(); |
1089 |
MapContext map = mapControl.getMapContext(); |
1090 |
FLayers layers = map.getLayers(); |
1091 |
|
1092 |
String title = PluginServices.getText(this, |
1093 |
"Seleccionar_capa_con_puntos_de_parada");
|
1094 |
String introductoryText = PluginServices.getText(this, |
1095 |
"Seleccione_una_capa_de_puntos_para_crear_paradas");
|
1096 |
|
1097 |
LayerSelectionPanel selectionPanel = new LayerSelectionPanel(layers,
|
1098 |
title, introductoryText, FLyrVect.class, FShape.POINT); |
1099 |
PluginServices.getMDIManager().addWindow(selectionPanel); |
1100 |
|
1101 |
if (!selectionPanel.wasFinishPressed())
|
1102 |
return;
|
1103 |
else {
|
1104 |
FLayer layer = selectionPanel.getLayer(); |
1105 |
if (layer == null) |
1106 |
return;
|
1107 |
if (!(layer instanceof FLyrVect)) |
1108 |
return;
|
1109 |
FLyrVect vectLyr = (FLyrVect) layer; |
1110 |
|
1111 |
try {
|
1112 |
if (vectLyr.getShapeType() != FShape.POINT)
|
1113 |
return;
|
1114 |
|
1115 |
// TODO
|
1116 |
// Hay que refinar bastante, para que el usuario elija
|
1117 |
// con que red y con qu? capa lineal quiere trabajar
|
1118 |
// tal y como est?, si hubiese varias se trabajaria
|
1119 |
// con la primera que devuelva el iterador
|
1120 |
|
1121 |
Network net = null;
|
1122 |
SingleLayerIterator it = new SingleLayerIterator(layers);
|
1123 |
while (it.hasNext() && net == null) { |
1124 |
FLayer aux = it.next(); |
1125 |
if (!aux.isActive())
|
1126 |
continue;
|
1127 |
net = (Network) aux.getProperty("network");
|
1128 |
} |
1129 |
if (net == null) |
1130 |
return;
|
1131 |
|
1132 |
// Por si queremos a?adir paradas a otras ya existentes
|
1133 |
// _getFlags().clear();
|
1134 |
|
1135 |
GvFlag flag; |
1136 |
ReadableVectorial reader = vectLyr.getSource(); |
1137 |
SelectableDataSource recordset = vectLyr.getRecordset(); |
1138 |
int numShapes = reader.getShapeCount();
|
1139 |
|
1140 |
double realTol = mapCtrl.getViewPort()
|
1141 |
.toMapDistance(FlagListener.pixelTolerance); |
1142 |
reader.start(); |
1143 |
for (int i = 0; i < numShapes; i++) { |
1144 |
Geometry geo = reader.getShape(i).toJTSGeometry(); |
1145 |
if (!((geo instanceof Point) || (geo instanceof MultiPoint))) |
1146 |
continue;
|
1147 |
|
1148 |
|
1149 |
|
1150 |
Coordinate[] coords = geo.getCoordinates();
|
1151 |
for (int j = 0; j < coords.length; j++) { |
1152 |
|
1153 |
try {
|
1154 |
flag = net.addFlag(coords[j].x, coords[j].y, realTol); |
1155 |
if (flag == null) |
1156 |
{ |
1157 |
// segundo intento:
|
1158 |
flag = net.addFlag(coords[j].x, coords[j].y, 4*realTol);
|
1159 |
if (flag == null) |
1160 |
{ |
1161 |
NullPointerException e = new NullPointerException("Punto " + i + " fuera de la red. Tolerancia=" + realTol); |
1162 |
NotificationManager.addError("No se puedo situar el registro " + i +
|
1163 |
"Por favor, compruebe que est? encima de la red o aumente la toleracina.", e);
|
1164 |
} |
1165 |
} |
1166 |
if (flag != null) |
1167 |
{ |
1168 |
// TODO: Create use a IFlagListener to do this
|
1169 |
// inside flagsChanged. The best solution is
|
1170 |
// to put all the code in RouteControlPanel
|
1171 |
NetworkUtils.addGraphicFlag(mapControl, flag); |
1172 |
} |
1173 |
} catch (GraphException e) {
|
1174 |
e.printStackTrace(); |
1175 |
NotificationManager.addError("No se puedo situar el registro " + i +
|
1176 |
"Por favor, compruebe que est? encima de la red.", e);
|
1177 |
} |
1178 |
|
1179 |
} // for j
|
1180 |
} // for i
|
1181 |
reader.stop(); |
1182 |
mapControl.drawGraphics(); |
1183 |
PluginServices.getMainFrame().enableControls(); |
1184 |
|
1185 |
} catch (DriverException e1) {
|
1186 |
return;
|
1187 |
} catch (DriverIOException e2) {
|
1188 |
return;
|
1189 |
} |
1190 |
} |
1191 |
} |
1192 |
|
1193 |
/**
|
1194 |
* Removes the selected flags in the component's table from: -the graphic
|
1195 |
* layer of the active view -the active network -the own table
|
1196 |
*
|
1197 |
*/
|
1198 |
private void removeStage() { |
1199 |
int[] selected = tblStages.getSelectedRows(); |
1200 |
|
1201 |
for (int i = selected.length - 1; i >= 0; i--) { |
1202 |
try {
|
1203 |
// removeFlag(selected[i]);
|
1204 |
if (network != null) { |
1205 |
final GvFlag flag = (GvFlag) _getFlags().get(selected[i]);
|
1206 |
NetworkUtils.clearFlagFromGraphics(mapCtrl, flag); |
1207 |
network.removeFlag(flag); |
1208 |
mapCtrl.repaint(); |
1209 |
} |
1210 |
} catch (IndexOutOfBoundsException iobEx) { |
1211 |
} |
1212 |
|
1213 |
}// for
|
1214 |
tblStages.clearSelection(); |
1215 |
invalidateSolution(); |
1216 |
mapCtrl.drawMap(false);
|
1217 |
} |
1218 |
|
1219 |
public GvFlag[] getFlags() { |
1220 |
return (GvFlag[]) _getFlags().toArray(new GvFlag[0]); |
1221 |
} |
1222 |
|
1223 |
public void flagsChanged(int reason) { |
1224 |
refresh(); |
1225 |
mapCtrl.drawGraphics(); |
1226 |
|
1227 |
} |
1228 |
} // @jve:decl-index=0:visual-constraint="17,9"
|