Changeset 311 in josm for src/org/openstreetmap/josm


Ignore:
Timestamp:
2007-08-22T22:55:36+02:00 (18 years ago)
Author:
framm
Message:
  • added rotate mode that rotates selected nodes around centre point
Location:
src/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r301 r311  
    1414
    1515import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.actions.GroupAction;
     17import org.openstreetmap.josm.actions.mapmode.AddNodeAction.Mode;
    1618import org.openstreetmap.josm.command.Command;
    1719import org.openstreetmap.josm.command.MoveCommand;
     20import org.openstreetmap.josm.command.RotateCommand;
    1821import org.openstreetmap.josm.data.coor.EastNorth;
    1922import org.openstreetmap.josm.data.osm.Node;
     
    3538 */
    3639public class MoveAction extends MapMode implements SelectionEnded {
     40       
     41        enum Mode {move, rotate}
     42        private final Mode mode;
     43
     44        public static class MoveGroup extends GroupAction {
     45                public MoveGroup(MapFrame mf) {
     46                        super(KeyEvent.VK_M,0);
     47                        putValue("help", "Action/Move");
     48                        actions.add(new MoveAction(mf, tr("Move"), Mode.move, tr("Move around objects that are under the mouse or selected.")));
     49                        actions.add(new MoveAction(mf, tr("Rotate"), Mode.rotate, tr("Rotate selected nodes around centre")));
     50                        setCurrent(0);
     51                }
     52        }
     53       
    3754        /**
    3855         * The old cursor before the user pressed the mouse button.
     
    5067         * @param mapFrame The MapFrame, this action belongs to.
    5168         */
    52         public MoveAction(MapFrame mapFrame) {
    53                 super(tr("Move"),
    54                                 "move",
    55                                 tr("Move around objects that are under the mouse or selected."),
    56                                 KeyEvent.VK_M,
    57                                 mapFrame,
    58                                 ImageProvider.getCursor("normal", "move"));
     69        public MoveAction(MapFrame mapFrame, String name, Mode mode, String desc) {
     70                super(name, "move/"+mode, desc, mapFrame, getCursor());
     71                this.mode = mode;
     72                putValue("help", "Action/Move/"+Character.toUpperCase(mode.toString().charAt(0))+mode.toString().substring(1));
    5973                selectionManager = new SelectionManager(this, false, mapFrame.mapView);
    6074        }
    6175
     76        private static Cursor getCursor() {
     77                try {
     78                return ImageProvider.getCursor("crosshair", null);
     79        } catch (Exception e) {
     80        }
     81            return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
     82    }
     83       
    6284        @Override public void enterMode() {
    6385                super.enterMode();
     
    7294        }
    7395
    74 
    7596        /**
    7697         * If the left mouse button is pressed, move all currently selected
     
    87108                if (mousePos == null)
    88109                        mousePos = e.getPoint();
    89 
     110               
    90111                EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY());
    91112                EastNorth mouseStartEN = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
     
    97118                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    98119                Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
     120               
     121                // when rotating, having only one node makes no sense - quit silently
     122                if (affectedNodes.size() < 2 && mode == Mode.move)
     123                        return;
     124               
    99125
    100126                // check if any coordinate would be outside the world
     
    105131                        }
    106132                }
    107 
    108133                Command c = !Main.main.undoRedo.commands.isEmpty() ? Main.main.undoRedo.commands.getLast() : null;
    109                 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects))
    110                         ((MoveCommand)c).moveAgain(dx,dy);
    111                 else
    112                         Main.main.undoRedo.add(new MoveCommand(selection, dx, dy));
     134
     135                if (mode == Mode.move) {
     136                        if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects))
     137                                ((MoveCommand)c).moveAgain(dx,dy);
     138                        else
     139                                Main.main.undoRedo.add(new MoveCommand(selection, dx, dy));
     140                } else if (mode == Mode.rotate) {
     141                        if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand)c).objects))
     142                                ((RotateCommand)c).rotateAgain(mouseStartEN, mouseEN);
     143                        else
     144                                Main.main.undoRedo.add(new RotateCommand(selection, mouseStartEN, mouseEN));
     145                }
    113146
    114147                Main.map.mapView.repaint();
     
    135168                                Main.ds.setSelected(osm);
    136169                        oldCursor = Main.map.mapView.getCursor();
    137                         Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     170                       
     171                        if (mode == Mode.move) {
     172                                Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     173                        } else {
     174                                Main.map.mapView.setCursor(ImageProvider.getCursor("rotate", null));
     175                        }
    138176                } else {
    139177                        selectionMode = true;
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r298 r311  
    2222import org.openstreetmap.josm.actions.mapmode.ZoomAction;
    2323import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup;
     24import org.openstreetmap.josm.actions.mapmode.MoveAction.MoveGroup;
    2425import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
    2526import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     
    8283                final Action selectionAction = new SelectionAction.Group(this);
    8384                toolBarActions.add(new IconToggleButton(selectionAction));
    84                 toolBarActions.add(new IconToggleButton(new MoveAction(this)));
     85                toolBarActions.add(new IconToggleButton(new MoveGroup(this)));
    8586                toolBarActions.add(new IconToggleButton(new AddNodeGroup(this)));
    8687                toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
Note: See TracChangeset for help on using the changeset viewer.