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 | 8326 | jaume | /* 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 | 8573 | azabala | *
|
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 12157 | fjp | * 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 | 11805 | fjp | * 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 | 11631 | fjp | * Para calcular matrices de distancias
|
54 | 11296 | caballero | *
|
55 | * Revision 1.25 2006/11/14 18:32:32 fjp
|
||
56 | 8751 | fjp | * *** empty log message ***
|
57 | *
|
||
58 | 8762 | fjp | * Revision 1.24 2006/11/14 16:12:01 fjp
|
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | 8751 | fjp | * Revision 1.23 2006/11/14 09:23:30 fjp
|
62 | 8723 | fjp | * cargar paradas desde cualquier tema de puntos
|
63 | *
|
||
64 | * Revision 1.22 2006/11/10 13:57:04 fjp
|
||
65 | 8639 | fjp | * *** empty log message ***
|
66 | *
|
||
67 | 8673 | fjp | * Revision 1.21 2006/11/09 21:08:32 azabala
|
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | 8659 | azabala | * Revision 1.20 2006/11/09 12:51:12 jaume
|
71 | * *** empty log message ***
|
||
72 | *
|
||
73 | 8647 | jaume | * Revision 1.19 2006/11/09 11:00:43 jaume
|
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | 8642 | jaume | * Revision 1.18 2006/11/09 10:59:53 jaume
|
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | 8641 | jaume | * Revision 1.17 2006/11/09 10:27:50 fjp
|
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | 8640 | fjp | * Revision 1.16 2006/11/09 10:24:11 fjp
|
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | 8639 | fjp | * Revision 1.15 2006/11/09 09:16:35 fjp
|
86 | 8636 | fjp | * Ya va!!
|
87 | *
|
||
88 | * Revision 1.14 2006/11/08 20:14:52 azabala
|
||
89 | 8626 | azabala | * *** empty log message ***
|
90 | *
|
||
91 | * Revision 1.13 2006/11/08 19:32:22 azabala
|
||
92 | 8623 | azabala | * saveroute and saveflags modifications
|
93 | *
|
||
94 | * Revision 1.12 2006/11/08 18:16:28 fjp
|
||
95 | 8616 | fjp | * *** empty log message ***
|
96 | *
|
||
97 | 8621 | fjp | * Revision 1.11 2006/11/08 16:48:19 fjp
|
98 | * *** empty log message ***
|
||
99 | *
|
||
100 | 8616 | fjp | * Revision 1.10 2006/11/08 16:00:39 fjp
|
101 | 8606 | fjp | * Por terminar el enlace flags-cuadro de di?logo
|
102 | *
|
||
103 | 8613 | fjp | * Revision 1.9 2006/11/08 13:18:46 fjp
|
104 | * Por terminar el enlace flags-cuadro de di?logo
|
||
105 | *
|
||
106 | 8606 | fjp | * Revision 1.8 2006/11/07 19:49:38 azabala
|
107 | 8573 | azabala | * *** 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 | 8326 | jaume | 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 | 8401 | jaume | import java.awt.GridLayout; |
152 | 8326 | jaume | import java.awt.event.ActionEvent; |
153 | import java.awt.event.ActionListener; |
||
154 | 8751 | fjp | import java.awt.geom.Rectangle2D; |
155 | 8762 | fjp | import java.text.NumberFormat; |
156 | 8573 | azabala | import java.util.ArrayList; |
157 | 12157 | fjp | import java.util.Hashtable; |
158 | 8573 | azabala | import java.util.List; |
159 | 8326 | jaume | |
160 | import javax.swing.ImageIcon; |
||
161 | 8573 | azabala | import javax.swing.JComboBox; |
162 | 8326 | jaume | import javax.swing.JLabel; |
163 | 8659 | azabala | import javax.swing.JOptionPane; |
164 | 8326 | jaume | import javax.swing.JPanel; |
165 | import javax.swing.JScrollPane; |
||
166 | import javax.swing.JTable; |
||
167 | 8762 | fjp | 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 | 8636 | fjp | import javax.swing.table.AbstractTableModel; |
173 | 8326 | jaume | import javax.swing.table.TableColumnModel; |
174 | import javax.swing.table.TableModel; |
||
175 | |||
176 | 8573 | azabala | import org.cresques.cts.IProjection; |
177 | 8326 | jaume | 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 | 8573 | azabala | import com.hardcode.gdbms.engine.values.Value; |
182 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
183 | 8326 | jaume | import com.iver.andami.PluginServices; |
184 | 8723 | fjp | import com.iver.andami.messages.NotificationManager; |
185 | 8326 | jaume | import com.iver.andami.ui.mdiManager.IWindow; |
186 | 8636 | fjp | import com.iver.andami.ui.mdiManager.SingletonWindow; |
187 | 8326 | jaume | import com.iver.andami.ui.mdiManager.WindowInfo; |
188 | 8411 | azabala | import com.iver.cit.gvsig.fmap.DriverException; |
189 | import com.iver.cit.gvsig.fmap.MapContext; |
||
190 | import com.iver.cit.gvsig.fmap.MapControl; |
||
191 | 8751 | fjp | import com.iver.cit.gvsig.fmap.ViewPort; |
192 | 8573 | azabala | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
193 | import com.iver.cit.gvsig.fmap.core.FPoint2D; |
||
194 | 8411 | azabala | 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 | 8573 | azabala | import com.iver.cit.gvsig.fmap.edition.EditionException; |
199 | 8411 | azabala | 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 | 8573 | azabala | 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 | 8411 | azabala | import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
206 | 8626 | azabala | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
207 | 8411 | azabala | import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
208 | 8723 | fjp | import com.iver.cit.gvsig.graph.GraphException; |
209 | 8616 | fjp | import com.iver.cit.gvsig.graph.NetworkUtils; |
210 | 12157 | fjp | import com.iver.cit.gvsig.graph.core.GvEdge; |
211 | 8326 | jaume | import com.iver.cit.gvsig.graph.core.GvFlag; |
212 | 8606 | fjp | import com.iver.cit.gvsig.graph.core.IFlagListener; |
213 | 8411 | azabala | import com.iver.cit.gvsig.graph.core.Network; |
214 | 8573 | azabala | 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 | 8723 | fjp | import com.iver.cit.gvsig.graph.tools.FlagListener; |
218 | 8573 | azabala | import com.iver.cit.gvsig.project.documents.gui.FOpenDialog; |
219 | 8411 | azabala | import com.iver.cit.gvsig.project.documents.view.gui.IView; |
220 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
221 | 8573 | azabala | import com.iver.cit.gvsig.util.GvSession; |
222 | 8411 | azabala | 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 | 8326 | jaume | |
227 | 8642 | jaume | public class RouteControlPanel extends JPanel implements SingletonWindow, |
228 | 8606 | fjp | ActionListener, IFlagListener {
|
229 | 8573 | azabala | WindowInfo wi; |
230 | 8326 | jaume | |
231 | 8573 | azabala | private JPanel westPanel = null; |
232 | 8521 | jaume | |
233 | 8573 | azabala | private JScrollPane scrlStages = null; |
234 | |||
235 | private JTable tblStages = null; |
||
236 | |||
237 | private GridBagLayoutPanel eastPanel = null; |
||
238 | |||
239 | 8636 | fjp | private MyTableModel tableModel = new MyTableModel(); // @jve:decl-index=0:visual-constraint="" |
240 | 8573 | azabala | |
241 | private JButton btnLoadStage = null; |
||
242 | |||
243 | private JButton btnSaveStage = null; |
||
244 | 12157 | fjp | |
245 | private JButton btnSetVelocities = null; |
||
246 | 8641 | jaume | |
247 | 8573 | azabala | private Network network;
|
248 | |||
249 | private ArrayList routeFlags; |
||
250 | |||
251 | private JLabel lblCost; |
||
252 | |||
253 | 8326 | jaume | private JLabel lblFlagAmout; |
254 | 8573 | azabala | |
255 | 8326 | jaume | private JButton btnPullDownStage; |
256 | 8573 | azabala | |
257 | 8326 | jaume | private JButton btnPushUpStage; |
258 | 8573 | azabala | |
259 | 8326 | jaume | private JButton btnRemoveStage; |
260 | 8573 | azabala | |
261 | 8326 | jaume | private JPanel southPanel; |
262 | 8573 | azabala | |
263 | 8326 | jaume | private final String[] colName = new String[] { |
264 | 8573 | azabala | PluginServices.getText(this, "enable"), |
265 | PluginServices.getText(this, "stage"), |
||
266 | PluginServices.getText(this, "cost"), }; |
||
267 | |||
268 | 8751 | fjp | private JButton btnCenterOnFlag; |
269 | 8573 | azabala | |
270 | 8401 | jaume | private JButton btnSaveRoute; |
271 | 8411 | azabala | |
272 | 8573 | azabala | private MapControl mapCtrl;
|
273 | 8641 | jaume | |
274 | 8636 | fjp | private class MyTableModel extends AbstractTableModel { |
275 | public int getColumnCount() { |
||
276 | return 3; |
||
277 | } |
||
278 | 8521 | jaume | |
279 | 8636 | fjp | 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 | 8641 | jaume | |
307 | 8636 | fjp | } |
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 | 8640 | fjp | PluginServices.getMainFrame().enableControls(); |
330 | 8636 | fjp | return;
|
331 | case 1: |
||
332 | String strAux = (String) aValue; |
||
333 | flag.setDescription(strAux); |
||
334 | return;
|
||
335 | 8641 | jaume | |
336 | 8636 | fjp | // case 2: // No es editable
|
337 | // Double dblAux = (Double) aValue;
|
||
338 | // flag.setCost(dblAux.doubleValue());
|
||
339 | // return;
|
||
340 | 8641 | jaume | |
341 | 8636 | fjp | } |
342 | |||
343 | } |
||
344 | 8641 | jaume | |
345 | 8636 | fjp | } |
346 | |||
347 | 8573 | azabala | /**
|
348 | * This method initializes
|
||
349 | 8641 | jaume | *
|
350 | 8573 | azabala | */
|
351 | public RouteControlPanel(Network network) {
|
||
352 | super();
|
||
353 | this.network = network;
|
||
354 | 8613 | fjp | // GvFlag[] flags = network.getFlags();
|
355 | // List vflags = _getFlags();
|
||
356 | // for (int i = 0; i < flags.length; i++) {
|
||
357 | // vflags.add(flags[i]);
|
||
358 | // }
|
||
359 | 8573 | azabala | initialize(); |
360 | } |
||
361 | 8641 | jaume | |
362 | 8573 | azabala | /**
|
363 | * Method to remove all flags (use
|
||
364 | * */
|
||
365 | public void refresh(){ |
||
366 | 8613 | fjp | // GvFlag[] flags = network.getFlags();
|
367 | // List vflags = _getFlags();
|
||
368 | // List tempFlags = Arrays.asList(flags);
|
||
369 | // vflags.addAll(tempFlags);
|
||
370 | 8573 | azabala | lblFlagAmout.setText(String.valueOf(_getFlags()
|
371 | .size())); |
||
372 | updateTotalCost(); |
||
373 | 12157 | fjp | ListSelectionModel rowSM = tblStages.getSelectionModel();
|
374 | if (_getFlags().size() == 0) |
||
375 | getBtnCenterOnFlag().setEnabled(false);
|
||
376 | else
|
||
377 | getBtnCenterOnFlag().setEnabled(!rowSM.isSelectionEmpty()); |
||
378 | 8636 | fjp | getTblStages().revalidate(); |
379 | System.out.println("Actualizo tabla"); |
||
380 | 8641 | jaume | |
381 | 8573 | azabala | } |
382 | 8606 | fjp | 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 | 8641 | jaume | |
397 | 8636 | fjp | public void setMapControl(MapControl mapCtrl, Network net) { |
398 | 8573 | azabala | 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 | 8636 | fjp | if (net != null) { |
409 | network = net; |
||
410 | network.addFlagListener(this);
|
||
411 | 8641 | jaume | } |
412 | 8573 | azabala | } |
413 | } |
||
414 | 8326 | jaume | |
415 | 8573 | azabala | public RouteControlPanel() {
|
416 | super();
|
||
417 | initialize(); |
||
418 | } |
||
419 | 8326 | jaume | |
420 | 8573 | azabala | public void setCostUnits(String unitsName) { |
421 | colName[2] = unitsName;
|
||
422 | getTblStages().repaint(); |
||
423 | } |
||
424 | 8521 | jaume | |
425 | 8573 | azabala | /**
|
426 | * This method initializes this
|
||
427 | 8641 | jaume | *
|
428 | 8573 | azabala | */
|
429 | private void initialize() { |
||
430 | BorderLayout borderLayout = new BorderLayout(); |
||
431 | borderLayout.setHgap(10);
|
||
432 | borderLayout.setVgap(10);
|
||
433 | JPanel cont = new JPanel(borderLayout); |
||
434 | 8641 | jaume | // cont.setPreferredSize(new Dimension(490, 320));
|
435 | 8647 | jaume | this.setPreferredSize(new Dimension(460, 280)); |
436 | 8641 | jaume | cont.add(getWestPanel(), BorderLayout.CENTER);
|
437 | cont.add(getEastPanel(), BorderLayout.EAST);
|
||
438 | 8573 | azabala | cont.add(getSouthPanel(), BorderLayout.SOUTH);
|
439 | 8641 | jaume | this.setLayout(new FlowLayout(FlowLayout.LEADING, 10, 10)); |
440 | 8573 | azabala | this.add(cont);
|
441 | updateFlags(); |
||
442 | } |
||
443 | 8326 | jaume | |
444 | 8573 | azabala | private void updateFlags() { |
445 | lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
||
446 | updateTotalCost(); |
||
447 | getTblStages().repaint(); |
||
448 | } |
||
449 | 8326 | jaume | |
450 | 8573 | azabala | 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 | 8326 | jaume | public Object getWindowModel() { |
467 | 8573 | azabala | return this.getClass(); |
468 | } |
||
469 | 8326 | jaume | |
470 | 8573 | azabala | public WindowInfo getWindowInfo() {
|
471 | if (wi == null) { |
||
472 | wi = new WindowInfo(WindowInfo.MODELESSDIALOG
|
||
473 | 8647 | jaume | | WindowInfo.MAXIMIZABLE |
474 | 8573 | azabala | | WindowInfo.ICONIFIABLE | WindowInfo.PALETTE); |
475 | 8647 | jaume | wi.setWidth((int) this.getPreferredSize().getWidth()); |
476 | wi.setHeight((int) this.getPreferredSize().getHeight()); |
||
477 | 8639 | fjp | wi.setTitle(PluginServices.getText(this, "route_control_panel")); |
478 | 8573 | azabala | } |
479 | return wi;
|
||
480 | } |
||
481 | 8326 | jaume | |
482 | 8573 | azabala | /**
|
483 | * This method initializes westPanel
|
||
484 | 8641 | jaume | *
|
485 | 8573 | azabala | * @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 | 8326 | jaume | |
497 | 8573 | azabala | westPanel.add(aux); |
498 | } |
||
499 | return westPanel;
|
||
500 | } |
||
501 | 8326 | jaume | |
502 | 8573 | azabala | private JButton getBtnPullDownStage() { |
503 | 8326 | jaume | if (btnPullDownStage == null) { |
504 | 8573 | azabala | btnPullDownStage = new JButton(new ImageIcon(this.getClass() |
505 | .getClassLoader().getResource("images/down-arrow.png")));
|
||
506 | // btnPullDownStage.setName("btnPullDownStage");
|
||
507 | 8326 | jaume | btnPullDownStage.addActionListener(this);
|
508 | } |
||
509 | return btnPullDownStage;
|
||
510 | } |
||
511 | |||
512 | private JButton getBtnPushUpStage() { |
||
513 | if (btnPushUpStage == null) { |
||
514 | 8573 | azabala | btnPushUpStage = new JButton(new ImageIcon(this.getClass() |
515 | .getClassLoader().getResource("images/up-arrow.png")));
|
||
516 | // btnPushUpStage.setName("btnPushUpStage");
|
||
517 | 8326 | jaume | btnPushUpStage.addActionListener(this);
|
518 | } |
||
519 | return btnPushUpStage;
|
||
520 | } |
||
521 | |||
522 | private JButton getBtnRemoveStage() { |
||
523 | if (btnRemoveStage == null) { |
||
524 | 8573 | azabala | btnRemoveStage = new JButton(new ImageIcon(this.getClass() |
525 | .getClassLoader().getResource("images/delete.png")));
|
||
526 | // btnRemoveStage.setName("btnRemoveStage");
|
||
527 | 8326 | jaume | btnRemoveStage.addActionListener(this);
|
528 | } |
||
529 | return btnRemoveStage;
|
||
530 | } |
||
531 | |||
532 | /**
|
||
533 | 8573 | azabala | * This method initializes scrlStages
|
534 | 8641 | jaume | *
|
535 | 8573 | azabala | * @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 | 8326 | jaume | |
546 | 8606 | fjp | /**
|
547 | * @deprecated
|
||
548 | * @param flag
|
||
549 | */
|
||
550 | 8573 | azabala | public void addFlag(GvFlag flag) { |
551 | _getFlags().add(flag); |
||
552 | lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
||
553 | updateTotalCost(); |
||
554 | getTblStages().repaint(); |
||
555 | } |
||
556 | 8326 | jaume | |
557 | 8573 | azabala | private void updateTotalCost() { |
558 | GvFlag[] flags = getFlags();
|
||
559 | double cost = 0; |
||
560 | for (int i = 0; i < flags.length; i++) { |
||
561 | 8762 | fjp | 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 | 11631 | fjp | |
574 | 8365 | jaume | cost += flags[i].getCost(); |
575 | } |
||
576 | 8762 | fjp | NumberFormat nf = NumberFormat.getInstance(); |
577 | nf.setMaximumFractionDigits(2);
|
||
578 | lblCost.setText(nf.format(cost) + getCostUnitName()); |
||
579 | 8365 | jaume | } |
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 | 8573 | azabala | removeFlag(_getFlags().indexOf(flag)); |
589 | } |
||
590 | 8326 | jaume | |
591 | 8573 | azabala | public void removeFlag(int index) { |
592 | _getFlags().remove(index); |
||
593 | lblFlagAmout.setText(String.valueOf(_getFlags().size()));
|
||
594 | getTblStages().repaint(); |
||
595 | } |
||
596 | 8326 | jaume | |
597 | 8573 | azabala | /**
|
598 | * This method initializes tblStages
|
||
599 | 8641 | jaume | *
|
600 | 8573 | azabala | * @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 | 8326 | jaume | |
610 | 8573 | azabala | 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 | 8762 | fjp | |
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 | 12157 | fjp | if (e.getValueIsAdjusting())
|
629 | return;
|
||
630 | 8762 | fjp | |
631 | ListSelectionModel lsm =
|
||
632 | (ListSelectionModel)e.getSource();
|
||
633 | getBtnCenterOnFlag().setEnabled(!lsm.isSelectionEmpty()); |
||
634 | } |
||
635 | }); |
||
636 | 11631 | fjp | |
637 | 8762 | fjp | tblStages.getModel().addTableModelListener(new TableModelListener() { |
638 | |||
639 | public void tableChanged(TableModelEvent e) { |
||
640 | System.out.println("Table model changed"); |
||
641 | 12157 | fjp | // getBtnCenterOnFlag().setEnabled(false);
|
642 | 8762 | fjp | } |
643 | 11631 | fjp | |
644 | 8762 | fjp | }); |
645 | |||
646 | 11631 | fjp | |
647 | 8573 | azabala | } |
648 | return tblStages;
|
||
649 | } |
||
650 | 8326 | jaume | |
651 | 8573 | azabala | protected int getFlagCount() { |
652 | return _getFlags().size();
|
||
653 | } |
||
654 | 8326 | jaume | |
655 | 8573 | azabala | private List _getFlags() { |
656 | 8606 | fjp | // if (routeFlags == null) {
|
657 | // routeFlags = new ArrayList();
|
||
658 | // }
|
||
659 | // return routeFlags;
|
||
660 | 8641 | jaume | |
661 | 8606 | fjp | return network.getOriginaFlags();
|
662 | 8573 | azabala | } |
663 | 8326 | jaume | |
664 | 8573 | azabala | protected boolean isSelected(int row) { |
665 | return ((GvFlag) _getFlags().get(row)).isEnabled();
|
||
666 | } |
||
667 | 8326 | jaume | |
668 | 8573 | azabala | /**
|
669 | * This method initializes eastPanel
|
||
670 | 8641 | jaume | *
|
671 | 8573 | azabala | * @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 | 8751 | fjp | aux.add(getBtnCenterOnFlag()); |
683 | 12157 | fjp | aux.add(getBtnSetVelocities()); |
684 | 8573 | azabala | layout.setRows(aux.getComponentCount()); |
685 | aux.setLayout(layout); |
||
686 | eastPanel = new GridBagLayoutPanel();
|
||
687 | eastPanel.addComponent(aux); |
||
688 | } |
||
689 | return eastPanel;
|
||
690 | 8401 | jaume | } |
691 | |||
692 | 8751 | fjp | private JButton getBtnCenterOnFlag() { |
693 | if (btnCenterOnFlag == null) { |
||
694 | btnCenterOnFlag = new JButton(); |
||
695 | btnCenterOnFlag.setText(PluginServices.getText(this,
|
||
696 | "center_on_flag"));
|
||
697 | 8762 | fjp | btnCenterOnFlag.setEnabled(false);
|
698 | 8751 | fjp | btnCenterOnFlag.addActionListener(this);
|
699 | } |
||
700 | return btnCenterOnFlag;
|
||
701 | } |
||
702 | 8573 | azabala | |
703 | 12157 | fjp | 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 | 8401 | jaume | private JButton getBtnSaveRoute() { |
719 | 8573 | azabala | 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 | 8401 | jaume | |
727 | /**
|
||
728 | 8573 | azabala | * This method initializes defaultTableModel
|
729 | 8641 | jaume | *
|
730 | 8573 | azabala | * @return javax.swing.table.DefaultTableModel
|
731 | */
|
||
732 | private TableModel getTableModel() { |
||
733 | return tableModel;
|
||
734 | } |
||
735 | 8521 | jaume | |
736 | 8573 | azabala | /**
|
737 | * This method initializes btnLoadStage
|
||
738 | 8641 | jaume | *
|
739 | 8573 | azabala | * @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 | 8521 | jaume | |
750 | 8573 | azabala | /**
|
751 | * This method initializes btnSaveStages
|
||
752 | 8641 | jaume | *
|
753 | 8573 | azabala | * @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 | 8521 | jaume | |
764 | 8573 | azabala | class FormatSelectionPanel extends JPanel implements IWindow { |
765 | 8521 | jaume | |
766 | 8573 | azabala | JComboBox formats;
|
767 | WindowInfo wi = null;
|
||
768 | 8521 | jaume | |
769 | 8623 | azabala | public FormatSelectionPanel(String introductoryText) { |
770 | 8573 | azabala | super(new BorderLayout()); |
771 | String[] formatos = { "SHP", "DXF", "POSTGIS", "GML" }; |
||
772 | formats = new JComboBox(formatos); |
||
773 | 8641 | jaume | GridBagLayoutPanel contentPanel = |
774 | 8573 | azabala | new GridBagLayoutPanel();
|
775 | 8623 | azabala | contentPanel.addComponent(new JLabel(introductoryText)); |
776 | 8573 | azabala | 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 | 8521 | jaume | } |
783 | 8573 | azabala | }); |
784 | contentPanel.addComponent(okButton); |
||
785 | 8641 | jaume | |
786 | 8573 | azabala | add(contentPanel); |
787 | } |
||
788 | 8521 | jaume | |
789 | 8573 | azabala | void close() {
|
790 | PluginServices.getMDIManager().closeWindow(this);
|
||
791 | } |
||
792 | 8521 | jaume | |
793 | 8573 | azabala | public String getSelectedFormat() { |
794 | return (String) formats.getSelectedItem(); |
||
795 | } |
||
796 | 8521 | jaume | |
797 | 8573 | azabala | 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 | 8623 | azabala | wi.setHeight(55);
|
805 | 8573 | azabala | } |
806 | return wi;
|
||
807 | } |
||
808 | 8521 | jaume | |
809 | 8573 | azabala | } |
810 | 8521 | jaume | |
811 | 8573 | azabala | 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 | 8401 | jaume | } else if (c.equals(getBtnPushUpStage())) { |
818 | 8326 | jaume | 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 | 8573 | azabala | Object aux = _getFlags().get(selected[i] - 1); |
824 | _getFlags().set(selected[i] - 1, _getFlags().get(selected[i]));
|
||
825 | 8326 | jaume | _getFlags().set(selected[i], aux); |
826 | selected[i]--; |
||
827 | tblStages.addRowSelectionInterval(selected[i], selected[i]); |
||
828 | } |
||
829 | 8762 | fjp | invalidateSolution(); |
830 | 8401 | jaume | } else if (c.equals(getBtnPullDownStage())) { |
831 | 8326 | jaume | // pull down
|
832 | int[] selected = tblStages.getSelectedRows(); |
||
833 | 8573 | azabala | if (selected.length == 0 |
834 | || selected[selected.length - 1] >= _getFlags().size() - 1) |
||
835 | 8326 | jaume | return;
|
836 | |||
837 | // move rows
|
||
838 | tblStages.clearSelection(); |
||
839 | 8573 | azabala | 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 | 8326 | jaume | _getFlags().set(selected[i], aux); |
843 | selected[i]++; |
||
844 | tblStages.addRowSelectionInterval(selected[i], selected[i]); |
||
845 | } |
||
846 | 8762 | fjp | invalidateSolution(); |
847 | 8326 | jaume | |
848 | 8401 | jaume | } else if (c.equals(getBtnRemoveStage())) { |
849 | 11631 | fjp | removeStage(); |
850 | 8573 | azabala | } else if (c.equals(getBtnSaveRoute())) { |
851 | saveRoute(); |
||
852 | 12157 | fjp | } else if (c.equals(getBtnSetVelocities())) { |
853 | setVelocities(); |
||
854 | 8751 | fjp | } 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 | 8762 | fjp | double width = extent.getWidth();
|
869 | double height = extent.getHeight();
|
||
870 | 11631 | fjp | |
871 | 8751 | fjp | Rectangle2D.Double r = new Rectangle2D.Double(); |
872 | 11631 | fjp | |
873 | 8762 | fjp | r.width = width; |
874 | r.height = height; |
||
875 | r.x = xNC - width/2;
|
||
876 | r.y = yNC - height/2;
|
||
877 | 8751 | fjp | |
878 | vp.setExtent(r); |
||
879 | |||
880 | 11631 | fjp | |
881 | |||
882 | 8751 | fjp | } |
883 | 8573 | azabala | repaint(); |
884 | } |
||
885 | |||
886 | 12157 | fjp | 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 | 8762 | fjp | 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 | 8573 | azabala | private void saveStage(){ |
955 | 8623 | azabala | 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 | 8573 | azabala | return;
|
973 | 8641 | jaume | |
974 | 8573 | azabala | List features = new ArrayList(); |
975 | 8623 | azabala | GvFlag[] flags = network.getFlags();
|
976 | 8573 | azabala | for(int i = 0; i < flags.length; i++){ |
977 | GvFlag flag = flags[i]; |
||
978 | 8751 | fjp | // Solo se guardan los flags habilitados
|
979 | if (!flag.isEnabled())
|
||
980 | continue;
|
||
981 | 8573 | azabala | 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 | 8641 | jaume | |
994 | 8573 | azabala | FlagsMemoryDriver driver = new FlagsMemoryDriver(features);
|
995 | IProjection projection = FOpenDialog.getLastProjection(); |
||
996 | 8623 | azabala | FLyrVect routeLayer = (FLyrVect) LayerFactory.createLayer("Flags",
|
997 | 8573 | azabala | driver, projection); |
998 | |||
999 | 8641 | jaume | FormatSelectionPanel selectionPanel = |
1000 | 8623 | azabala | new FormatSelectionPanel(PluginServices.
|
1001 | getText(null,
|
||
1002 | "Seleccione_un_formato_para_guardar_los_flags"));
|
||
1003 | 8573 | azabala | PluginServices.getMDIManager().addWindow(selectionPanel); |
1004 | |||
1005 | String format = selectionPanel.getSelectedFormat();
|
||
1006 | com.iver.cit.gvsig.ExportTo export = new com.iver.cit.gvsig.ExportTo(); |
||
1007 | 8623 | azabala | IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
1008 | if(! (window instanceof IView)) |
||
1009 | return;
|
||
1010 | IView view = (View) window;
|
||
1011 | MapControl mapControl = view.getMapControl(); |
||
1012 | 8573 | azabala | 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 | 8513 | azabala | } |
1023 | 8573 | azabala | } 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 | 8521 | jaume | |
1031 | 8573 | azabala | } |
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 | 8659 | azabala | 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 | 8623 | azabala | return;
|
1044 | 11631 | fjp | } |
1045 | 8659 | azabala | Route lastRoute = (Route) routes.get(routes.size() - 1);
|
1046 | RouteMemoryDriver driver = new RouteMemoryDriver(lastRoute.getFeatureList());
|
||
1047 | 8573 | azabala | IProjection projection = FOpenDialog.getLastProjection(); |
1048 | FLyrVect routeLayer = (FLyrVect) LayerFactory.createLayer("Route",
|
||
1049 | driver, projection); |
||
1050 | 8521 | jaume | |
1051 | 8623 | azabala | FormatSelectionPanel selectionPanel = new FormatSelectionPanel(PluginServices.getText(null, |
1052 | "Seleccione_un_formato_para_guardar_la_ruta"));
|
||
1053 | 8573 | azabala | PluginServices.getMDIManager().addWindow(selectionPanel); |
1054 | 8521 | jaume | |
1055 | 8573 | azabala | 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 | 8521 | jaume | |
1077 | 8573 | azabala | /**
|
1078 | * Converts a point layer loaded in the active view's toc in a collection of
|
||
1079 | * flags of the active network
|
||
1080 | 8641 | jaume | *
|
1081 | 8573 | azabala | */
|
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 | 8723 | fjp | // Hay que refinar bastante, para que el usuario elija
|
1117 | 8573 | azabala | // 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 | 8673 | fjp | // Por si queremos a?adir paradas a otras ya existentes
|
1133 | // _getFlags().clear();
|
||
1134 | 11631 | fjp | |
1135 | 8573 | azabala | GvFlag flag; |
1136 | ReadableVectorial reader = vectLyr.getSource(); |
||
1137 | 8626 | azabala | SelectableDataSource recordset = vectLyr.getRecordset(); |
1138 | 8573 | azabala | int numShapes = reader.getShapeCount();
|
1139 | |||
1140 | 8723 | fjp | double realTol = mapCtrl.getViewPort()
|
1141 | .toMapDistance(FlagListener.pixelTolerance); |
||
1142 | 11296 | caballero | reader.start(); |
1143 | 8573 | azabala | 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 | 11631 | fjp | |
1148 | |||
1149 | 8573 | azabala | |
1150 | Coordinate[] coords = geo.getCoordinates();
|
||
1151 | for (int j = 0; j < coords.length; j++) { |
||
1152 | 8641 | jaume | |
1153 | 8723 | fjp | try {
|
1154 | flag = net.addFlag(coords[j].x, coords[j].y, realTol); |
||
1155 | 11805 | fjp | 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 | 8723 | fjp | } catch (GraphException e) {
|
1174 | e.printStackTrace(); |
||
1175 | 11631 | fjp | NotificationManager.addError("No se puedo situar el registro " + i +
|
1176 | 8723 | fjp | "Por favor, compruebe que est? encima de la red.", e);
|
1177 | } |
||
1178 | 8573 | azabala | |
1179 | 11631 | fjp | } // for j
|
1180 | } // for i
|
||
1181 | 11296 | caballero | reader.stop(); |
1182 | 11631 | fjp | mapControl.drawGraphics(); |
1183 | PluginServices.getMainFrame().enableControls(); |
||
1184 | 8326 | jaume | |
1185 | 8573 | azabala | } catch (DriverException e1) {
|
1186 | return;
|
||
1187 | } catch (DriverIOException e2) {
|
||
1188 | return;
|
||
1189 | } |
||
1190 | } |
||
1191 | } |
||
1192 | 8326 | jaume | |
1193 | 8573 | azabala | /**
|
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 | 8641 | jaume | *
|
1197 | 8573 | azabala | */
|
1198 | private void removeStage() { |
||
1199 | int[] selected = tblStages.getSelectedRows(); |
||
1200 | |||
1201 | for (int i = selected.length - 1; i >= 0; i--) { |
||
1202 | try {
|
||
1203 | 8616 | fjp | // removeFlag(selected[i]);
|
1204 | if (network != null) { |
||
1205 | 8573 | azabala | final GvFlag flag = (GvFlag) _getFlags().get(selected[i]);
|
1206 | 8616 | fjp | NetworkUtils.clearFlagFromGraphics(mapCtrl, flag); |
1207 | network.removeFlag(flag); |
||
1208 | mapCtrl.repaint(); |
||
1209 | 8573 | azabala | } |
1210 | } catch (IndexOutOfBoundsException iobEx) { |
||
1211 | } |
||
1212 | |||
1213 | }// for
|
||
1214 | tblStages.clearSelection(); |
||
1215 | 8762 | fjp | invalidateSolution(); |
1216 | 8616 | fjp | mapCtrl.drawMap(false);
|
1217 | 8326 | jaume | } |
1218 | |||
1219 | public GvFlag[] getFlags() { |
||
1220 | return (GvFlag[]) _getFlags().toArray(new GvFlag[0]); |
||
1221 | } |
||
1222 | 8606 | fjp | |
1223 | public void flagsChanged(int reason) { |
||
1224 | refresh(); |
||
1225 | 8616 | fjp | mapCtrl.drawGraphics(); |
1226 | 8641 | jaume | |
1227 | 8606 | fjp | } |
1228 | 8573 | azabala | } // @jve:decl-index=0:visual-constraint="17,9" |