Ticket #2233: fix cursor bug.patch
File fix cursor bug.patch, 6.1 KB (added by , 16 years ago) |
---|
-
src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
8 8 import java.awt.BasicStroke; 9 9 import java.awt.Color; 10 10 import java.awt.Cursor; 11 import java.awt.EventQueue; 11 12 import java.awt.Graphics; 12 13 import java.awt.Graphics2D; 13 14 import java.awt.Point; … … 58 59 * 59 60 */ 60 61 public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, AWTEventListener { 61 62 final private Cursor cursorCrosshair; 63 final private Cursor cursorJoinNode; 64 final private Cursor cursorJoinWay; 65 enum Cursors { crosshair, node, way } 66 private Cursors currCursor = Cursors.crosshair; 67 62 68 private static Node lastUsedNode = null; 63 69 private double PHI=Math.toRadians(90); 64 70 … … 87 93 // Add extra shortcut N 88 94 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 89 95 Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT).getKeyStroke(), tr("Draw")); 96 97 cursorCrosshair = getCursor(); 98 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); 99 cursorJoinWay = ImageProvider.getCursor("crosshair", "joinway"); 90 100 } 91 101 92 102 private static Cursor getCursor() { … … 98 108 } 99 109 100 110 /** 101 * Sets a special cursor to indicate that the next click will automatically join into 102 * an existing node or way (if feature is enabled) 103 * 104 * @param way If true, the cursor will indicate it is joined into a way; node otherwise 111 * Displays the given cursor instead of the normal one 112 * @param Cursors One of the available cursors 105 113 */ 106 private void setJoinCursor(boolean way) { 107 if(!drawTargetCursor) { 108 resetCursor(); 114 private void setCursor(final Cursors c) { 115 if(currCursor.equals(c) || (!drawTargetCursor && currCursor.equals(Cursors.crosshair))) 109 116 return; 110 }111 117 try { 112 Main.map.mapView.setCursor( 113 ImageProvider.getCursor("crosshair", (way ? "joinway" : "joinnode")) 114 ); 115 return; 116 } catch (Exception e) { 117 e.printStackTrace(); 118 } 119 resetCursor(); 118 // We invoke this to prevent strange things from happening 119 EventQueue.invokeLater(new Runnable() { 120 public void run() { 121 switch(c) { 122 case way: 123 Main.map.mapView.setCursor(cursorJoinWay); 124 break; 125 case node: 126 Main.map.mapView.setCursor(cursorJoinNode); 127 break; 128 default: 129 Main.map.mapView.setCursor(cursorCrosshair); 130 break; 131 } 132 } 133 }); 134 currCursor = c; 135 } catch(Exception e) {} 120 136 } 121 122 /** 123 * Resets the cursor to the default cursor for drawing mode (i.e. crosshair) 124 */ 125 private void resetCursor() { 126 Main.map.mapView.setCursor(getCursor()); 137 138 private void redrawIfRequired() { 139 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return; 140 Main.map.mapView.repaint(); 127 141 } 128 142 129 143 /** … … 134 148 removeHighlighting(); 135 149 // if ctrl key is held ("no join"), don't highlight anything 136 150 if (ctrl) { 137 resetCursor();151 setCursor(Cursors.crosshair); 138 152 return; 139 153 } 140 154 … … 143 157 mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos); 144 158 145 159 if (mouseOnExistingNode != null) { 146 set JoinCursor(false);160 setCursor(Cursors.node); 147 161 // We also need this list for the statusbar help text 148 162 oldHighlights.add(mouseOnExistingNode); 149 163 if(drawTargetHighlight) … … 153 167 154 168 // Insert the node into all the nearby way segments 155 169 if(mouseOnExistingWays.size() == 0) { 156 resetCursor();170 setCursor(Cursors.crosshair); 157 171 return; 158 172 } 159 173 160 set JoinCursor(true);174 setCursor(Cursors.way); 161 175 162 176 // We also need this list for the statusbar help text 163 177 oldHighlights.addAll(mouseOnExistingWays); … … 218 232 if(Main.map == null || Main.map.mapView == null || !Main.map.mapView.isDrawableLayer()) 219 233 return; 220 234 updateKeyModifiers((InputEvent) event); 235 computeHelperLine(); 221 236 addHighlighting(); 222 computeHelperLine();237 redrawIfRequired(); 223 238 } 224 239 /** 225 240 * redraw to (possibly) get rid of helper line if selection changes. … … 228 243 if(!Main.map.mapView.isDrawableLayer()) 229 244 return; 230 245 computeHelperLine(); 246 addHighlighting(); 247 redrawIfRequired(); 231 248 } 232 249 233 250 private void tryAgain(MouseEvent e) { … … 246 263 Main.map.selectSelectTool(true); 247 264 248 265 // Redraw to remove the helper line stub 266 computeHelperLine(); 249 267 removeHighlighting(); 250 computeHelperLine(); 251 Main.map.mapView.repaint(); 268 redrawIfRequired(); 252 269 } 253 270 254 271 /** … … 476 493 477 494 computeHelperLine(); 478 495 removeHighlighting(); 479 Main.map.mapView.repaint();496 redrawIfRequired(); 480 497 } 481 498 482 499 /** … … 549 566 updateKeyModifiers(e); 550 567 mousePos = e.getPoint(); 551 568 569 computeHelperLine(); 552 570 addHighlighting(); 553 computeHelperLine();571 redrawIfRequired(); 554 572 } 555 573 556 574 private void updateKeyModifiers(InputEvent e) { … … 662 680 Main.map.statusLine.setHeading(hdg); 663 681 Main.map.statusLine.setDist(distance); 664 682 updateStatusLine(); 665 666 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return;667 Main.map.mapView.repaint();668 683 } 669 684 670 685 /**