Changeset 1409 in josm
- Timestamp:
- 2009-02-15T18:30:41+01:00 (16 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1405 r1409 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; … … 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); … … 110 196 // computeHelperLine(false, false, false); 111 197 } 198 112 199 @Override public void exitMode() { 113 200 super.exitMode(); … … 116 203 Main.map.mapView.removeTemporaryLayer(this); 117 204 DataSet.selListeners.remove(this); 205 removeHighlighting(); 118 206 try { 119 207 Toolkit.getDefaultToolkit().removeAWTEventListener(this); … … 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 … … 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 … … 259 347 Node selectedNode = null; 260 348 Way selectedWay = null; 261 349 262 350 for (OsmPrimitive p : selection) { 263 351 if (p instanceof Node) { … … 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 … … 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; … … 326 414 } 327 415 } 328 416 329 417 // User clicked last node again, finish way 330 418 if(n0 == n) { … … 379 467 Main.ds.setSelected(way); 380 468 } 381 469 382 470 String title; 383 471 if (!extendedWay) { … … 404 492 if(!wayIsFinished) lastUsedNode = n; 405 493 computeHelperLine(); 494 removeHighlighting(); 406 495 Main.map.mapView.repaint(); 407 496 } … … 420 509 mousePos = e.getPoint(); 421 510 511 addHighlighting(); 422 512 computeHelperLine(); 423 513 } … … 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); … … 452 543 if (!ctrl && mousePos != null) { 453 544 currentMouseNode = Main.map.mapView.getNearestNode(mousePos); 545 } 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); 454 553 } 455 554 … … 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 … … 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 } … … 640 738 641 739 public void paint(Graphics g, MapView mv) { 642 643 // don't draw line if disabled in prefs 644 if (!drawHelperLine) return; 740 if (!drawHelperLine && !drawTargetHighlight) return; 645 741 646 742 // sanity checks … … 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 … … 677 772 g2.draw(b); 678 773 g2.setStroke(new BasicStroke(1)); 679 680 774 } 681 775 … … 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."); … … 704 798 return rv.toString(); 705 799 } 706 800 707 801 @Override public boolean layerIsSupported(Layer l) { 708 802 return l instanceof OsmDataLayer; -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r1314 r1409 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 /** -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r1367 r1409 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; … … 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); … … 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 … … 1136 1140 g2d.draw(currentPath); 1137 1141 } 1138 1142 1139 1143 if(useStrokes > dist) 1140 1144 g2d.setStroke(new BasicStroke(1)); -
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r1289 r1409 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 /** … … 62 63 protected Color incompleteColor; 63 64 protected Color backgroundColor; 65 protected Color highlightColor; 64 66 protected boolean showDirectionArrow; 65 67 protected boolean showRelevantDirectionsOnly; … … 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 … … 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 … … 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); … … 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; … … 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)
Note:
See TracChangeset
for help on using the changeset viewer.