source: josm/trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java@ 1222

Last change on this file since 1222 was 1218, checked in by ulfl, 15 years ago

fix capitalization and other minor menu titles stuff

  • Property svn:eol-style set to native
File size: 3.1 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.corrector.ReverseWayTagCorrector;
19import org.openstreetmap.josm.corrector.UserCancelException;
20import org.openstreetmap.josm.data.osm.DataSet;
21import org.openstreetmap.josm.data.osm.Relation;
22import org.openstreetmap.josm.data.osm.Node;
23import org.openstreetmap.josm.data.osm.OsmPrimitive;
24import org.openstreetmap.josm.data.osm.Way;
25import org.openstreetmap.josm.data.osm.visitor.Visitor;
26import org.openstreetmap.josm.tools.Shortcut;
27
28public final class ReverseWayAction extends JosmAction {
29
30 public ReverseWayAction() {
31 super(tr("Reverse Ways"), "wayflip", tr("Reverse the direction of all selected ways."),
32 Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true);
33 }
34
35 public void actionPerformed(ActionEvent e) {
36 final Collection<Way> sel = new LinkedList<Way>();
37 new Visitor() {
38 public void visit(Node n) {
39 }
40
41 public void visit(Way w) {
42 sel.add(w);
43 }
44
45 public void visit(Relation e) {
46 }
47
48 public void visitAll() {
49 for (OsmPrimitive osm : Main.ds.getSelected())
50 osm.visit(this);
51 }
52 }.visitAll();
53
54 if (sel.isEmpty()) {
55 JOptionPane.showMessageDialog(Main.parent,
56 tr("Please select at least one way."));
57 return;
58 }
59
60 boolean propertiesUpdated = false;
61 ReverseWayTagCorrector reverseWayTagCorrector = new ReverseWayTagCorrector();
62 Collection<Command> c = new LinkedList<Command>();
63 for (Way w : sel) {
64 Way wnew = new Way(w);
65 Collections.reverse(wnew.nodes);
66 if (Main.pref.getBoolean("tag-correction.reverse-way", true)) {
67 try
68 {
69 final Collection<Command> changePropertyCommands = reverseWayTagCorrector.execute(wnew);
70 propertiesUpdated = propertiesUpdated
71 || (changePropertyCommands != null && !changePropertyCommands.isEmpty());
72 c.addAll(changePropertyCommands);
73 }
74 catch(UserCancelException ex)
75 {
76 return;
77 }
78 }
79 c.add(new ChangeCommand(w, wnew));
80 }
81 Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
82 if (propertiesUpdated)
83 DataSet.fireSelectionChanged(Main.ds.getSelected());
84 Main.map.repaint();
85 }
86}
Note: See TracBrowser for help on using the repository browser.