Ticket #1902: TargetHighlight.patch
| File TargetHighlight.patch, 16.1 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: images\cursor\modifier\joinnode.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: images\cursor\modifier\joinway.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
65 65 private boolean ctrl; 66 66 private boolean alt; 67 67 private boolean shift; 68 private boolean mouseOnExistingNode; 68 private Node mouseOnExistingNode; 69 private Set<Way> mouseOnExistingWays = new HashSet<Way>(); 70 private Set<OsmPrimitive> oldHighlights = new HashSet<OsmPrimitive>(); 69 71 private boolean drawHelperLine; 70 72 private boolean wayIsFinished = false; 73 private boolean drawTargetHighlight; 74 private boolean drawTargetCursor; 71 75 private Point mousePos; 72 76 private Color selectedColor; 73 77 … … 92 96 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 93 97 } 94 98 99 /** 100 * Sets a special cursor to indicate that the next click will automatically join into 101 * an existing node or way (if feature is enabled) 102 * 103 * @param way If true, the cursor will indicate it is joined into a way; node otherwise 104 */ 105 private void setJoinCursor(boolean way) { 106 if(!drawTargetCursor) { 107 resetCursor(); 108 return; 109 } 110 try { 111 Main.map.mapView.setCursor( 112 ImageProvider.getCursor("crosshair", (way ? "joinway" : "joinnode")) 113 ); 114 return; 115 } catch (Exception e) { 116 e.printStackTrace(); 117 } 118 resetCursor(); 119 } 120 121 /** 122 * Resets the cursor to the default cursor for drawing mode (i.e. crosshair) 123 */ 124 private void resetCursor() { 125 Main.map.mapView.setCursor(getCursor()); 126 } 127 128 /** 129 * Takes the data from computeHelperLine to determine which ways/nodes should be highlighted 130 * (if feature enabled). Also sets the target cursor if appropriate. 131 */ 132 private void addHighlighting() { 133 // if ctrl key is held ("no join"), don't highlight anything 134 if (ctrl) { 135 removeHighlighting(); 136 resetCursor(); 137 return; 138 } 139 140 if (mouseOnExistingNode != null) { 141 setJoinCursor(false); 142 // Clean old highlights 143 removeHighlighting(); 144 if(drawTargetHighlight) { 145 oldHighlights.add(mouseOnExistingNode); 146 mouseOnExistingNode.highlighted = true; 147 } 148 return; 149 } 150 151 // Insert the node into all the nearby way segments 152 if(mouseOnExistingWays.size() == 0) { 153 removeHighlighting(); 154 resetCursor(); 155 return; 156 } 157 158 setJoinCursor(true); 159 // Clean old highlights 160 removeHighlighting(); 161 162 if(!drawTargetHighlight) return; 163 oldHighlights.addAll(mouseOnExistingWays); 164 for(Way w : mouseOnExistingWays) { 165 w.highlighted = true; 166 } 167 } 168 169 /** 170 * Removes target highlighting from primitives 171 */ 172 private void removeHighlighting() { 173 for(OsmPrimitive prim : oldHighlights) { 174 prim.highlighted = false; 175 } 176 } 177 95 178 @Override public void enterMode() { 96 179 super.enterMode(); 97 180 selectedColor = Main.pref.getColor(marktr("selected"), Color.red); 98 181 drawHelperLine = Main.pref.getBoolean("draw.helper-line", true); 182 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true); 183 drawTargetCursor = Main.pref.getBoolean("draw.target-cursor", true); 99 184 wayIsFinished = false; 100 185 101 186 Main.map.mapView.addMouseListener(this); 102 187 Main.map.mapView.addMouseMotionListener(this); 103 188 Main.map.mapView.addTemporaryLayer(this); 104 189 DataSet.selListeners.add(this); 190 105 191 try { 106 192 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 107 193 } catch (SecurityException ex) { … … 109 195 // would like to but haven't got mouse position yet: 110 196 // computeHelperLine(false, false, false); 111 197 } 198 112 199 @Override public void exitMode() { 113 200 super.exitMode(); 114 201 Main.map.mapView.removeMouseListener(this); 115 202 Main.map.mapView.removeMouseMotionListener(this); 116 203 Main.map.mapView.removeTemporaryLayer(this); 117 204 DataSet.selListeners.remove(this); 205 removeHighlighting(); 118 206 try { 119 207 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 120 208 } catch (SecurityException ex) { … … 146 234 Main.ds.setSelected(); 147 235 mouseClicked(e); 148 236 } 149 237 150 238 /** 151 239 * If user clicked with the left button, add a node at the current mouse 152 240 * position. … … 183 271 184 272 if (!ctrl) 185 273 n = Main.map.mapView.getNearestNode(mousePos); 186 274 187 275 if (n != null) { 188 276 // user clicked on node 189 277 if (shift || selection.isEmpty()) { … … 258 346 if (!shift && selection.size() > 0 && !wayIsFinishedTemp) { 259 347 Node selectedNode = null; 260 348 Way selectedWay = null; 261 349 262 350 for (OsmPrimitive p : selection) { 263 351 if (p instanceof Node) { 264 352 if (selectedNode != null) { … … 276 364 selectedWay = (Way) p; 277 365 } 278 366 } 279 367 280 368 // No nodes or ways have been selected, try again with no selection 281 369 // This occurs when a relation has been selected 282 370 if(selectedNode == null && selectedWay == null) { … … 291 379 if (selectedWay.isFirstLastNode(lastUsedNode)) { 292 380 n0 = lastUsedNode; 293 381 } else { 294 // We have a way selected, but no suitable node to continue from. Start anew. 382 // We have a way selected, but no suitable node to continue from. Start anew. 295 383 tryAgain(e); 296 384 return; 297 385 } … … 325 413 return; 326 414 } 327 415 } 328 416 329 417 // User clicked last node again, finish way 330 418 if(n0 == n) { 331 419 lastUsedNode = null; … … 378 466 extendedWay = true; 379 467 Main.ds.setSelected(way); 380 468 } 381 469 382 470 String title; 383 471 if (!extendedWay) { 384 472 if (!newNode) { … … 403 491 Main.main.undoRedo.add(c); 404 492 if(!wayIsFinished) lastUsedNode = n; 405 493 computeHelperLine(); 494 removeHighlighting(); 406 495 Main.map.mapView.repaint(); 407 496 } 408 497 … … 419 508 shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 420 509 mousePos = e.getPoint(); 421 510 511 addHighlighting(); 422 512 computeHelperLine(); 423 513 } 424 514 … … 443 533 Node selectedNode = null; 444 534 Way selectedWay = null; 445 535 Node currentMouseNode = null; 446 mouseOnExistingNode = false; 536 mouseOnExistingNode = null; 537 mouseOnExistingWays = new HashSet<Way>(); 447 538 448 539 Main.map.statusLine.setAngle(-1); 449 540 Main.map.statusLine.setHeading(-1); … … 453 544 currentMouseNode = Main.map.mapView.getNearestNode(mousePos); 454 545 } 455 546 547 // We need this for highlighting and we'll only do so if we actually want to re-use 548 // *and* there is no node nearby (because nodes beat ways when re-using) 549 if(!ctrl && currentMouseNode == null) { 550 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(mousePos); 551 for(WaySegment ws : wss) 552 mouseOnExistingWays.add(ws.way); 553 } 554 456 555 if (currentMouseNode != null) { 457 556 // user clicked on node 458 557 if (selection.isEmpty()) return; 459 558 currentMouseEastNorth = currentMouseNode.eastNorth; 460 mouseOnExistingNode = true;559 mouseOnExistingNode = currentMouseNode; 461 560 } else { 462 561 // no node found in clicked area 463 562 currentMouseEastNorth = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y); … … 510 609 Main.map.statusLine.setDist(distance); 511 610 updateStatusLine(); 512 611 513 if (!drawHelperLine || wayIsFinished) return; 514 612 if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return; 515 613 Main.map.mapView.repaint(); 516 614 } 517 615 … … 639 737 } 640 738 641 739 public void paint(Graphics g, MapView mv) { 740 if (!drawHelperLine && !drawTargetHighlight) return; 642 741 643 // don't draw line if disabled in prefs644 if (!drawHelperLine) return;645 646 742 // sanity checks 647 743 if (Main.map.mapView == null) return; 648 744 if (mousePos == null) return; … … 651 747 if (shift) return; 652 748 653 749 // don't draw line if we don't know where from or where to 654 if (currentBaseNode == null) return; 655 if (currentMouseEastNorth == null) return; 750 if (currentBaseNode == null || currentMouseEastNorth == null) return; 656 751 657 752 // don't draw line if mouse is outside window 658 753 if (!Main.map.mapView.getBounds().contains(mousePos)) return; … … 676 771 677 772 g2.draw(b); 678 773 g2.setStroke(new BasicStroke(1)); 679 680 774 } 681 775 682 776 @Override public String getModeHelpText() { 683 777 String rv; 684 778 685 779 if (currentBaseNode != null && !shift) { 686 if (mouseOnExistingNode ) {780 if (mouseOnExistingNode != null) { 687 781 if (alt && /* FIXME: way exists */true) 688 782 rv = tr("Click to create a new way to the existing node."); 689 783 else … … 703 797 //rv.append(tr("Click to add a new node. Ctrl: no node re-use/auto-insert. Shift: no auto-connect. Alt: new way")); 704 798 return rv.toString(); 705 799 } 706 800 707 801 @Override public boolean layerIsSupported(Layer l) { 708 802 return l instanceof OsmDataLayer; 709 803 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
122 122 * If set to true, this object is currently selected. 123 123 */ 124 124 public volatile boolean selected = false; 125 126 /** 127 * If set to true, this object is highlighted. Currently this is only used to 128 * show which ways/nodes will connect 129 */ 130 public volatile boolean highlighted = false; 125 131 126 132 /** 127 133 * Time of last modification to this object. This is not set by JOSM but -
src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
119 119 120 120 if(osm.mappaintStyle == null && styles != null) { 121 121 osm.mappaintStyle = styles.get(osm); 122 if(osm instanceof Way) 123 osm.isMappaintArea = styles.isArea(osm); 122 osm.isMappaintArea = styles.isArea(osm); 124 123 } 125 124 return osm.isMappaintArea; 126 125 } … … 150 149 151 150 if (nodeStyle != null && isZoomOk(nodeStyle) && showIcons > dist) 152 151 drawNode(n, nodeStyle.icon, nodeStyle.annotate, n.selected); 152 else if (n.highlighted) 153 drawNode(n, highlightColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 153 154 else if (n.selected) 154 155 drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 155 156 else if (n.tagged) … … 265 266 int tmpWidth = (int) (100 / (float) (circum / realWidth)); 266 267 if (tmpWidth > width) width = tmpWidth; 267 268 } 268 if(w.selected) 269 270 if(w.highlighted) 271 color = highlightColor; 272 else if(w.selected) 269 273 color = selectedColor; 270 274 271 275 // draw overlays under the way … … 1135 1139 } 1136 1140 g2d.draw(currentPath); 1137 1141 } 1138 1142 1139 1143 if(useStrokes > dist) 1140 1144 g2d.setStroke(new BasicStroke(1)); 1141 1145 -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
36 36 public final static Color darkblue = new Color(0,0,128); 37 37 public final static Color darkgreen = new Color(0,128,0); 38 38 public final static Color teal = new Color(0,128,128); 39 public final static Color lightteal= new Color(0, 255, 186); 39 40 40 41 /** 41 42 * The environment to paint to. … … 61 62 protected Color untaggedWayColor; 62 63 protected Color incompleteColor; 63 64 protected Color backgroundColor; 65 protected Color highlightColor; 64 66 protected boolean showDirectionArrow; 65 67 protected boolean showRelevantDirectionsOnly; 66 68 protected boolean showHeadArrowOnly; … … 96 98 untaggedWayColor = Main.pref.getColor(marktr("untagged way"), darkgreen); 97 99 incompleteColor = Main.pref.getColor(marktr("incomplete way"), darkerblue); 98 100 backgroundColor = Main.pref.getColor(marktr("background"), Color.BLACK); 101 highlightColor = Main.pref.getColor(marktr("highlight"), lightteal); 99 102 } 100 103 101 104 protected void getSettings(Boolean virtual) { … … 131 134 System.out.println("Simplepaint Profiler"); 132 135 133 136 getSettings(virtual); 134 135 if(profiler) 137 138 if(profiler) 136 139 { 137 140 System.out.format("Prepare : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast)); 138 141 profilerLast = java.lang.System.currentTimeMillis(); 139 142 } 140 143 141 144 // draw tagged ways first, then untagged ways. takes 142 145 // time to iterate through list twice, OTOH does not 143 146 // require changing the colour while painting... … … 244 247 245 248 if (inactive) 246 249 drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode); 250 else if (n.highlighted) 251 drawNode(n, highlightColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 247 252 else if (n.selected) 248 253 drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 249 254 else if(n.tagged) … … 300 305 301 306 if (inactive) { 302 307 wayColor = inactiveColor; 308 } else if(w.highlighted) { 309 wayColor = highlightColor; 310 } else if(w.selected) { 311 wayColor = selectedColor; 303 312 } else if (!w.tagged) { 304 313 wayColor = untaggedWayColor; 305 314 } else { … … 311 320 Point lastP = nc.getPoint(it.next().eastNorth); 312 321 for (int orderNumber = 1; it.hasNext(); orderNumber++) { 313 322 Point p = nc.getPoint(it.next().eastNorth); 314 drawSegment(lastP, p, w .selected && !inactive ? selectedColor : wayColor,323 drawSegment(lastP, p, wayColor, 315 324 showOnlyHeadArrowOnly ? !it.hasNext() : showThisDirectionArrow); 316 325 if (showOrderNumber) 317 326 drawOrderNumber(lastP, p, orderNumber);
