1 | /**
|
---|
2 | *
|
---|
3 | */
|
---|
4 | package org.openstreetmap.josm.actions;
|
---|
5 |
|
---|
6 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
7 |
|
---|
8 | import java.awt.event.ActionEvent;
|
---|
9 | import java.awt.event.KeyEvent;
|
---|
10 | import java.util.Collection;
|
---|
11 | import java.util.LinkedList;
|
---|
12 |
|
---|
13 | import javax.swing.JOptionPane;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.command.ChangeCommand;
|
---|
17 | import org.openstreetmap.josm.command.Command;
|
---|
18 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
19 | import org.openstreetmap.josm.data.osm.Node;
|
---|
20 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
21 | import org.openstreetmap.josm.data.osm.Segment;
|
---|
22 |
|
---|
23 | public final class ReverseSegmentAction extends JosmAction {
|
---|
24 |
|
---|
25 | public ReverseSegmentAction() {
|
---|
26 | super(tr("Reverse Segments"), "segmentflip", tr("Revert the direction of all selected Segments."), KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK);
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void actionPerformed(ActionEvent e) {
|
---|
30 | Collection<OsmPrimitive> sel = Main.ds.getSelected();
|
---|
31 | boolean hasSegments = false;
|
---|
32 | for (OsmPrimitive osm : sel) {
|
---|
33 | if (osm instanceof Segment) {
|
---|
34 | hasSegments = true;
|
---|
35 | break;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | if (!hasSegments) {
|
---|
39 | JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one segment."));
|
---|
40 | return;
|
---|
41 | }
|
---|
42 | Collection<Command> c = new LinkedList<Command>();
|
---|
43 | for (OsmPrimitive osm : sel) {
|
---|
44 | if (!(osm instanceof Segment))
|
---|
45 | continue;
|
---|
46 | Segment s = (Segment)osm;
|
---|
47 | Segment snew = new Segment(s);
|
---|
48 | Node n = snew.from;
|
---|
49 | snew.from = snew.to;
|
---|
50 | snew.to = n;
|
---|
51 | c.add(new ChangeCommand(s, snew));
|
---|
52 | }
|
---|
53 | Main.main.editLayer().add(new SequenceCommand(tr("Reverse Segments"), c));
|
---|
54 | Main.map.repaint();
|
---|
55 | }
|
---|
56 | }
|
---|