1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.Collections;
|
---|
10 | import java.util.LinkedList;
|
---|
11 |
|
---|
12 | import javax.swing.JOptionPane;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.command.ChangeCommand;
|
---|
16 | import org.openstreetmap.josm.command.Command;
|
---|
17 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
18 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
19 | import org.openstreetmap.josm.data.osm.Node;
|
---|
20 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
21 | import org.openstreetmap.josm.data.osm.Way;
|
---|
22 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
23 |
|
---|
24 | public final class ReverseWayAction extends JosmAction {
|
---|
25 |
|
---|
26 | public ReverseWayAction() {
|
---|
27 | super(tr("Reverse ways"), "wayflip",
|
---|
28 | tr("Reverse the direction of all selected ways."),
|
---|
29 | KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public void actionPerformed(ActionEvent e) {
|
---|
33 | final Collection<Way> sel = new LinkedList<Way>();
|
---|
34 | new Visitor(){
|
---|
35 | public void visit(Node n) {}
|
---|
36 | public void visit(Way w) {sel.add(w);}
|
---|
37 | public void visit(Relation e){}
|
---|
38 | public void visitAll() {
|
---|
39 | for (OsmPrimitive osm : Main.ds.getSelected())
|
---|
40 | osm.visit(this);
|
---|
41 | }
|
---|
42 | }.visitAll();
|
---|
43 |
|
---|
44 | if (sel.isEmpty()) {
|
---|
45 | JOptionPane.showMessageDialog(Main.parent,
|
---|
46 | tr("Please select at least one way."));
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | Collection<Command> c = new LinkedList<Command>();
|
---|
50 | for (Way w : sel) {
|
---|
51 | Way wnew = new Way(w);
|
---|
52 | Collections.reverse(wnew.nodes);
|
---|
53 | c.add(new ChangeCommand(w, wnew));
|
---|
54 | }
|
---|
55 | Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
|
---|
56 | Main.map.repaint();
|
---|
57 | }
|
---|
58 | }
|
---|