Changeset 1444 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2009-02-25T14:21:24+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1443 r1444 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; … … 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); … … 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 … … 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 105 */ 106 private void setJoinCursor(boolean way) { 107 if(!drawTargetCursor) { 108 resetCursor(); 109 return; 110 } 111 * Displays the given cursor instead of the normal one 112 * @param Cursors One of the available cursors 113 */ 114 private void setCursor(final Cursors c) { 115 if(currCursor.equals(c) || (!drawTargetCursor && currCursor.equals(Cursors.crosshair))) 116 return; 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(); 120 } 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()); 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) {} 136 } 137 138 private void redrawIfRequired() { 139 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return; 140 Main.map.mapView.repaint(); 127 141 } 128 142 … … 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 } … … 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); … … 154 168 // Insert the node into all the nearby way segments 155 169 if(mouseOnExistingWays.size() == 0) { 156 resetCursor();157 return; 158 } 159 160 set JoinCursor(true);170 setCursor(Cursors.crosshair); 171 return; 172 } 173 174 setCursor(Cursors.way); 161 175 162 176 // We also need this list for the statusbar help text … … 219 233 return; 220 234 updateKeyModifiers((InputEvent) event); 235 computeHelperLine(); 221 236 addHighlighting(); 222 computeHelperLine();237 redrawIfRequired(); 223 238 } 224 239 /** … … 229 244 return; 230 245 computeHelperLine(); 246 addHighlighting(); 247 redrawIfRequired(); 231 248 } 232 249 … … 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 … … 477 494 computeHelperLine(); 478 495 removeHighlighting(); 479 Main.map.mapView.repaint();496 redrawIfRequired(); 480 497 } 481 498 … … 550 567 mousePos = e.getPoint(); 551 568 569 computeHelperLine(); 552 570 addHighlighting(); 553 computeHelperLine();571 redrawIfRequired(); 554 572 } 555 573 … … 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
Note:
See TracChangeset
for help on using the changeset viewer.