source: osm/applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsNameCommand.java@ 20867

Last change on this file since 20867 was 20867, checked in by roland, 14 years ago

Public Transport Plugin: Key accelerators

File size: 2.5 KB
Line 
1package public_transport;
2
3import org.openstreetmap.josm.Main;
4import org.openstreetmap.josm.command.Command;
5import org.openstreetmap.josm.data.osm.Node;
6import org.openstreetmap.josm.data.osm.OsmPrimitive;
7
8import java.util.Collection;
9import java.util.Vector;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.MutableTreeNode;
12
13public class WaypointsNameCommand extends Command
14{
15 private int workingLine = 0;
16 private WaypointTableModel waypointTM = null;
17 private String oldName = null;
18 private String name = null;
19 private String oldShelter = null;
20 private String shelter = null;
21
22 public WaypointsNameCommand
23 (WaypointTableModel waypointTM, int workingLine, String name, String shelter)
24 {
25 this.waypointTM = waypointTM;
26 this.workingLine = workingLine;
27 if (waypointTM.nodes.elementAt(workingLine) != null)
28 {
29 oldName = waypointTM.nodes.elementAt(workingLine).get("name");
30 oldShelter = waypointTM.nodes.elementAt(workingLine).get("shelter");
31 }
32 this.name = name;
33 this.shelter = shelter;
34 if ("".equals(shelter))
35 this.shelter = null;
36 }
37
38 public boolean executeCommand()
39 {
40 if (waypointTM.nodes.elementAt(workingLine) != null)
41 {
42 waypointTM.nodes.elementAt(workingLine).put("name", name);
43 waypointTM.nodes.elementAt(workingLine).put("shelter", shelter);
44 }
45 waypointTM.inEvent = true;
46 if (name == null)
47 waypointTM.setValueAt("", workingLine, 1);
48 else
49 waypointTM.setValueAt(name, workingLine, 1);
50 if (shelter == null)
51 waypointTM.setValueAt("", workingLine, 2);
52 else
53 waypointTM.setValueAt(shelter, workingLine, 2);
54 waypointTM.inEvent = false;
55 return true;
56 }
57
58 public void undoCommand()
59 {
60 if (waypointTM.nodes.elementAt(workingLine) != null)
61 {
62 waypointTM.nodes.elementAt(workingLine).put("name", oldName);
63 waypointTM.nodes.elementAt(workingLine).put("shelter", oldShelter);
64 }
65 waypointTM.inEvent = true;
66 if (oldName == null)
67 waypointTM.setValueAt("", workingLine, 1);
68 else
69 waypointTM.setValueAt(oldName, workingLine, 1);
70 if (oldShelter == null)
71 waypointTM.setValueAt("", workingLine, 2);
72 else
73 waypointTM.setValueAt(oldShelter, workingLine, 2);
74 waypointTM.inEvent = false;
75 }
76
77 public void fillModifiedData
78 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted,
79 Collection< OsmPrimitive > added)
80 {
81 }
82
83 public MutableTreeNode description()
84 {
85 return new DefaultMutableTreeNode("public_transport.Waypoints.EditName");
86 }
87};
Note: See TracBrowser for help on using the repository browser.