Changeset 10875 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-08-22T21:16:36+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r10874 r10875 52 52 import org.openstreetmap.josm.data.osm.WaySegment; 53 53 import org.openstreetmap.josm.data.osm.visitor.paint.ArrowPaintHelper; 54 import org.openstreetmap.josm.data.osm.visitor.paint.MapPath2D;55 54 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 56 55 import org.openstreetmap.josm.data.preferences.AbstractToStringProperty; … … 66 65 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 67 66 import org.openstreetmap.josm.gui.NavigatableComponent; 67 import org.openstreetmap.josm.gui.draw.MapPath2D; 68 import org.openstreetmap.josm.gui.draw.MapViewPath; 69 import org.openstreetmap.josm.gui.draw.SymbolShape; 68 70 import org.openstreetmap.josm.gui.layer.Layer; 69 71 import org.openstreetmap.josm.gui.layer.MapViewPaintable; … … 1509 1511 g2.setStroke(HELPER_STROKE.get()); 1510 1512 1511 Map Path2D b = new MapPath2D();1513 MapViewPath b = new MapViewPath(mv); 1512 1514 b.moveTo(p2); 1513 1515 if (absoluteFix) { … … 1521 1523 g2.setColor(SNAP_HELPER_COLOR.get()); 1522 1524 g2.setStroke(HELPER_STROKE.get()); 1523 Map Path2D b = new MapPath2D();1525 MapViewPath b = new MapViewPath(mv); 1524 1526 b.moveTo(p3); 1525 b.lineTo( mv.getPointFor(projectionSource));1527 b.lineTo(projectionSource); 1526 1528 g2.draw(b); 1527 1529 } … … 1530 1532 g2.setColor(HIGHLIGHT_COLOR.get()); 1531 1533 g2.setStroke(HIGHLIGHT_STROKE.get()); 1532 Map Path2D b = new MapPath2D();1533 b.moveTo( mv.getPointFor(segmentPoint1));1534 b.lineTo( mv.getPointFor(segmentPoint2));1534 MapViewPath b = new MapViewPath(mv); 1535 b.moveTo(segmentPoint1); 1536 b.lineTo(segmentPoint2); 1535 1537 g2.draw(b); 1536 1538 } … … 1538 1540 g2.setColor(RUBBER_LINE_COLOR.get()); 1539 1541 g2.setStroke(RUBBER_LINE_STROKE.get()); 1540 Map Path2D b = new MapPath2D();1542 MapViewPath b = new MapViewPath(mv); 1541 1543 b.moveTo(p1); 1542 1544 b.lineTo(p3); … … 1546 1548 if (SHOW_PROJECTED_POINT.get()) { 1547 1549 g2.setStroke(RUBBER_LINE_STROKE.get()); 1548 g2.draw Oval((int) p3.getInViewX()-5, (int) p3.getInViewY()-5, 10, 10); // projected point1550 g2.draw(new MapViewPath(mv).shapeAround(p3, SymbolShape.CIRCLE, 10)); // projected point 1549 1551 } 1550 1552 … … 1554 1556 1555 1557 /** 1556 * 1558 * If mouse position is close to line at 15-30-45-... angle, remembers this direction 1557 1559 * @param currentEN Current position 1558 1560 * @param baseHeading The heading -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r10853 r10875 48 48 import org.openstreetmap.josm.gui.MapFrame; 49 49 import org.openstreetmap.josm.gui.MapView; 50 import org.openstreetmap.josm.gui.draw.MapViewPath; 51 import org.openstreetmap.josm.gui.draw.SymbolShape; 50 52 import org.openstreetmap.josm.gui.layer.Layer; 51 53 import org.openstreetmap.josm.gui.layer.MapViewPaintable; … … 1019 1021 if (newN1en != null) { 1020 1022 1021 Point p1 = mv.getPoint(initialN1en);1022 Point p2 = mv.getPoint(initialN2en);1023 Point p3 = mv.getPoint(newN1en);1024 Point p4 = mv.getPoint(newN2en);1023 EastNorth p1 = initialN1en; 1024 EastNorth p2 = initialN2en; 1025 EastNorth p3 = newN1en; 1026 EastNorth p4 = newN2en; 1025 1027 1026 1028 Point2D normalUnitVector = activeMoveDirection != null ? getNormalUniVector() : null; … … 1030 1032 g2.setStroke(mainStroke); 1031 1033 // Draw rectangle around new area. 1032 GeneralPath b = new GeneralPath();1033 b.moveTo(p1 .x, p1.y);1034 b.lineTo(p3 .x, p3.y);1035 b.lineTo(p4 .x, p4.y);1036 b.lineTo(p2 .x, p2.y);1037 b.lineTo(p1 .x, p1.y);1034 MapViewPath b = new MapViewPath(mv); 1035 b.moveTo(p1); 1036 b.lineTo(p3); 1037 b.lineTo(p4); 1038 b.lineTo(p2); 1039 b.lineTo(p1); 1038 1040 g2.draw(b); 1039 1041 … … 1063 1065 if (p1.distance(p2) < 3) { 1064 1066 g2.setStroke(mainStroke); 1065 g2.drawOval((int) (p1.x-symbolSize/2), (int) (p1.y-symbolSize/2), 1066 (int) (symbolSize), (int) (symbolSize)); 1067 g2.draw(new MapViewPath(mv).shapeAround(p1, SymbolShape.CIRCLE, symbolSize)); 1067 1068 } else { 1068 Line2D oldline = new Line2D.Double(p1, p2);1069 1069 g2.setStroke(oldLineStroke); 1070 g2.draw( oldline);1070 g2.draw(new MapViewPath(mv).moveTo(p1).lineTo(p2)); 1071 1071 } 1072 1072 … … 1081 1081 // Draw a guideline along the normal. 1082 1082 Line2D normline; 1083 Point2D centerpoint = new Point2D.Double((p1.getX()+p2.getX())*0.5, (p1.getY()+p2.getY())*0.5);1083 Point2D centerpoint = mv.getPoint2D(p1.interpolate(p2, .5)); 1084 1084 normline = createSemiInfiniteLine(centerpoint, normalUnitVector, g2); 1085 1085 g2.draw(normline); … … 1163 1163 */ 1164 1164 private void drawReferenceSegment(Graphics2D g2, MapView mv, ReferenceSegment seg) { 1165 Point p1 = mv.getPoint(seg.p1);1166 Point p2 = mv.getPoint(seg.p2);1167 GeneralPath b = new GeneralPath();1168 b.moveTo(p1.x, p1.y);1169 b.lineTo(p2.x, p2.y);1170 1165 g2.setColor(helperColor); 1171 1166 g2.setStroke(helperStrokeDash); 1172 g2.draw( b);1167 g2.draw(new MapViewPath(mv).moveTo(seg.p1).lineTo(seg.p2)); 1173 1168 } 1174 1169 -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r10853 r10875 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.BasicStroke; 8 9 import java.awt.Color; 9 10 import java.awt.Cursor; 10 11 import java.awt.Graphics2D; 11 12 import java.awt.Point; 12 import java.awt.Stroke;13 13 import java.awt.event.KeyEvent; 14 14 import java.awt.event.MouseEvent; … … 35 35 import org.openstreetmap.josm.data.osm.Way; 36 36 import org.openstreetmap.josm.data.osm.WaySegment; 37 import org.openstreetmap.josm.data.osm.visitor.paint.MapPath2D;38 37 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 38 import org.openstreetmap.josm.data.preferences.CachingProperty; 39 39 import org.openstreetmap.josm.data.preferences.ColorProperty; 40 import org.openstreetmap.josm.data.preferences.IntegerProperty; 41 import org.openstreetmap.josm.data.preferences.StrokeProperty; 40 42 import org.openstreetmap.josm.gui.MapFrame; 41 43 import org.openstreetmap.josm.gui.MapView; 42 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 44 import org.openstreetmap.josm.gui.draw.MapViewPath; 45 import org.openstreetmap.josm.gui.draw.SymbolShape; 43 46 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 44 47 import org.openstreetmap.josm.gui.layer.Layer; 45 48 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 46 import org.openstreetmap.josm.gui.util.GuiHelper;47 49 import org.openstreetmap.josm.gui.util.ModifierListener; 48 50 import org.openstreetmap.josm.tools.ImageProvider; … … 56 58 SelectionChangedListener, ModifierListener { 57 59 58 enum State {59 selecting, improving60 private enum State { 61 SELECTING, IMPROVING 60 62 } 61 63 … … 73 75 private boolean dragging; 74 76 75 private final Cursor cursorSelect ;76 private final Cursor cursorSelectHover ;77 private final Cursor cursorImprove ;78 private final Cursor cursorImproveAdd ;79 private final Cursor cursorImproveDelete ;80 private final Cursor cursorImproveAddLock ;81 private final Cursor cursorImproveLock ;77 private final Cursor cursorSelect = ImageProvider.getCursor("normal", "mode"); 78 private final Cursor cursorSelectHover = ImageProvider.getCursor("hand", "mode"); 79 private final Cursor cursorImprove = ImageProvider.getCursor("crosshair", null); 80 private final Cursor cursorImproveAdd = ImageProvider.getCursor("crosshair", "addnode"); 81 private final Cursor cursorImproveDelete = ImageProvider.getCursor("crosshair", "delete_node"); 82 private final Cursor cursorImproveAddLock = ImageProvider.getCursor("crosshair", "add_node_lock"); 83 private final Cursor cursorImproveLock = ImageProvider.getCursor("crosshair", "lock"); 82 84 83 85 private Color guideColor; 84 private transient Stroke selectTargetWayStroke; 85 private transient Stroke moveNodeStroke; 86 private transient Stroke moveNodeIntersectingStroke; 87 private transient Stroke addNodeStroke; 88 private transient Stroke deleteNodeStroke; 89 private int dotSize; 86 87 private static final CachingProperty<BasicStroke> SELECT_TARGET_WAY_STROKE 88 = new StrokeProperty("improvewayaccuracy.stroke.select-target", "2").cached(); 89 private static final CachingProperty<BasicStroke> MOVE_NODE_STROKE 90 = new StrokeProperty("improvewayaccuracy.stroke.move-node", "1 6").cached(); 91 private static final CachingProperty<BasicStroke> MOVE_NODE_INTERSECTING_STROKE 92 = new StrokeProperty("improvewayaccuracy.stroke.move-node-intersecting", "1 2 6").cached(); 93 private static final CachingProperty<BasicStroke> ADD_NODE_STROKE 94 = new StrokeProperty("improvewayaccuracy.stroke.add-node", "1").cached(); 95 private static final CachingProperty<BasicStroke> DELETE_NODE_STROKE 96 = new StrokeProperty("improvewayaccuracy.stroke.delete-node", "1").cached(); 97 private static final CachingProperty<Integer> DOT_SIZE 98 = new IntegerProperty("improvewayaccuracy.dot-size", 6).cached(); 90 99 91 100 private boolean selectionChangedBlocked; … … 111 120 KeyEvent.VK_W, Shortcut.DIRECT), mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 112 121 113 cursorSelect = ImageProvider.getCursor("normal", "mode");114 cursorSelectHover = ImageProvider.getCursor("hand", "mode");115 cursorImprove = ImageProvider.getCursor("crosshair", null);116 cursorImproveAdd = ImageProvider.getCursor("crosshair", "addnode");117 cursorImproveDelete = ImageProvider.getCursor("crosshair", "delete_node");118 cursorImproveAddLock = ImageProvider.getCursor("crosshair",119 "add_node_lock");120 cursorImproveLock = ImageProvider.getCursor("crosshair", "lock");121 122 readPreferences(); 122 123 } … … 156 157 if (guideColor == null) 157 158 guideColor = PaintColors.HIGHLIGHT.get(); 158 159 selectTargetWayStroke = GuiHelper.getCustomizedStroke(Main.pref.get("improvewayaccuracy.stroke.select-target", "2"));160 moveNodeStroke = GuiHelper.getCustomizedStroke(Main.pref.get("improvewayaccuracy.stroke.move-node", "1 6"));161 moveNodeIntersectingStroke = GuiHelper.getCustomizedStroke(Main.pref.get("improvewayaccuracy.stroke.move-node-intersecting", "1 2 6"));162 addNodeStroke = GuiHelper.getCustomizedStroke(Main.pref.get("improvewayaccuracy.stroke.add-node", "1"));163 deleteNodeStroke = GuiHelper.getCustomizedStroke(Main.pref.get("improvewayaccuracy.stroke.delete-node", "1"));164 dotSize = Main.pref.getInteger("improvewayaccuracy.dot-size", 6);165 159 } 166 160 … … 190 184 @Override 191 185 public String getModeHelpText() { 192 if (state == State. selecting) {186 if (state == State.SELECTING) { 193 187 if (targetWay != null) { 194 188 return tr("Click on the way to start improving its shape."); … … 234 228 g.setColor(guideColor); 235 229 236 if (state == State. selecting&& targetWay != null) {230 if (state == State.SELECTING && targetWay != null) { 237 231 // Highlighting the targetWay in Selecting state 238 232 // Non-native highlighting is used, because sometimes highlighted 239 233 // segments are covered with others, which is bad. 240 g.setStroke( selectTargetWayStroke);234 g.setStroke(SELECT_TARGET_WAY_STROKE.get()); 241 235 242 236 List<Node> nodes = targetWay.getNodes(); 243 237 244 MapPath2D b = new MapPath2D(); 245 Point p0 = mv.getPoint(nodes.get(0)); 246 Point pn; 247 b.moveTo(p0.x, p0.y); 248 249 for (Node n : nodes) { 250 pn = mv.getPoint(n); 251 b.lineTo(pn.x, pn.y); 252 } 253 if (targetWay.isClosed()) { 254 b.lineTo(p0.x, p0.y); 255 } 256 257 g.draw(b); 258 259 } else if (state == State.improving) { 238 g.draw(new MapViewPath(mv).append(nodes, false)); 239 240 } else if (state == State.IMPROVING) { 260 241 // Drawing preview lines and highlighting the node 261 242 // that is going to be moved. … … 263 244 264 245 // Finding endpoints 265 Point p1 = null, p2 = null; 246 Node p1 = null; 247 Node p2 = null; 266 248 if (ctrl && candidateSegment != null) { 267 g.setStroke( addNodeStroke);268 p1 = mv.getPoint(candidateSegment.getFirstNode());269 p2 = mv.getPoint(candidateSegment.getSecondNode());249 g.setStroke(ADD_NODE_STROKE.get()); 250 p1 = candidateSegment.getFirstNode(); 251 p2 = candidateSegment.getSecondNode(); 270 252 } else if (!alt && !ctrl && candidateNode != null) { 271 g.setStroke( moveNodeStroke);253 g.setStroke(MOVE_NODE_STROKE.get()); 272 254 List<Pair<Node, Node>> wpps = targetWay.getNodePairs(false); 273 255 for (Pair<Node, Node> wpp : wpps) { 274 256 if (wpp.a == candidateNode) { 275 p1 = mv.getPoint(wpp.b);257 p1 = wpp.b; 276 258 } 277 259 if (wpp.b == candidateNode) { 278 p2 = mv.getPoint(wpp.a);260 p2 = wpp.a; 279 261 } 280 262 if (p1 != null && p2 != null) { … … 283 265 } 284 266 } else if (alt && !ctrl && candidateNode != null) { 285 g.setStroke( deleteNodeStroke);267 g.setStroke(DELETE_NODE_STROKE.get()); 286 268 List<Node> nodes = targetWay.getNodes(); 287 269 int index = nodes.indexOf(candidateNode); … … 289 271 // Only draw line if node is not first and/or last 290 272 if (index != 0 && index != (nodes.size() - 1)) { 291 p1 = mv.getPoint(nodes.get(index - 1));292 p2 = mv.getPoint(nodes.get(index + 1));273 p1 = nodes.get(index - 1); 274 p2 = nodes.get(index + 1); 293 275 } else if (targetWay.isClosed()) { 294 p1 = mv.getPoint(targetWay.getNode(1));295 p2 = mv.getPoint(targetWay.getNode(nodes.size() - 2));276 p1 = targetWay.getNode(1); 277 p2 = targetWay.getNode(nodes.size() - 2); 296 278 } 297 279 // TODO: indicate what part that will be deleted? (for end nodes) … … 300 282 301 283 // Drawing preview lines 302 Map Path2D b = new MapPath2D();284 MapViewPath b = new MapViewPath(mv); 303 285 if (alt && !ctrl) { 304 286 // In delete mode 305 287 if (p1 != null && p2 != null) { 306 b.moveTo(p1 .x, p1.y);307 b.lineTo(p2 .x, p2.y);288 b.moveTo(p1); 289 b.lineTo(p2); 308 290 } 309 291 } else { … … 311 293 if (p1 != null) { 312 294 b.moveTo(mousePos.x, mousePos.y); 313 b.lineTo(p1 .x, p1.y);295 b.lineTo(p1); 314 296 } 315 297 if (p2 != null) { 316 298 b.moveTo(mousePos.x, mousePos.y); 317 b.lineTo(p2 .x, p2.y);299 b.lineTo(p2); 318 300 } 319 301 } … … 322 304 // Highlighting candidateNode 323 305 if (candidateNode != null) { 324 p1 = mv.getPoint(candidateNode);325 g.fill Rect(p1.x - dotSize/2, p1.y - dotSize/2, dotSize, dotSize);306 p1 = candidateNode; 307 g.fill(new MapViewPath(mv).shapeAround(p1, SymbolShape.SQUARE, DOT_SIZE.get())); 326 308 } 327 309 … … 329 311 b.reset(); 330 312 drawIntersectingWayHelperLines(mv, b); 331 g.setStroke( moveNodeIntersectingStroke);313 g.setStroke(MOVE_NODE_INTERSECTING_STROKE.get()); 332 314 g.draw(b); 333 315 } … … 336 318 } 337 319 338 protected void drawIntersectingWayHelperLines(MapView mv, Map Path2Db) {320 protected void drawIntersectingWayHelperLines(MapView mv, MapViewPath b) { 339 321 for (final OsmPrimitive referrer : candidateNode.getReferrers()) { 340 322 if (!(referrer instanceof Way) || targetWay.equals(referrer)) { … … 347 329 } 348 330 if (i > 0) { 349 final MapViewPoint p = mv.getState().getPointFor(nodes.get(i - 1));350 331 b.moveTo(mousePos.x, mousePos.y); 351 b.lineTo( p);332 b.lineTo(nodes.get(i - 1)); 352 333 } 353 334 if (i < nodes.size() - 1) { 354 final MapViewPoint p = mv.getState().getPointFor(nodes.get(i + 1));355 335 b.moveTo(mousePos.x, mousePos.y); 356 b.lineTo( p);336 b.lineTo(nodes.get(i + 1)); 357 337 } 358 338 } … … 414 394 mousePos = e.getPoint(); 415 395 416 if (state == State. selecting) {396 if (state == State.SELECTING) { 417 397 if (targetWay != null) { 418 398 getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId()); 419 399 updateStateByCurrentSelection(); 420 400 } 421 } else if (state == State. improving&& mousePos != null) {401 } else if (state == State.IMPROVING && mousePos != null) { 422 402 // Checking if the new coordinate is outside of the world 423 403 if (mv.getLatLon(mousePos.x, mousePos.y).isOutSideWorld()) { … … 553 533 } 554 534 555 if (state == State. selecting) {535 if (state == State.SELECTING) { 556 536 mv.setNewCursor(targetWay == null ? cursorSelect 557 537 : cursorSelectHover, this); 558 } else if (state == State. improving) {538 } else if (state == State.IMPROVING) { 559 539 if (alt && !ctrl) { 560 540 mv.setNewCursor(cursorImproveDelete, this); … … 578 558 */ 579 559 public void updateCursorDependentObjectsIfNeeded() { 580 if (state == State. improving&& (shift || dragging)560 if (state == State.IMPROVING && (shift || dragging) 581 561 && !(candidateNode == null && candidateSegment == null)) { 582 562 return; … … 589 569 } 590 570 591 if (state == State. selecting) {571 if (state == State.SELECTING) { 592 572 targetWay = ImproveWayAccuracyHelper.findWay(mv, mousePos); 593 } else if (state == State. improving) {573 } else if (state == State.IMPROVING) { 594 574 if (ctrl && !alt) { 595 575 candidateSegment = ImproveWayAccuracyHelper.findCandidateSegment(mv, … … 608 588 */ 609 589 public void startSelecting() { 610 state = State. selecting;590 state = State.SELECTING; 611 591 612 592 targetWay = null; … … 622 602 */ 623 603 public void startImproving(Way targetWay) { 624 state = State. improving;604 state = State.IMPROVING; 625 605 626 606 DataSet ds = getLayerManager().getEditDataSet(); -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r10874 r10875 33 33 import org.openstreetmap.josm.data.osm.Way; 34 34 import org.openstreetmap.josm.data.osm.WaySegment; 35 import org.openstreetmap.josm.data.osm.visitor.paint.MapPath2D;36 35 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 37 36 import org.openstreetmap.josm.data.preferences.AbstractToStringProperty; … … 45 44 import org.openstreetmap.josm.gui.MapView; 46 45 import org.openstreetmap.josm.gui.Notification; 46 import org.openstreetmap.josm.gui.draw.MapViewPath; 47 47 import org.openstreetmap.josm.gui.layer.Layer; 48 48 import org.openstreetmap.josm.gui.layer.MapViewPaintable; … … 468 468 g.setStroke(REF_LINE_STROKE.get()); 469 469 g.setColor(mainColor); 470 Map Path2D line = new MapPath2D();471 line.moveTo( mv.getState().getPointFor(referenceSegment.getFirstNode()));472 line.lineTo( mv.getState().getPointFor(referenceSegment.getSecondNode()));470 MapViewPath line = new MapViewPath(mv); 471 line.moveTo(referenceSegment.getFirstNode()); 472 line.lineTo(referenceSegment.getSecondNode()); 473 473 g.draw(line); 474 474 475 475 g.setStroke(HELPER_LINE_STROKE.get()); 476 476 g.setColor(mainColor); 477 line = new Map Path2D();478 line.moveTo( mv.getState().getPointFor(helperLineStart));479 line.lineTo( mv.getState().getPointFor(helperLineEnd));477 line = new MapViewPath(mv); 478 line.moveTo(helperLineStart); 479 line.lineTo(helperLineEnd); 480 480 g.draw(line); 481 481 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/ArrowPaintHelper.java
r10829 r10875 3 3 4 4 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 5 import org.openstreetmap.josm.gui.draw.MapPath2D; 5 6 import org.openstreetmap.josm.tools.Utils; 6 7 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r10856 r10875 21 21 import java.awt.font.TextLayout; 22 22 import java.awt.geom.AffineTransform; 23 import java.awt.geom.GeneralPath;24 23 import java.awt.geom.Path2D; 25 24 import java.awt.geom.Point2D; … … 63 62 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 64 63 import org.openstreetmap.josm.gui.NavigatableComponent; 64 import org.openstreetmap.josm.gui.draw.MapPath2D; 65 import org.openstreetmap.josm.gui.draw.MapViewPath; 65 66 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 66 67 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 1392 1393 // only highlight the segment if the way itself is not highlighted 1393 1394 if (!way.isHighlighted() && highlightWaySegments != null) { 1394 GeneralPath highlightSegs = null;1395 MapViewPath highlightSegs = null; 1395 1396 for (WaySegment ws : highlightWaySegments) { 1396 1397 if (ws.way != way || ws.lowerIndex < offset) { … … 1398 1399 } 1399 1400 if (highlightSegs == null) { 1400 highlightSegs = new GeneralPath(); 1401 } 1402 1403 Point2D p1 = mapState.getPointFor(ws.getFirstNode()).getInView(); 1404 Point2D p2 = mapState.getPointFor(ws.getSecondNode()).getInView(); 1405 highlightSegs.moveTo(p1.getX(), p1.getY()); 1406 highlightSegs.lineTo(p2.getX(), p2.getY()); 1401 highlightSegs = new MapViewPath(mapState); 1402 } 1403 1404 highlightSegs.moveTo(ws.getFirstNode()); 1405 highlightSegs.lineTo(ws.getSecondNode()); 1407 1406 } 1408 1407 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java
r10829 r10875 30 30 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 31 31 import org.openstreetmap.josm.gui.NavigatableComponent; 32 import org.openstreetmap.josm.gui.draw.MapPath2D; 32 33 33 34 /** -
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r10874 r10875 10 10 import java.awt.geom.Point2D.Double; 11 11 import java.awt.geom.Rectangle2D; 12 import java.io.Serializable; 12 13 13 14 import javax.swing.JComponent; … … 29 30 * @since 10343 30 31 */ 31 public final class MapViewState { 32 public final class MapViewState implements Serializable { 33 34 private static final long serialVersionUID = 1L; 32 35 33 36 /** … … 55 58 public static final int OUTSIDE_RIGHT = 8; 56 59 57 private final Projecting projecting;60 private final transient Projecting projecting; 58 61 59 62 private final int viewWidth; -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
r10827 r10875 16 16 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings; 17 17 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; 18 import org.openstreetmap.josm.gui.draw.SymbolShape; 18 19 import org.openstreetmap.josm.gui.mappaint.Cascade; 19 20 import org.openstreetmap.josm.gui.mappaint.Environment; … … 24 25 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProvider; 25 26 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.SimpleBoxProvider; 26 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape;27 27 import org.openstreetmap.josm.gui.util.RotationAngle; 28 28 import org.openstreetmap.josm.tools.CheckParameterUtil; -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/Symbol.java
r10840 r10875 5 5 import java.awt.Shape; 6 6 import java.awt.Stroke; 7 import java.awt.geom.Ellipse2D;8 import java.awt.geom.GeneralPath;9 import java.awt.geom.Rectangle2D;10 7 import java.util.Objects; 11 import java.util.Optional; 12 import java.util.stream.Stream;8 9 import org.openstreetmap.josm.gui.draw.SymbolShape; 13 10 14 11 /** … … 86 83 */ 87 84 public Shape buildShapeAround(double x, double y) { 88 int radius = size / 2; 89 Shape shape; 90 switch (symbolShape) { 91 case SQUARE: 92 // optimize for performance reasons 93 shape = new Rectangle2D.Double(x - radius, y - radius, size, size); 94 break; 95 case CIRCLE: 96 shape = new Ellipse2D.Double(x - radius, y - radius, size, size); 97 break; 98 default: 99 shape = buildPolygon(x, y, radius); 100 break; 101 } 102 return shape; 103 } 104 105 private Shape buildPolygon(double cx, double cy, int radius) { 106 GeneralPath polygon = new GeneralPath(); 107 for (int i = 0; i < symbolShape.sides; i++) { 108 double angle = ((2 * Math.PI / symbolShape.sides) * i) - symbolShape.rotation; 109 double x = cx + radius * Math.cos(angle); 110 double y = cy + radius * Math.sin(angle); 111 if (i == 0) { 112 polygon.moveTo(x, y); 113 } else { 114 polygon.lineTo(x, y); 115 } 116 } 117 polygon.closePath(); 118 return polygon; 119 } 120 121 /** 122 * A list of possible symbol shapes. 123 */ 124 public enum SymbolShape { 125 /** 126 * A square 127 */ 128 SQUARE("square", 4, Math.PI / 4), 129 /** 130 * A circle 131 */ 132 CIRCLE("circle", 1, 0), 133 /** 134 * A triangle with sides of equal lengh 135 */ 136 TRIANGLE("triangle", 3, Math.PI / 2), 137 /** 138 * A pentagon 139 */ 140 PENTAGON("pentagon", 5, Math.PI / 2), 141 /** 142 * A hexagon 143 */ 144 HEXAGON("hexagon", 6, 0), 145 /** 146 * A heptagon 147 */ 148 HEPTAGON("heptagon", 7, Math.PI / 2), 149 /** 150 * An octagon 151 */ 152 OCTAGON("octagon", 8, Math.PI / 8), 153 /** 154 * a nonagon 155 */ 156 NONAGON("nonagon", 9, Math.PI / 2), 157 /** 158 * A decagon 159 */ 160 DECAGON("decagon", 10, 0); 161 162 private final String name; 163 final int sides; 164 165 final double rotation; 166 167 SymbolShape(String name, int sides, double rotation) { 168 this.name = name; 169 this.sides = sides; 170 this.rotation = rotation; 171 } 172 173 /** 174 * Gets the number of normally straight sides this symbol has. Returns 1 for a circle. 175 * @return The sides of the symbol 176 */ 177 public int getSides() { 178 return sides; 179 } 180 181 /** 182 * Gets the rotateion of the first point of this symbol. 183 * @return The roration 184 */ 185 public double getRotation() { 186 return rotation; 187 } 188 189 /** 190 * Get the MapCSS name for this shape 191 * @return The name 192 */ 193 public String getName() { 194 return name; 195 } 196 197 /** 198 * Get the shape with the given name 199 * @param val The name to search 200 * @return The shape as optional 201 */ 202 public static Optional<SymbolShape> forName(String val) { 203 return Stream.of(values()).filter(shape -> val.equals(shape.name)).findAny(); 204 } 85 return symbolShape.shapeAround(x, y, size); 205 86 } 206 87 }
Note:
See TracChangeset
for help on using the changeset viewer.