Changeset 3919 in josm for trunk/src/org
- Timestamp:
- 2011-02-20T15:08:35+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r3847 r3919 116 116 if (layer.isVisible()) { 117 117 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 118 Main.map.mapView.setCursor 119 (Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 118 Main.map.mapView.setNewCursor(Cursor.MOVE_CURSOR, this); 120 119 } 121 120 } … … 137 136 @Override public void mouseReleased(MouseEvent e) { 138 137 Main.map.mapView.repaint(); 139 Main.map.mapView. setCursor(Cursor.getDefaultCursor());138 Main.map.mapView.resetCursor(this); 140 139 prevEastNorth = null; 141 140 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r3835 r3919 53 53 */ 54 54 public class DeleteAction extends MapMode implements AWTEventListener { 55 //private boolean drawTargetHighlight;56 private boolean drawTargetCursor;57 //private Collection<? extends OsmPrimitive> oldPrims = null;58 59 55 // Cache previous mouse event (needed when only the modifier keys are 60 56 // pressed but the mouse isn't moved) … … 80 76 } 81 77 } 82 private DeleteMode currentMode = DeleteMode.none;83 78 84 79 private static class DeleteParameters { … … 105 100 if (!isEnabled()) 106 101 return; 107 //drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true);108 drawTargetCursor = Main.pref.getBoolean("draw.target-cursor", true);109 102 110 103 Main.map.mapView.addMouseListener(this); … … 116 109 System.out.println(ex); 117 110 } 118 119 currentMode = DeleteMode.none;120 111 } 121 112 … … 189 180 return; 190 181 191 // Clean old highlights192 //cleanOldHighlights();193 194 182 DeleteParameters parameters = getDeleteParameters(e, modifiers); 195 setCursor(parameters.mode); 196 197 // Needs to implement WaySegment highlight first 198 /*if(drawTargetHighlight) { 199 // Add new highlights 200 for(OsmPrimitive p : prims) { 201 p.highlighted = true; 202 } 203 oldPrims = prims; 204 }*/ 205 206 // We only need to repaint if the highlights changed 207 //Main.map.mapView.repaint(); 208 } 209 210 /** 211 * Small helper function that cleans old highlights 212 */ 213 /*private void cleanOldHighlights() { 214 if(oldPrims == null) 215 return; 216 for(OsmPrimitive p: oldPrims) { 217 p.highlighted = false; 218 } 219 }*/ 183 Main.map.mapView.setNewCursor(parameters.mode.cursor(), this); 184 } 220 185 221 186 /** … … 338 303 339 304 /** 340 * This function sets the given cursor in a safe way. This implementation341 * differs from the on in DrawAction (it is favorable, too).342 * FIXME: Update DrawAction to use this "setCursor-style" and move function343 * to MapMode.344 * @param c345 */346 private void setCursor(final DeleteMode c) {347 if(currentMode.equals(c) || (!drawTargetCursor && currentMode.equals(DeleteMode.none)))348 return;349 // We invoke this to prevent strange things from happening350 EventQueue.invokeLater(new Runnable() {351 public void run() {352 // Don't change cursor when mode has changed already353 if(!(Main.map.mapMode instanceof DeleteAction))354 return;355 356 Main.map.mapView.setCursor(c.cursor());357 //System.out.println("Set cursor to: " + c.name());358 }359 });360 currentMode = c;361 }362 363 /**364 305 * This is required to update the cursors when ctrl/shift/alt is pressed 365 306 */ -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r3837 r3919 62 62 //static private final Logger logger = Logger.getLogger(DrawAction.class.getName()); 63 63 64 final private Cursor cursorCrosshair;65 64 final private Cursor cursorJoinNode; 66 65 final private Cursor cursorJoinWay; 67 enum Cursors { crosshair, node, way }68 private Cursors currCursor = Cursors.crosshair;69 66 70 67 private Node lastUsedNode = null; … … 80 77 private boolean wayIsFinished = false; 81 78 private boolean drawTargetHighlight; 82 private boolean drawTargetCursor;83 79 private Point mousePos; 84 80 private Point oldMousePos; … … 93 89 super(tr("Draw"), "node/autonode", tr("Draw nodes"), 94 90 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.GROUP_EDIT), 95 mapFrame, getCursor());91 mapFrame, ImageProvider.getCursor("crosshair", null)); 96 92 97 93 // Add extra shortcut N … … 99 95 Main.registerActionShortcut(this, extraShortcut); 100 96 101 cursorCrosshair = getCursor();102 97 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 103 98 cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway"); 104 }105 106 private static Cursor getCursor() {107 try {108 return ImageProvider.getCursor("crosshair", null);109 } catch (Exception e) {110 }111 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);112 }113 114 /**115 * Displays the given cursor instead of the normal one116 * @param Cursors One of the available cursors117 */118 private void setCursor(final Cursors c) {119 if(currCursor.equals(c) || (!drawTargetCursor && currCursor.equals(Cursors.crosshair)))120 return;121 // We invoke this to prevent strange things from happening122 EventQueue.invokeLater(new Runnable() {123 public void run() {124 // Don't change cursor when mode has changed already125 if(!(Main.map.mapMode instanceof DrawAction))126 return;127 switch(c) {128 case way:129 Main.map.mapView.setCursor(cursorJoinWay);130 break;131 case node:132 Main.map.mapView.setCursor(cursorJoinNode);133 break;134 default:135 Main.map.mapView.setCursor(cursorCrosshair);136 break;137 }138 }139 });140 currCursor = c;141 99 } 142 100 … … 158 116 // if ctrl key is held ("no join"), don't highlight anything 159 117 if (ctrl) { 160 setCursor(Cursors.crosshair);118 Main.map.mapView.setNewCursor(cursor, this); 161 119 return; 162 120 } … … 169 127 170 128 if (mouseOnExistingNode != null) { 171 setCursor(Cursors.node);129 Main.map.mapView.setNewCursor(cursorJoinNode, this); 172 130 // We also need this list for the statusbar help text 173 131 oldHighlights.add(mouseOnExistingNode); … … 180 138 // Insert the node into all the nearby way segments 181 139 if (mouseOnExistingWays.size() == 0) { 182 setCursor(Cursors.crosshair);183 return; 184 } 185 186 setCursor(Cursors.way);140 Main.map.mapView.setNewCursor(cursor, this); 141 return; 142 } 143 144 Main.map.mapView.setNewCursor(cursorJoinWay, this); 187 145 188 146 // We also need this list for the statusbar help text … … 208 166 return; 209 167 super.enterMode(); 210 currCursor = Cursors.crosshair;211 168 selectedColor =PaintColors.SELECTED.get(); 212 169 drawHelperLine = Main.pref.getBoolean("draw.helper-line", true); 213 170 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true); 214 drawTargetCursor = Main.pref.getBoolean("draw.target-cursor", true);215 171 wayIsFinished = false; 216 172 -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r3762 r3919 74 74 75 75 /** 76 * The old cursor before the user pressed the mouse button.77 */78 private Cursor oldCursor;79 /**80 76 * The position of the mouse cursor when the drag action was initiated. 81 77 */ … … 110 106 Shortcut.registerShortcut("mapmode:extrude", tr("Mode: {0}", tr("Extrude")), KeyEvent.VK_X, Shortcut.GROUP_EDIT), 111 107 mapFrame, 112 getCursor("normal", "rectangle", Cursor.DEFAULT_CURSOR));108 ImageProvider.getCursor("normal", "rectangle")); 113 109 putValue("help", ht("/Action/Extrude")); 114 110 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200); … … 263 259 updateStatusLine(); 264 260 265 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));261 Main.map.mapView.setNewCursor(Cursor.MOVE_CURSOR, this); 266 262 267 263 if (mode == Mode.extrude) { … … 354 350 355 351 // Switch back into select mode 356 restoreCursor();352 Main.map.mapView.setNewCursor(cursor, this); 357 353 Main.map.mapView.removeTemporaryLayer(this); 358 354 selectedSegment = null; … … 528 524 } 529 525 } 530 531 private static Cursor getCursor(String name, String mod, int def) {532 try {533 return ImageProvider.getCursor(name, mod);534 } catch (Exception e) {535 }536 return Cursor.getPredefinedCursor(def);537 }538 539 private void setCursor(Cursor c) {540 if (oldCursor == null) {541 oldCursor = Main.map.mapView.getCursor();542 Main.map.mapView.setCursor(c);543 }544 }545 546 private void restoreCursor() {547 if (oldCursor != null) {548 Main.map.mapView.setCursor(oldCursor);549 oldCursor = null;550 }551 }552 526 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r2017 r3919 24 24 */ 25 25 abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener { 26 private final Cursor cursor; 27 private Cursor oldCursor; 26 protected final Cursor cursor; 28 27 29 28 /** … … 48 47 public void enterMode() { 49 48 putValue("active", true); 50 oldCursor = Main.map.mapView.getCursor(); 51 Main.map.mapView.setCursor(cursor); 49 Main.map.mapView.setNewCursor(cursor, this); 52 50 updateStatusLine(); 53 51 } 54 52 public void exitMode() { 55 53 putValue("active", false); 56 Main.map.mapView. setCursor(oldCursor);54 Main.map.mapView.resetCursor(this); 57 55 } 58 56 -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r3754 r3919 76 76 * The old cursor before the user pressed the mouse button. 77 77 */ 78 private Cursor oldCursor;79 /**80 * The position of the mouse before the user starts to drag it while pressing a button.81 */82 78 private Point startingDraggingPos; 83 79 /** … … 109 105 Shortcut.registerShortcut("mapmode:select", tr("Mode: {0}", tr("Select")), KeyEvent.VK_S, Shortcut.GROUP_EDIT), 110 106 mapFrame, 111 getCursor("normal", "selection", Cursor.DEFAULT_CURSOR));107 ImageProvider.getCursor("normal", "selection")); 112 108 mv = mapFrame.mapView; 113 109 putValue("help", ht("/Action/Move/Move")); … … 115 111 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay", 200); 116 112 initialMoveThreshold = Main.pref.getInteger("edit.initial-move-threshold", 5); 117 }118 119 private static Cursor getCursor(String name, String mod, int def) {120 try {121 return ImageProvider.getCursor(name, mod);122 } catch (Exception e) {123 }124 return Cursor.getPredefinedCursor(def);125 }126 127 private void setCursor(Cursor c) {128 if (oldCursor == null) {129 oldCursor = mv.getCursor();130 mv.setCursor(c);131 }132 }133 134 private void restoreCursor() {135 if (oldCursor != null) {136 mv.setCursor(oldCursor);137 oldCursor = null;138 }139 113 } 140 114 … … 182 156 183 157 if (mode == Mode.move) { 184 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));158 mv.setNewCursor(Cursor.MOVE_CURSOR, this); 185 159 } 186 160 … … 257 231 tr("Warning"), 258 232 JOptionPane.WARNING_MESSAGE); 259 restoreCursor();233 mv.setNewCursor(cursor, this); 260 234 return; 261 235 } … … 457 431 // Mode.move redraws when mouseDragged is called 458 432 // Mode.rotate redraws here 459 setCursor(ImageProvider.getCursor("rotate", null));433 mv.setNewCursor(ImageProvider.getCursor("rotate", null), this); 460 434 mv.repaint(); 461 435 } else if (alt && ctrl) { … … 469 443 // Mode.move redraws when mouseDragged is called 470 444 // Mode.scale redraws here 471 setCursor(ImageProvider.getCursor("scale", null));445 mv.setNewCursor(ImageProvider.getCursor("scale", null), this); 472 446 mv.repaint(); 473 447 } else if (!c.isEmpty()) { … … 482 456 mode = Mode.select; 483 457 484 oldCursor = mv.getCursor();485 458 selectionManager.register(mv); 486 459 selectionManager.mousePressed(e); … … 500 473 startingDraggingPos = null; 501 474 502 restoreCursor();475 mv.setNewCursor(cursor, this); 503 476 if (mode == Mode.select) { 504 477 selectionManager.unregister(mv); -
trunk/src/org/openstreetmap/josm/gui/MapMover.java
r1939 r3919 67 67 */ 68 68 private final NavigatableComponent nc; 69 /**70 * The old cursor when we changed it to movement cursor.71 */72 private Cursor oldCursor;73 69 74 70 private boolean movementInPlace = false; … … 167 163 movementInPlace = true; 168 164 mousePosMove = nc.getEastNorth(e.getX(), e.getY()); 169 oldCursor = nc.getCursor(); 170 nc.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 165 nc.setNewCursor(Cursor.MOVE_CURSOR, this); 171 166 } 172 167 … … 178 173 return; 179 174 movementInPlace = false; 180 if (oldCursor != null) 181 nc.setCursor(oldCursor); 182 else 183 nc.setCursor(Cursor.getDefaultCursor()); 175 nc.resetCursor(this); 184 176 mousePosMove = null; 185 oldCursor = null;186 177 } 187 178 -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r3838 r3919 4 4 import static org.openstreetmap.josm.tools.I18n.marktr; 5 5 6 import java.awt.Cursor; 6 7 import java.awt.Point; 7 8 import java.awt.Rectangle; … … 1213 1214 SYSTEMS_OF_MEASUREMENT.put(marktr("Imperial"), IMPERIAL_SOM); 1214 1215 } 1216 1217 private class CursorInfo { 1218 public Cursor cursor; 1219 public Object object; 1220 public CursorInfo(Cursor c, Object o) { 1221 cursor = c; 1222 object = o; 1223 } 1224 } 1225 1226 private LinkedList<CursorInfo> Cursors = new LinkedList<CursorInfo>(); 1227 /** 1228 * Set new cursor. 1229 */ 1230 public void setNewCursor(Cursor cursor, Object reference) { 1231 if(Cursors.size() > 0) { 1232 CursorInfo l = Cursors.getLast(); 1233 if(l != null && l.cursor == cursor && l.object == reference) { 1234 return; 1235 } 1236 stripCursors(reference); 1237 } 1238 Cursors.add(new CursorInfo(cursor, reference)); 1239 setCursor(cursor); 1240 } 1241 public void setNewCursor(int cursor, Object reference) { 1242 setNewCursor(Cursor.getPredefinedCursor(cursor), reference); 1243 } 1244 /** 1245 * Remove the new cursor and reset to previous 1246 */ 1247 public void resetCursor(Object reference) { 1248 if(Cursors.size() == 0) { 1249 setCursor(null); 1250 return; 1251 } 1252 CursorInfo l = Cursors.getLast(); 1253 stripCursors(reference); 1254 if(l != null && l.object == reference) { 1255 if(Cursors.size() == 0) 1256 setCursor(null); 1257 else 1258 setCursor(Cursors.getLast().cursor); 1259 } 1260 } 1261 1262 private void stripCursors(Object reference) { 1263 LinkedList<CursorInfo> c = new LinkedList<CursorInfo>(); 1264 for(CursorInfo i : Cursors) { 1265 if(i.object != reference) 1266 c.add(i); 1267 } 1268 Cursors = c; 1269 } 1215 1270 }
Note:
See TracChangeset
for help on using the changeset viewer.