1 | package public_transport;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import org.openstreetmap.josm.Main;
|
---|
6 | import org.openstreetmap.josm.command.Command;
|
---|
7 | import org.openstreetmap.josm.data.osm.Node;
|
---|
8 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
9 |
|
---|
10 | import java.util.Collection;
|
---|
11 | import java.util.Iterator;
|
---|
12 | import java.util.Vector;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 |
|
---|
15 | public class GTFSCatchCommand extends Command
|
---|
16 | {
|
---|
17 | private Vector< Integer > workingLines = null;
|
---|
18 | private Node undoMapNode = null;
|
---|
19 | private Node undoTableNode = null;
|
---|
20 | private GTFSStopTableModel gtfsStopTM = null;
|
---|
21 | private String type = null;
|
---|
22 |
|
---|
23 | public GTFSCatchCommand(GTFSImporterAction controller)
|
---|
24 | {
|
---|
25 | gtfsStopTM = controller.getGTFSStopTableModel();
|
---|
26 | workingLines = new Vector< Integer >();
|
---|
27 |
|
---|
28 | // use either selected lines or all lines if no line is selected
|
---|
29 | int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows();
|
---|
30 | if (selectedLines.length != 1)
|
---|
31 | return;
|
---|
32 | workingLines.add(selectedLines[0]);
|
---|
33 | }
|
---|
34 |
|
---|
35 | public boolean executeCommand()
|
---|
36 | {
|
---|
37 | if (workingLines.size() != 1)
|
---|
38 | return false;
|
---|
39 | Node dest = null;
|
---|
40 | Iterator< Node > iter =
|
---|
41 | Main.main.getCurrentDataSet().getSelectedNodes().iterator();
|
---|
42 | int j = workingLines.elementAt(0);
|
---|
43 | while (iter.hasNext())
|
---|
44 | {
|
---|
45 | Node n = iter.next();
|
---|
46 | if ((n != null) && (n.equals(gtfsStopTM.nodes.elementAt(j))))
|
---|
47 | continue;
|
---|
48 | if (dest != null)
|
---|
49 | return false;
|
---|
50 | dest = n;
|
---|
51 | }
|
---|
52 | if (dest == null)
|
---|
53 | return false;
|
---|
54 | undoMapNode = new Node(dest);
|
---|
55 |
|
---|
56 | Node node = gtfsStopTM.nodes.elementAt(j);
|
---|
57 | undoTableNode = node;
|
---|
58 | if (node != null)
|
---|
59 | {
|
---|
60 | Main.main.getCurrentDataSet().removePrimitive(node);
|
---|
61 | node.setDeleted(true);
|
---|
62 | }
|
---|
63 |
|
---|
64 | dest.setCoor(gtfsStopTM.coors.elementAt(j));
|
---|
65 | dest.put("highway", "bus_stop");
|
---|
66 | dest.put("stop_id", (String)gtfsStopTM.getValueAt(j, 0));
|
---|
67 | if (dest.get("name") == null)
|
---|
68 | dest.put("name", (String)gtfsStopTM.getValueAt(j, 1));
|
---|
69 | dest.put("note", "moved by gtfs import");
|
---|
70 | gtfsStopTM.nodes.set(j, dest);
|
---|
71 | type = (String)gtfsStopTM.getValueAt(j, 2);
|
---|
72 | gtfsStopTM.setValueAt("fed", j, 2);
|
---|
73 |
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public void undoCommand()
|
---|
78 | {
|
---|
79 | if (workingLines.size() != 1)
|
---|
80 | return;
|
---|
81 | int j = workingLines.elementAt(0);
|
---|
82 |
|
---|
83 | Node node = gtfsStopTM.nodes.elementAt(j);
|
---|
84 | if (node != null)
|
---|
85 | {
|
---|
86 | Main.main.getCurrentDataSet().removePrimitive(node);
|
---|
87 | node.setDeleted(true);
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (undoMapNode != null)
|
---|
91 | {
|
---|
92 | undoMapNode.setDeleted(false);
|
---|
93 | Main.main.getCurrentDataSet().addPrimitive(undoMapNode);
|
---|
94 | }
|
---|
95 | if (undoTableNode != null)
|
---|
96 | {
|
---|
97 | undoTableNode.setDeleted(false);
|
---|
98 | Main.main.getCurrentDataSet().addPrimitive(undoTableNode);
|
---|
99 | }
|
---|
100 | gtfsStopTM.nodes.set(j, undoTableNode);
|
---|
101 | gtfsStopTM.setValueAt(type, j, 2);
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void fillModifiedData
|
---|
105 | (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted,
|
---|
106 | Collection< OsmPrimitive > added)
|
---|
107 | {
|
---|
108 | }
|
---|
109 |
|
---|
110 | @Override public JLabel getDescription()
|
---|
111 | {
|
---|
112 | return new JLabel(tr("Public Transport: Catch GTFS stops"));
|
---|
113 | }
|
---|
114 | };
|
---|