Changeset 33010 in osm for applications/editors/josm
- Timestamp:
- 2016-09-24T02:24:22+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/public_transport/src/public_transport
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSCatchCommand.java
r32357 r33010 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.util.Collection; 6 import java.util.Iterator; 7 import java.util.Vector; 8 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.command.Command; 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.Node; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 15 public class GTFSCatchCommand extends Command { 16 private Vector<Integer> workingLines = null; 17 18 private Node undoMapNode = null; 19 20 private Node undoTableNode = null; 21 22 private GTFSStopTableModel gtfsStopTM = null; 23 24 private String type = null; 5 public class GTFSCatchCommand extends AbstractGTFSCatchJoinCommand { 25 6 26 7 public GTFSCatchCommand(GTFSImporterAction controller) { 27 gtfsStopTM = controller.getGTFSStopTableModel(); 28 workingLines = new Vector<>(); 29 30 // use either selected lines or all lines if no line is selected 31 int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows(); 32 if (selectedLines.length != 1) 33 return; 34 workingLines.add(selectedLines[0]); 35 } 36 37 @Override 38 public boolean executeCommand() { 39 if (workingLines.size() != 1) 40 return false; 41 Node dest = null; 42 DataSet ds = Main.getLayerManager().getEditDataSet(); 43 Iterator<Node> iter = ds.getSelectedNodes().iterator(); 44 int j = workingLines.elementAt(0); 45 while (iter.hasNext()) { 46 Node n = iter.next(); 47 if ((n != null) && (n.equals(gtfsStopTM.nodes.elementAt(j)))) 48 continue; 49 if (dest != null) 50 return false; 51 dest = n; 52 } 53 if (dest == null) 54 return false; 55 undoMapNode = new Node(dest); 56 57 Node node = gtfsStopTM.nodes.elementAt(j); 58 undoTableNode = node; 59 if (node != null) { 60 ds.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 @Override 78 public void undoCommand() { 79 if (workingLines.size() != 1) 80 return; 81 int j = workingLines.elementAt(0); 82 83 DataSet ds = Main.getLayerManager().getEditDataSet(); 84 Node node = gtfsStopTM.nodes.elementAt(j); 85 if (node != null) { 86 ds.removePrimitive(node); 87 node.setDeleted(true); 88 } 89 90 if (undoMapNode != null) { 91 undoMapNode.setDeleted(false); 92 ds.addPrimitive(undoMapNode); 93 } 94 if (undoTableNode != null) { 95 undoTableNode.setDeleted(false); 96 ds.addPrimitive(undoTableNode); 97 } 98 gtfsStopTM.nodes.set(j, undoTableNode); 99 gtfsStopTM.setValueAt(type, j, 2); 100 } 101 102 @Override 103 public void fillModifiedData(Collection<OsmPrimitive> modified, 104 Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 8 super(controller, true); 105 9 } 106 10 -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSJoinCommand.java
r32357 r33010 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.util.Collection; 6 import java.util.Iterator; 7 import java.util.Vector; 8 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.command.Command; 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.Node; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 15 public class GTFSJoinCommand extends Command { 16 private Vector<Integer> workingLines = null; 17 18 private Node undoMapNode = null; 19 20 private Node undoTableNode = null; 21 22 private GTFSStopTableModel gtfsStopTM = null; 23 24 private String type = null; 5 public class GTFSJoinCommand extends AbstractGTFSCatchJoinCommand { 25 6 26 7 public GTFSJoinCommand(GTFSImporterAction controller) { 27 gtfsStopTM = controller.getGTFSStopTableModel(); 28 workingLines = new Vector<>(); 29 30 // use either selected lines or all lines if no line is selected 31 int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows(); 32 if (selectedLines.length != 1) 33 return; 34 workingLines.add(selectedLines[0]); 35 } 36 37 @Override 38 public boolean executeCommand() { 39 if (workingLines.size() != 1) 40 return false; 41 Node dest = null; 42 DataSet ds = Main.getLayerManager().getEditDataSet(); 43 Iterator<Node> iter = ds.getSelectedNodes().iterator(); 44 int j = workingLines.elementAt(0); 45 while (iter.hasNext()) { 46 Node n = iter.next(); 47 if ((n != null) && (n.equals(gtfsStopTM.nodes.elementAt(j)))) 48 continue; 49 if (dest != null) 50 return false; 51 dest = n; 52 } 53 if (dest == null) 54 return false; 55 undoMapNode = new Node(dest); 56 57 Node node = gtfsStopTM.nodes.elementAt(j); 58 undoTableNode = node; 59 if (node != null) { 60 ds.removePrimitive(node); 61 node.setDeleted(true); 62 } 63 64 dest.put("highway", "bus_stop"); 65 dest.put("stop_id", (String) gtfsStopTM.getValueAt(j, 0)); 66 if (dest.get("name") == null) 67 dest.put("name", (String) gtfsStopTM.getValueAt(j, 1)); 68 gtfsStopTM.nodes.set(j, dest); 69 type = (String) gtfsStopTM.getValueAt(j, 2); 70 gtfsStopTM.setValueAt(tr("moved"), j, 2); 71 72 return true; 73 } 74 75 @Override 76 public void undoCommand() { 77 if (workingLines.size() != 1) 78 return; 79 int j = workingLines.elementAt(0); 80 81 DataSet ds = Main.getLayerManager().getEditDataSet(); 82 Node node = gtfsStopTM.nodes.elementAt(j); 83 if (node != null) { 84 ds.removePrimitive(node); 85 node.setDeleted(true); 86 } 87 88 if (undoMapNode != null) { 89 undoMapNode.setDeleted(false); 90 ds.addPrimitive(undoMapNode); 91 } 92 if (undoTableNode != null) { 93 undoTableNode.setDeleted(false); 94 ds.addPrimitive(undoTableNode); 95 } 96 gtfsStopTM.nodes.set(j, undoTableNode); 97 gtfsStopTM.setValueAt(type, j, 2); 98 } 99 100 @Override 101 public void fillModifiedData(Collection<OsmPrimitive> modified, 102 Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 8 super(controller, false); 103 9 } 104 10 … … 107 13 return tr("Public Transport: Join GTFS stops"); 108 14 } 109 } ;15 }
Note:
See TracChangeset
for help on using the changeset viewer.