source: josm/trunk/src/org/openstreetmap/josm/actions/MirrorAction.java@ 1724

Last change on this file since 1724 was 1722, checked in by stoecker, 15 years ago

Large rework in projection handling - now allows only switching and more specific projections
TODO:

  • allow subprojections (i.e. settings for projections)
  • setup preferences for subprojections
  • better support of the new projection depending world bounds (how to handle valid data outside of world)
  • do not allow to zoom out of the world - zoom should stop when whole world is displayed
  • fix Lambert and SwissGrid to handle new OutOfWorld style and subprojections
  • fix new UTM projection
  • handle layers with fixed projection on projection change
  • allow easier projection switching (e.g. in menu)

NOTE:
This checkin very likely will cause problems. Please report or fix them. Older plugins may have trouble. The SVN plugins
have been fixed but may have problems nevertheless. This is a BIG change, but will make JOSMs internal structure much cleaner
and reduce lots of projection related problems.

File size: 2.5 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.HashSet;
10import java.util.LinkedList;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.command.Command;
16import org.openstreetmap.josm.command.ChangeCommand;
17import org.openstreetmap.josm.command.MoveCommand;
18import org.openstreetmap.josm.command.SequenceCommand;
19import org.openstreetmap.josm.data.coor.EastNorth;
20import org.openstreetmap.josm.data.osm.Node;
21import org.openstreetmap.josm.data.osm.OsmPrimitive;
22import org.openstreetmap.josm.data.osm.Way;
23import org.openstreetmap.josm.tools.Shortcut;
24
25/**
26 * Mirror the selected nodes or ways along the vertical axis
27 *
28 * Note: If a ways are selected, their nodes are mirrored
29 *
30 * @author Teemu Koskinen, based on much copy&Paste from other Actions.
31 */
32public final class MirrorAction extends JosmAction {
33
34 public MirrorAction() {
35 super(tr("Mirror"), "mirror", tr("Mirror selected nodes and ways."),
36 Shortcut.registerShortcut("tools:mirror", tr("Tool: {0}", tr("Mirror")),
37 KeyEvent.VK_M, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
38 }
39
40 public void actionPerformed(ActionEvent e) {
41 Collection<OsmPrimitive> sel = Main.ds.getSelected();
42 HashSet<Node> nodes = new HashSet<Node>();
43
44 for (OsmPrimitive osm : sel) {
45 if (osm instanceof Node) {
46 nodes.add((Node)osm);
47 } else if (osm instanceof Way) {
48 nodes.addAll(((Way)osm).nodes);
49 }
50 }
51
52 if (nodes.size() == 0) {
53 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one node or way."));
54 return;
55 }
56
57 double minEast = 20000000000.0;
58 double maxEast = -20000000000.0;
59 for (Node n : nodes) {
60 double east = n.getEastNorth().east();
61 minEast = Math.min(minEast, east);
62 maxEast = Math.max(maxEast, east);
63 }
64 double middle = (minEast + maxEast) / 2;
65
66 Collection<Command> cmds = new LinkedList<Command>();
67
68 for (Node n : nodes)
69 cmds.add(new MoveCommand(n, 2 * (middle - n.getEastNorth().east()), 0.0));
70
71 Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds));
72 Main.map.repaint();
73 }
74}
Note: See TracBrowser for help on using the repository browser.