source: josm/branch/0.5/src/org/openstreetmap/josm/actions/ReverseWayAction.java@ 330

Last change on this file since 330 was 330, checked in by framm, 17 years ago

forgot to add some files...

File size: 1.8 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9import java.util.Collections;
10import java.util.LinkedList;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.command.ChangeCommand;
16import org.openstreetmap.josm.command.Command;
17import org.openstreetmap.josm.command.SequenceCommand;
18import org.openstreetmap.josm.data.osm.Relation;
19import org.openstreetmap.josm.data.osm.Node;
20import org.openstreetmap.josm.data.osm.OsmPrimitive;
21import org.openstreetmap.josm.data.osm.Way;
22import org.openstreetmap.josm.data.osm.visitor.Visitor;
23
24public 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}
Note: See TracBrowser for help on using the repository browser.