- Timestamp:
- 2007-10-11T22:25:35+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r361 r365 9 9 import java.awt.event.KeyEvent; 10 10 import java.awt.event.MouseEvent; 11 import java.awt.event.ActionEvent; 11 12 import java.util.Collection; 12 13 import java.util.LinkedList; … … 38 39 */ 39 40 public 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 54 45 /** 55 46 * The old cursor before the user pressed the mouse button. … … 61 52 private Point mousePos; 62 53 private SelectionManager selectionManager; 63 private boolean selectionMode = false;64 54 65 55 /** … … 67 57 * @param mapFrame The MapFrame, this action belongs to. 68 58 */ 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"); 73 64 selectionManager = new SelectionManager(this, false, mapFrame.mapView); 74 65 } 75 66 76 private static Cursor getCursor( ) {67 private static Cursor getCursor(String name, String mod, int def) { 77 68 try { 78 return ImageProvider.getCursor( "crosshair", null);69 return ImageProvider.getCursor(name, mod); 79 70 } catch (Exception e) { 80 71 } 81 return Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR);72 return Cursor.getPredefinedCursor(def); 82 73 } 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 } 83 92 84 93 @Override public void enterMode() { … … 100 109 */ 101 110 @Override public void mouseDragged(MouseEvent e) { 111 if (mode == Mode.select) return; 112 102 113 if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) 103 114 return; 104 115 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) { 109 121 mousePos = e.getPoint(); 122 } 110 123 111 124 EastNorth mouseEN = Main.map.mapView.getEastNorth(e.getX(), e.getY()); … … 127 140 for (OsmPrimitive osm : affectedNodes) { 128 141 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.")); 130 144 return; 131 145 } 132 146 } 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; 134 149 135 150 if (mode == Mode.move) { … … 161 176 if (e.getButton() != MouseEvent.BUTTON1) 162 177 return; 178 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 163 179 164 180 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 165 181 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; 169 193 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;178 194 selectionManager.register(Main.map.mapView); 179 195 selectionManager.mousePressed(e); … … 189 205 */ 190 206 @Override public void mouseReleased(MouseEvent e) { 191 if ( selectionMode) {207 if (mode == Mode.select) { 192 208 selectionManager.unregister(Main.map.mapView); 193 selectionMode = false;194 } else195 Main.map.mapView.setCursor(oldCursor);209 } 210 restoreCursor(); 211 mode = null; 196 212 } 197 213 198 214 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) {205 215 if (shift && ctrl) 206 216 return; // not allowed together -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r358 r365 18 18 import org.openstreetmap.josm.actions.mapmode.MapMode; 19 19 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 20 import org.openstreetmap.josm.actions.mapmode.SelectAction .SelectGroup;20 import org.openstreetmap.josm.actions.mapmode.SelectAction; 21 21 import org.openstreetmap.josm.gui.dialogs.CommandStackDialog; 22 22 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; … … 78 78 toolBarActions.setFloatable(false); 79 79 toolBarActions.add(new IconToggleButton(new ZoomAction(this))); 80 toolBarActions.add(new IconToggleButton(new Select Group(this)));80 toolBarActions.add(new IconToggleButton(new SelectAction(this))); 81 81 toolBarActions.add(new IconToggleButton(new DrawAction(this))); 82 82 toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
Note:
See TracChangeset
for help on using the changeset viewer.