Changeset 365 in josm for trunk/src/org


Ignore:
Timestamp:
2007-10-11T22:25:35+02:00 (17 years ago)
Author:
gebner
Message:

Make the select mapmode modeless and fix the rotation cursor.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r361 r365  
    99import java.awt.event.KeyEvent;
    1010import java.awt.event.MouseEvent;
     11import java.awt.event.ActionEvent;
    1112import java.util.Collection;
    1213import java.util.LinkedList;
     
    3839 */
    3940public class SelectAction extends MapMode implements SelectionEnded {
    40        
    41         enum Mode {move, rotate}
    42         private final Mode mode;
    43 
    44         public static class SelectGroup extends GroupAction {
    45                 public SelectGroup(MapFrame mf) {
    46                         super(KeyEvent.VK_S,0);
    47                         putValue("help", "Action/Move");
    48                         actions.add(new SelectAction(mf, tr("Select/Move"), Mode.move, tr("Select and move around objects that are under the mouse or selected.")));
    49                         actions.add(new SelectAction(mf, tr("Rotate"), Mode.rotate, tr("Rotate selected nodes around centre")));
    50                         setCurrent(0);
    51                 }
    52         }
    53        
     41
     42        enum Mode { move, rotate, select }
     43        private Mode mode = null;
     44
    5445        /**
    5546         * The old cursor before the user pressed the mouse button.
     
    6152        private Point mousePos;
    6253        private SelectionManager selectionManager;
    63         private boolean selectionMode = false;
    6454
    6555        /**
     
    6757         * @param mapFrame The MapFrame, this action belongs to.
    6858         */
    69         public SelectAction(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));
     59        public SelectAction(MapFrame mapFrame) {
     60                super(tr("Select"), "move/move", tr("Select, move and rotate objects"),
     61                        KeyEvent.VK_S, mapFrame,
     62                        getCursor("normal", "selection", Cursor.DEFAULT_CURSOR));
     63                putValue("help", "Action/Move/Move");
    7364                selectionManager = new SelectionManager(this, false, mapFrame.mapView);
    7465        }
    7566
    76         private static Cursor getCursor() {
     67        private static Cursor getCursor(String name, String mod, int def) {
    7768                try {
    78                 return ImageProvider.getCursor("crosshair", null);
     69                return ImageProvider.getCursor(name, mod);
    7970        } catch (Exception e) {
    8071        }
    81             return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
     72            return Cursor.getPredefinedCursor(def);
    8273    }
     74
     75        private static Cursor getCursor(String name, int def) {
     76                return getCursor(name, null, def);
     77        }
     78
     79        private void setCursor(Cursor c) {
     80                if (oldCursor == null) {
     81                        oldCursor = Main.map.mapView.getCursor();
     82                        Main.map.mapView.setCursor(c);
     83                }
     84        }
     85
     86        private void restoreCursor() {
     87                if (oldCursor != null) {
     88                        Main.map.mapView.setCursor(oldCursor);
     89                        oldCursor = null;
     90                }
     91        }
    8392       
    8493        @Override public void enterMode() {
     
    100109         */
    101110        @Override public void mouseDragged(MouseEvent e) {
     111                if (mode == Mode.select) return;
     112
    102113                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0)
    103114                        return;
    104115
    105                 if (selectionMode)
    106                         return;
    107 
    108                 if (mousePos == null)
     116                if (mode == Mode.move) {
     117                        setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     118                }
     119
     120                if (mousePos == null) {
    109121                        mousePos = e.getPoint();
     122                }
    110123               
    111124                EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY());
     
    127140                for (OsmPrimitive osm : affectedNodes) {
    128141                        if (osm instanceof Node && ((Node)osm).coor.isOutSideWorld()) {
    129                                 JOptionPane.showMessageDialog(Main.parent,tr("Cannot move objects outside of the world."));
     142                                JOptionPane.showMessageDialog(Main.parent,
     143                                        tr("Cannot move objects outside of the world."));
    130144                                return;
    131145                        }
    132146                }
    133                 Command c = !Main.main.undoRedo.commands.isEmpty() ? Main.main.undoRedo.commands.getLast() : null;
     147                Command c = !Main.main.undoRedo.commands.isEmpty()
     148                        ? Main.main.undoRedo.commands.getLast() : null;
    134149
    135150                if (mode == Mode.move) {
     
    161176                if (e.getButton() != MouseEvent.BUTTON1)
    162177                        return;
     178                boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    163179
    164180                Collection<OsmPrimitive> sel = Main.ds.getSelected();
    165181                OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint());
    166                 if (osm != null) {
    167                         if (!sel.contains(osm))
    168                                 Main.ds.setSelected(osm);
     182                if (ctrl) {
     183                        if (osm != null && !sel.contains(osm)) Main.ds.setSelected(osm);
     184
     185                        mode = Mode.rotate;
     186                        setCursor(ImageProvider.getCursor("rotate", null));
     187                } else if (osm != null) {
     188                        if (!sel.contains(osm)) Main.ds.setSelected(osm);
     189
     190                        mode = Mode.move;
     191                } else {
     192                        mode = Mode.select;
    169193                        oldCursor = Main.map.mapView.getCursor();
    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                         }
    176                 } else {
    177                         selectionMode = true;
    178194                        selectionManager.register(Main.map.mapView);
    179195                        selectionManager.mousePressed(e);
     
    189205         */
    190206        @Override public void mouseReleased(MouseEvent e) {
    191                 if (selectionMode) {
     207                if (mode == Mode.select) {
    192208                        selectionManager.unregister(Main.map.mapView);
    193                         selectionMode = false;
    194                 } else
    195                         Main.map.mapView.setCursor(oldCursor);
     209                }
     210                restoreCursor();
     211                mode = null;
    196212        }
    197213
    198214        public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
    199                 selectEverythingInRectangle(selectionManager, r, alt, shift, ctrl);
    200         }
    201 
    202         public static void selectEverythingInRectangle(
    203                         SelectionManager selectionManager, Rectangle r,
    204                         boolean alt, boolean shift, boolean ctrl) {
    205215            if (shift && ctrl)
    206216                        return; // not allowed together
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r358 r365  
    1818import org.openstreetmap.josm.actions.mapmode.MapMode;
    1919import org.openstreetmap.josm.actions.mapmode.ZoomAction;
    20 import org.openstreetmap.josm.actions.mapmode.SelectAction.SelectGroup;
     20import org.openstreetmap.josm.actions.mapmode.SelectAction;
    2121import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
    2222import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     
    7878                toolBarActions.setFloatable(false);
    7979                toolBarActions.add(new IconToggleButton(new ZoomAction(this)));
    80                 toolBarActions.add(new IconToggleButton(new SelectGroup(this)));
     80                toolBarActions.add(new IconToggleButton(new SelectAction(this)));
    8181                toolBarActions.add(new IconToggleButton(new DrawAction(this)));
    8282                toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
Note: See TracChangeset for help on using the changeset viewer.