- Timestamp:
- 2006-10-07T00:14:05+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r113 r151 5 5 import java.awt.Cursor; 6 6 import java.awt.Point; 7 import java.awt.Rectangle; 7 8 import java.awt.event.KeyEvent; 8 9 import java.awt.event.MouseEvent; … … 19 20 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 20 21 import org.openstreetmap.josm.gui.MapFrame; 22 import org.openstreetmap.josm.gui.SelectionManager; 23 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 21 24 import org.openstreetmap.josm.tools.ImageProvider; 22 25 /** 23 26 * 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) 28 32 * 29 33 * @author imi 30 34 */ 31 public class MoveAction extends MapMode { 35 public class MoveAction extends MapMode implements SelectionEnded { 32 36 /** 33 37 * The old cursor before the user pressed the mouse button. … … 38 42 */ 39 43 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; 45 46 46 47 /** … … 50 51 public MoveAction(MapFrame mapFrame) { 51 52 super(tr("Move"), 52 "move", 53 tr("Move selected objectsaround."),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, 56 57 ImageProvider.getCursor("normal", "move")); 58 selectionManager = new SelectionManager(this, false, mapFrame.mapView); 57 59 } 58 60 … … 69 71 } 70 72 71 73 72 74 /** 73 75 * 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). 75 78 */ 76 79 @Override public void mouseDragged(MouseEvent e) { 77 80 if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) 78 81 return; 82 83 if (selectionMode) 84 return; 79 85 80 if (mousePos == null) {86 if (mousePos == null) 81 87 mousePos = e.getPoint(); 82 singleOsmPrimitive = null;83 }84 88 85 EastNorth mouse Geo= Main.map.mapView.getEastNorth(e.getX(), e.getY());86 EastNorth mouseStart Geo= Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);87 double dx = mouse Geo.east() - mouseStartGeo.east();88 double dy = mouse Geo.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(); 89 93 if (dx == 0 && dy == 0) 90 94 return; … … 92 96 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 93 97 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 94 98 95 99 // check if any coordinate would be outside the world 96 100 for (OsmPrimitive osm : affectedNodes) { … … 100 104 } 101 105 } 102 106 103 107 Command c = !Main.main.editLayer().commands.isEmpty() ? Main.main.editLayer().commands.getLast() : null; 104 108 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects)) … … 106 110 else 107 111 Main.main.editLayer().add(new MoveCommand(selection, dx, dy)); 108 112 109 113 Main.map.mapView.repaint(); 110 114 mousePos = e.getPoint(); … … 124 128 return; 125 129 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 135 144 mousePos = e.getPoint(); 136 oldCursor = Main.map.mapView.getCursor();137 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));138 145 } 139 146 140 147 /** 141 148 * Restore the old mouse cursor. 142 149 */ 143 150 @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); 149 156 } 157 158 159 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) { 160 SelectionAction.selectEverythingInRectangle(selectionManager, r, alt, shift, ctrl); 161 } 150 162 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r118 r151 138 138 */ 139 139 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) 141 145 return; // not allowed together 142 146 … … 155 159 Main.ds.setSelected(curSel); 156 160 Main.map.mapView.repaint(); 157 161 } 158 162 159 163 @Override public void mouseDragged(MouseEvent e) { -
src/org/openstreetmap/josm/plugins/PluginLoader.java
r149 r151 43 43 try { 44 44 ClassLoader loader = URLClassLoader.newInstance( 45 new URL[]{new URL("file:/"+pluginFile.getAbsolutePath())}, 45 new URL[]{new URL("file://"+pluginFile.getAbsolutePath())}, 46 46 getClass().getClassLoader()); 47 47 Object plugin = Class.forName(pluginClass, true, loader).newInstance();
Note:
See TracChangeset
for help on using the changeset viewer.