Changeset 151 in josm for src/org/openstreetmap


Ignore:
Timestamp:
2006-10-07T00:14:05+02:00 (18 years ago)
Author:
imi
Message:
  • changed move action to move the object under cursor, not the selected one
  • fixed plugins under linux/mac
Location:
src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r113 r151  
    55import java.awt.Cursor;
    66import java.awt.Point;
     7import java.awt.Rectangle;
    78import java.awt.event.KeyEvent;
    89import java.awt.event.MouseEvent;
     
    1920import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
    2021import org.openstreetmap.josm.gui.MapFrame;
     22import org.openstreetmap.josm.gui.SelectionManager;
     23import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
    2124import org.openstreetmap.josm.tools.ImageProvider;
    2225/**
    2326 * Move is an action that can move all kind of OsmPrimitives (except Keys for now).
    24  *
    25  * If any object is selected, all selected objects are moved. If no object is
    26  * selected, the nearest object will be selected and moved. In this case, the
    27  * object will be unselected as soon as movement stopped.
     27 *
     28 * If an selected object is under the mouse when dragging, move all selected objects.
     29 * If an unselected object is under the mouse when dragging, it becomes selected
     30 * and will be moved.
     31 * If no object is under the mouse, move all selected objects (if any)
    2832 *
    2933 * @author imi
    3034 */
    31 public class MoveAction extends MapMode {
     35public class MoveAction extends MapMode implements SelectionEnded {
    3236        /**
    3337         * The old cursor before the user pressed the mouse button.
     
    3842         */
    3943        private Point mousePos;
    40         /**
    41          * Non-<code>null</code>, if no object was selected before movement
    42          * (and so the object get unselected after mouse release).
    43          */
    44         private OsmPrimitive singleOsmPrimitive;
     44        private SelectionManager selectionManager;
     45        private boolean selectionMode = false;
    4546
    4647        /**
     
    5051        public MoveAction(MapFrame mapFrame) {
    5152                super(tr("Move"),
    52                                 "move", 
    53                                 tr("Move selected objects around."),
    54                                 KeyEvent.VK_M, 
    55                                 mapFrame, 
     53                                "move",
     54                                tr("Move around objects that are under the mouse or selected."),
     55                                KeyEvent.VK_M,
     56                                mapFrame,
    5657                                ImageProvider.getCursor("normal", "move"));
     58                selectionManager = new SelectionManager(this, false, mapFrame.mapView);
    5759        }
    5860
     
    6971        }
    7072
    71        
     73
    7274        /**
    7375         * If the left mouse button is pressed, move all currently selected
    74          * objects.
     76         * objects (if one of them is under the mouse) or the current one under the
     77         * mouse (which will become selected).
    7578         */
    7679        @Override public void mouseDragged(MouseEvent e) {
    7780                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0)
    7881                        return;
     82
     83                if (selectionMode)
     84                        return;
    7985               
    80                 if (mousePos == null) {
     86                if (mousePos == null)
    8187                        mousePos = e.getPoint();
    82                         singleOsmPrimitive = null;
    83                 }
    8488
    85                 EastNorth mouseGeo = Main.map.mapView.getEastNorth(e.getX(), e.getY());
    86                 EastNorth mouseStartGeo = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
    87                 double dx = mouseGeo.east() - mouseStartGeo.east();
    88                 double dy = mouseGeo.north() - mouseStartGeo.north();
     89                EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY());
     90                EastNorth mouseStartEN = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
     91                double dx = mouseEN.east() - mouseStartEN.east();
     92                double dy = mouseEN.north() - mouseStartEN.north();
    8993                if (dx == 0 && dy == 0)
    9094                        return;
     
    9296                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    9397                Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
    94                
     98
    9599                // check if any coordinate would be outside the world
    96100                for (OsmPrimitive osm : affectedNodes) {
     
    100104                        }
    101105                }
    102                
     106
    103107                Command c = !Main.main.editLayer().commands.isEmpty() ? Main.main.editLayer().commands.getLast() : null;
    104108                if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects))
     
    106110                else
    107111                        Main.main.editLayer().add(new MoveCommand(selection, dx, dy));
    108                
     112
    109113                Main.map.mapView.repaint();
    110114                mousePos = e.getPoint();
     
    124128                        return;
    125129
    126                 if (Main.ds.getSelected().size() == 0) {
    127                         OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
    128                         if (osm != null)
    129                                 Main.ds.setSelected(osm);
    130                         singleOsmPrimitive = osm;
    131                         Main.map.mapView.repaint();
    132                 } else
    133                         singleOsmPrimitive = null;
    134                
     130                Collection<OsmPrimitive> sel = Main.ds.getSelected();
     131                OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
     132                if (osm != null) {
     133                if (!sel.contains(osm))
     134                        Main.ds.setSelected(osm);
     135                oldCursor = Main.map.mapView.getCursor();
     136                Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     137        } else {
     138                selectionMode = true;
     139                        selectionManager.register(Main.map.mapView);
     140        }
     141
     142                Main.map.mapView.repaint();
     143
    135144                mousePos = e.getPoint();
    136                 oldCursor = Main.map.mapView.getCursor();
    137                 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    138145        }
    139        
     146
    140147        /**
    141148         * Restore the old mouse cursor.
    142149         */
    143150        @Override public void mouseReleased(MouseEvent e) {
    144                 Main.map.mapView.setCursor(oldCursor);
    145                 if (singleOsmPrimitive != null) {
    146                         Main.ds.clearSelection();
    147                         Main.map.mapView.repaint();
    148                 }
     151                if (selectionMode) {
     152                        selectionManager.unregister(Main.map.mapView);
     153                        selectionMode = false;
     154                } else
     155                        Main.map.mapView.setCursor(oldCursor);
    149156        }
     157
     158       
     159        public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
     160                SelectionAction.selectEverythingInRectangle(selectionManager, r, alt, shift, ctrl);
     161    }
    150162}
  • src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java

    r118 r151  
    138138         */
    139139        public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
    140                 if (shift && ctrl)
     140                selectEverythingInRectangle(selectionManager, r, alt, shift, ctrl);
     141        }
     142
     143        public static void selectEverythingInRectangle(SelectionManager selectionManager, Rectangle r, boolean alt, boolean shift, boolean ctrl) {
     144            if (shift && ctrl)
    141145                        return; // not allowed together
    142146
     
    155159                Main.ds.setSelected(curSel);
    156160                Main.map.mapView.repaint();
    157         }
     161    }
    158162
    159163        @Override public void mouseDragged(MouseEvent e) {
  • src/org/openstreetmap/josm/plugins/PluginLoader.java

    r149 r151  
    4343                try {
    4444                        ClassLoader loader = URLClassLoader.newInstance(
    45                                         new URL[]{new URL("file:/"+pluginFile.getAbsolutePath())},
     45                                        new URL[]{new URL("file://"+pluginFile.getAbsolutePath())},
    4646                                        getClass().getClassLoader());
    4747                        Object plugin = Class.forName(pluginClass, true, loader).newInstance();
Note: See TracChangeset for help on using the changeset viewer.