source: josm/src/org/openstreetmap/josm/actions/ReverseSegmentAction.java@ 128

Last change on this file since 128 was 128, checked in by imi, 18 years ago
  • added icons to annotation preset selection box
  • added history dialog (not finished)
File size: 1.7 KB
Line 
1/**
2 *
3 */
4package org.openstreetmap.josm.actions;
5
6import static org.openstreetmap.josm.tools.I18n.tr;
7
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.util.Collection;
11import java.util.LinkedList;
12
13import javax.swing.JOptionPane;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.command.ChangeCommand;
17import org.openstreetmap.josm.command.Command;
18import org.openstreetmap.josm.command.SequenceCommand;
19import org.openstreetmap.josm.data.osm.Node;
20import org.openstreetmap.josm.data.osm.OsmPrimitive;
21import org.openstreetmap.josm.data.osm.Segment;
22
23public 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}
Note: See TracBrowser for help on using the repository browser.