Ticket #13413: patch-improve-way-accuracy-action-2.patch
| File patch-improve-way-accuracy-action-2.patch, 42.6 KB (added by , 9 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
diff --git a/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java b/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java index 35feecd..d4b71ee 100644
a b import org.openstreetmap.josm.data.osm.OsmPrimitive; 51 51 import org.openstreetmap.josm.data.osm.Way; 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; 57 56 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … import org.openstreetmap.josm.gui.MapView; 65 64 import org.openstreetmap.josm.gui.MapViewState; 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; 68 69 import org.openstreetmap.josm.gui.layer.Layer; 69 70 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 70 71 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 72 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; 71 73 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 72 74 import org.openstreetmap.josm.gui.util.ModifierListener; 73 75 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh 1507 1509 g2.setColor(SNAP_HELPER_COLOR.get()); 1508 1510 g2.setStroke(HELPER_STROKE.get()); 1509 1511 1510 Map Path2D b = new MapPath2D();1512 MapViewPath b = new MapViewPath(mv); 1511 1513 b.moveTo(p2); 1512 1514 if (absoluteFix) { 1513 1515 b.lineTo(p2.interpolate(p1, 2)); // bi-directional line … … public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh 1519 1521 if (projectionSource != null) { 1520 1522 g2.setColor(SNAP_HELPER_COLOR.get()); 1521 1523 g2.setStroke(HELPER_STROKE.get()); 1522 Map Path2D b = new MapPath2D();1524 MapViewPath b = new MapViewPath(mv); 1523 1525 b.moveTo(p3); 1524 b.lineTo( mv.getPointFor(projectionSource));1526 b.lineTo(projectionSource); 1525 1527 g2.draw(b); 1526 1528 } 1527 1529 1528 1530 if (customBaseHeading >= 0) { 1529 1531 g2.setColor(HIGHLIGHT_COLOR.get()); 1530 1532 g2.setStroke(HIGHLIGHT_STROKE.get()); 1531 Map Path2D b = new MapPath2D();1532 b.moveTo( mv.getPointFor(segmentPoint1));1533 b.lineTo( mv.getPointFor(segmentPoint2));1533 MapViewPath b = new MapViewPath(mv); 1534 b.moveTo(segmentPoint1); 1535 b.lineTo(segmentPoint2); 1534 1536 g2.draw(b); 1535 1537 } 1536 1538 1537 1539 g2.setColor(RUBBER_LINE_COLOR.get()); 1538 1540 g2.setStroke(RUBBER_LINE_STROKE.get()); 1539 Map Path2D b = new MapPath2D();1541 MapViewPath b = new MapViewPath(mv); 1540 1542 b.moveTo(p1); 1541 1543 b.lineTo(p3); 1542 1544 g2.draw(b); … … public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh 1544 1546 g2.drawString(labelText, (int) p3.getInViewX()-5, (int) p3.getInViewY()+20); 1545 1547 if (SHOW_PROJECTED_POINT.get()) { 1546 1548 g2.setStroke(RUBBER_LINE_STROKE.get()); 1547 g2.draw Oval((int) p3.getInViewX()-5, (int) p3.getInViewY()-5, 10, 10); // projected point1549 g2.draw(new MapViewPath(mv).shapeAround(p3, SymbolShape.CIRCLE, 10)); // projected point 1548 1550 } 1549 1551 1550 1552 g2.setColor(SNAP_HELPER_COLOR.get()); … … public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh 1552 1554 } 1553 1555 1554 1556 /** 1555 * If mouse position is close to line at 15-30-45-... angle, remembers this direction1557 * If mouse position is close to line at 15-30-45-... angle, remembers this direction 1556 1558 * @param currentEN Current position 1557 1559 * @param baseHeading The heading 1558 1560 * @param curHeading The current mouse heading -
src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
diff --git a/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java b/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java index e95966b..ca1ede9 100644
a b import org.openstreetmap.josm.data.preferences.ColorProperty; 47 47 import org.openstreetmap.josm.gui.MainMenu; 48 48 import org.openstreetmap.josm.gui.MapFrame; 49 49 import org.openstreetmap.josm.gui.MapView; 50 import org.openstreetmap.josm.gui.draw.MapViewPath; 50 51 import org.openstreetmap.josm.gui.layer.Layer; 51 52 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 52 53 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 54 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; 53 55 import org.openstreetmap.josm.gui.util.GuiHelper; 54 56 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 55 57 import org.openstreetmap.josm.gui.util.ModifierListener; … … public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress 1018 1020 } else { 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; 1027 1029 … … public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress 1029 1031 g2.setColor(mainColor); 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.getState()); 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 1040 1042 if (dualAlignActive) { … … public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress 1062 1064 g2.setColor(mainColor); 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.getState()).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.getState()).moveTo(p1).lineTo(p2)); 1071 1071 } 1072 1072 1073 1073 if (dualAlignActive) { … … public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress 1080 1080 g2.setStroke(helperStrokeDash); 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); 1086 1086 // Draw right angle marker on initial position, only when moving at right angle … … public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress 1162 1162 * @param seg the reference segment 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); 1167 1168 MapViewPath b = new MapViewPath(mv.getState()); 1169 b.moveTo(seg.p1); 1170 b.lineTo(seg.p2); 1172 1171 g2.draw(b); 1173 1172 } 1174 1173 -
src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
diff --git a/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java b/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java index e09b698..dcf867b 100644
a b import static org.openstreetmap.josm.tools.I18n.marktr; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 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; 15 15 import java.util.ArrayList; … … import org.openstreetmap.josm.data.osm.Node; 34 34 import org.openstreetmap.josm.data.osm.OsmPrimitive; 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; 43 45 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 44 46 import org.openstreetmap.josm.gui.layer.Layer; 45 47 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 46 import org.openstreetmap.josm.gui. util.GuiHelper;48 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; 47 49 import org.openstreetmap.josm.gui.util.ModifierListener; 48 50 import org.openstreetmap.josm.tools.ImageProvider; 49 51 import org.openstreetmap.josm.tools.Pair; … … import org.openstreetmap.josm.tools.Shortcut; 55 57 public class ImproveWayAccuracyAction extends MapMode implements 56 58 SelectionChangedListener, ModifierListener { 57 59 58 enum State {59 selecting, improving60 private enum State { 61 SELECTING, IMPROVING 60 62 } 61 63 62 64 private State state; … … public class ImproveWayAccuracyAction extends MapMode implements 72 74 private Point mousePos; 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; 92 101 … … public class ImproveWayAccuracyAction extends MapMode implements 110 119 tr("Mode: {0}", tr("Improve Way Accuracy")), 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 } 123 124 … … public class ImproveWayAccuracyAction extends MapMode implements 156 157 if (guideColor == null) 157 158 guideColor = PaintColors.HIGHLIGHT.get(); 158 159 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 160 } 166 161 167 162 @Override … … public class ImproveWayAccuracyAction extends MapMode implements 189 184 190 185 @Override 191 186 public String getModeHelpText() { 192 if (state == State. selecting) {187 if (state == State.SELECTING) { 193 188 if (targetWay != null) { 194 189 return tr("Click on the way to start improving its shape."); 195 190 } else { … … public class ImproveWayAccuracyAction extends MapMode implements 233 228 234 229 g.setColor(guideColor); 235 230 236 if (state == State. selecting&& targetWay != null) {231 if (state == State.SELECTING && targetWay != null) { 237 232 // Highlighting the targetWay in Selecting state 238 233 // Non-native highlighting is used, because sometimes highlighted 239 234 // segments are covered with others, which is bad. 240 g.setStroke( selectTargetWayStroke);235 g.setStroke(SELECT_TARGET_WAY_STROKE.get()); 241 236 242 237 List<Node> nodes = targetWay.getNodes(); 243 238 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); 239 g.draw(new MapViewPath(mv.getState()).append(nodes, false)); 258 240 259 } else if (state == State. improving) {241 } else if (state == State.IMPROVING) { 260 242 // Drawing preview lines and highlighting the node 261 243 // that is going to be moved. 262 244 // Non-native highlighting is used here as well. 263 245 264 246 // Finding endpoints 265 Point p1 = null, p2 = null; 247 Node p1 = null; 248 Node p2 = null; 266 249 if (ctrl && candidateSegment != null) { 267 g.setStroke( addNodeStroke);268 p1 = mv.getPoint(candidateSegment.getFirstNode());269 p2 = mv.getPoint(candidateSegment.getSecondNode());250 g.setStroke(ADD_NODE_STROKE.get()); 251 p1 = candidateSegment.getFirstNode(); 252 p2 = candidateSegment.getSecondNode(); 270 253 } else if (!alt && !ctrl && candidateNode != null) { 271 g.setStroke( moveNodeStroke);254 g.setStroke(MOVE_NODE_STROKE.get()); 272 255 List<Pair<Node, Node>> wpps = targetWay.getNodePairs(false); 273 256 for (Pair<Node, Node> wpp : wpps) { 274 257 if (wpp.a == candidateNode) { 275 p1 = mv.getPoint(wpp.b);258 p1 = wpp.b; 276 259 } 277 260 if (wpp.b == candidateNode) { 278 p2 = mv.getPoint(wpp.a);261 p2 = wpp.a; 279 262 } 280 263 if (p1 != null && p2 != null) { 281 264 break; 282 265 } 283 266 } 284 267 } else if (alt && !ctrl && candidateNode != null) { 285 g.setStroke( deleteNodeStroke);268 g.setStroke(DELETE_NODE_STROKE.get()); 286 269 List<Node> nodes = targetWay.getNodes(); 287 270 int index = nodes.indexOf(candidateNode); 288 271 289 272 // Only draw line if node is not first and/or last 290 273 if (index != 0 && index != (nodes.size() - 1)) { 291 p1 = mv.getPoint(nodes.get(index - 1));292 p2 = mv.getPoint(nodes.get(index + 1));274 p1 = nodes.get(index - 1); 275 p2 = nodes.get(index + 1); 293 276 } else if (targetWay.isClosed()) { 294 p1 = mv.getPoint(targetWay.getNode(1));295 p2 = mv.getPoint(targetWay.getNode(nodes.size() - 2));277 p1 = targetWay.getNode(1); 278 p2 = targetWay.getNode(nodes.size() - 2); 296 279 } 297 280 // TODO: indicate what part that will be deleted? (for end nodes) 298 281 } 299 282 300 283 301 284 // Drawing preview lines 302 Map Path2D b = new MapPath2D();285 MapViewPath b = new MapViewPath(mv.getState()); 303 286 if (alt && !ctrl) { 304 287 // In delete mode 305 288 if (p1 != null && p2 != null) { 306 b.moveTo(p1 .x, p1.y);307 b.lineTo(p2 .x, p2.y);289 b.moveTo(p1); 290 b.lineTo(p2); 308 291 } 309 292 } else { 310 293 // In add or move mode 311 294 if (p1 != null) { 312 295 b.moveTo(mousePos.x, mousePos.y); 313 b.lineTo(p1 .x, p1.y);296 b.lineTo(p1); 314 297 } 315 298 if (p2 != null) { 316 299 b.moveTo(mousePos.x, mousePos.y); 317 b.lineTo(p2 .x, p2.y);300 b.lineTo(p2); 318 301 } 319 302 } 320 303 g.draw(b); 321 304 322 305 // Highlighting candidateNode 323 306 if (candidateNode != null) { 324 p1 = mv.getPoint(candidateNode);325 g.fill Rect(p1.x - dotSize/2, p1.y - dotSize/2, dotSize, dotSize);307 p1 = candidateNode; 308 g.fill(new MapViewPath(mv.getState()).shapeAround(p1, SymbolShape.SQUARE, DOT_SIZE.get())); 326 309 } 327 310 328 311 if (!alt && !ctrl && candidateNode != null) { 329 312 b.reset(); 330 313 drawIntersectingWayHelperLines(mv, b); 331 g.setStroke( moveNodeIntersectingStroke);314 g.setStroke(MOVE_NODE_INTERSECTING_STROKE.get()); 332 315 g.draw(b); 333 316 } 334 317 335 318 } 336 319 } 337 320 338 protected void drawIntersectingWayHelperLines(MapView mv, Map Path2Db) {321 protected void drawIntersectingWayHelperLines(MapView mv, MapViewPath b) { 339 322 for (final OsmPrimitive referrer : candidateNode.getReferrers()) { 340 323 if (!(referrer instanceof Way) || targetWay.equals(referrer)) { 341 324 continue; … … public class ImproveWayAccuracyAction extends MapMode implements 346 329 continue; 347 330 } 348 331 if (i > 0) { 349 final MapViewPoint p = mv.getState().getPointFor(nodes.get(i - 1));350 332 b.moveTo(mousePos.x, mousePos.y); 351 b.lineTo( p);333 b.lineTo(nodes.get(i - 1)); 352 334 } 353 335 if (i < nodes.size() - 1) { 354 final MapViewPoint p = mv.getState().getPointFor(nodes.get(i + 1));355 336 b.moveTo(mousePos.x, mousePos.y); 356 b.lineTo( p);337 b.lineTo(nodes.get(i + 1)); 357 338 } 358 339 } 359 340 } … … public class ImproveWayAccuracyAction extends MapMode implements 413 394 updateKeyModifiers(e); 414 395 mousePos = e.getPoint(); 415 396 416 if (state == State. selecting) {397 if (state == State.SELECTING) { 417 398 if (targetWay != null) { 418 399 getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId()); 419 400 updateStateByCurrentSelection(); 420 401 } 421 } else if (state == State. improving&& mousePos != null) {402 } else if (state == State.IMPROVING && mousePos != null) { 422 403 // Checking if the new coordinate is outside of the world 423 404 if (mv.getLatLon(mousePos.x, mousePos.y).isOutSideWorld()) { 424 405 JOptionPane.showMessageDialog(Main.parent, … … public class ImproveWayAccuracyAction extends MapMode implements 552 533 return; 553 534 } 554 535 555 if (state == State. selecting) {536 if (state == State.SELECTING) { 556 537 mv.setNewCursor(targetWay == null ? cursorSelect 557 538 : cursorSelectHover, this); 558 } else if (state == State. improving) {539 } else if (state == State.IMPROVING) { 559 540 if (alt && !ctrl) { 560 541 mv.setNewCursor(cursorImproveDelete, this); 561 542 } else if (shift || dragging) { … … public class ImproveWayAccuracyAction extends MapMode implements 577 558 * candidateSegment 578 559 */ 579 560 public void updateCursorDependentObjectsIfNeeded() { 580 if (state == State. improving&& (shift || dragging)561 if (state == State.IMPROVING && (shift || dragging) 581 562 && !(candidateNode == null && candidateSegment == null)) { 582 563 return; 583 564 } … … public class ImproveWayAccuracyAction extends MapMode implements 588 569 return; 589 570 } 590 571 591 if (state == State. selecting) {572 if (state == State.SELECTING) { 592 573 targetWay = ImproveWayAccuracyHelper.findWay(mv, mousePos); 593 } else if (state == State. improving) {574 } else if (state == State.IMPROVING) { 594 575 if (ctrl && !alt) { 595 576 candidateSegment = ImproveWayAccuracyHelper.findCandidateSegment(mv, 596 577 targetWay, mousePos); … … public class ImproveWayAccuracyAction extends MapMode implements 607 588 * Switches to Selecting state 608 589 */ 609 590 public void startSelecting() { 610 state = State. selecting;591 state = State.SELECTING; 611 592 612 593 targetWay = null; 613 594 … … public class ImproveWayAccuracyAction extends MapMode implements 621 602 * @param targetWay Way that is going to be improved 622 603 */ 623 604 public void startImproving(Way targetWay) { 624 state = State. improving;605 state = State.IMPROVING; 625 606 626 607 DataSet ds = getLayerManager().getEditDataSet(); 627 608 Collection<OsmPrimitive> currentSelection = ds.getSelected(); -
src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
diff --git a/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java b/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java index 16f985f..277d631 100644
a b import org.openstreetmap.josm.data.osm.Node; 32 32 import org.openstreetmap.josm.data.osm.OsmPrimitive; 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; 38 37 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … import org.openstreetmap.josm.data.preferences.StrokeProperty; 44 43 import org.openstreetmap.josm.gui.MapFrame; 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; 49 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … public class ParallelWayAction extends MapMode implements ModifierListener, MapV 467 467 // FIXME: should clip the line (gets insanely slow when zoomed in on a very long line 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.getState()); 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.getState()); 478 line.moveTo(helperLineStart); 479 line.lineTo(helperLineEnd); 480 480 g.draw(line); 481 481 } 482 482 } -
src/org/openstreetmap/josm/data/osm/visitor/paint/ArrowPaintHelper.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/ArrowPaintHelper.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/ArrowPaintHelper.java index bdfa09d..7f99f0f 100644
a b 2 2 package org.openstreetmap.josm.data.osm.visitor.paint; 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 7 8 /** -
deleted file src/org/openstreetmap/josm/data/osm/visitor/paint/MapPath2D.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPath2D.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPath2D.java deleted file mode 100644 index cf2593c..0000000
+ - 1 // License: GPL. For details, see LICENSE file.2 package org.openstreetmap.josm.data.osm.visitor.paint;3 4 import java.awt.geom.Path2D;5 6 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;7 8 /**9 * An extension of {@link Path2D} with special methods for map positions.10 * @author Michael Zangl11 * @since 1082712 */13 public class MapPath2D extends Path2D.Double {14 /**15 * Create a new, empty path.16 */17 public MapPath2D() {18 // no default definitions19 }20 21 /**22 * Move the path to the view position of given point23 * @param p The point24 */25 public void moveTo(MapViewPoint p) {26 moveTo(p.getInViewX(), p.getInViewY());27 }28 29 /**30 * Draw a line to the view position of given point31 * @param p The point32 */33 public void lineTo(MapViewPoint p) {34 lineTo(p.getInViewX(), p.getInViewY());35 }36 } -
src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java index 3b99149..aa7875b 100644
a b import java.awt.font.GlyphVector; 20 20 import java.awt.font.LineMetrics; 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; 26 25 import java.awt.geom.Rectangle2D; … … import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.Poly 62 61 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 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; 67 68 import org.openstreetmap.josm.gui.mappaint.StyleElementList; … … public class StyledMapRenderer extends AbstractMapRenderer { 1391 1392 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) { 1397 1398 continue; 1398 1399 } 1399 1400 if (highlightSegs == null) { 1400 highlightSegs = new GeneralPath();1401 highlightSegs = new MapViewPath(mapState); 1401 1402 } 1402 1403 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()); 1404 highlightSegs.moveTo(ws.getFirstNode()); 1405 highlightSegs.lineTo(ws.getSecondNode()); 1407 1406 } 1408 1407 1409 1408 drawPathHighlight(highlightSegs, line); -
src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java
diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java index 4867897..6971d87 100644
a b import org.openstreetmap.josm.data.osm.WaySegment; 29 29 import org.openstreetmap.josm.data.osm.visitor.Visitor; 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 /** 34 35 * A map renderer that paints a simple scheme of every primitive it visits to a -
src/org/openstreetmap/josm/gui/MapViewState.java
diff --git a/src/org/openstreetmap/josm/gui/MapViewState.java b/src/org/openstreetmap/josm/gui/MapViewState.java index 9969eb0..e3bbe51 100644
a b import java.awt.geom.Path2D; 9 9 import java.awt.geom.Point2D; 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; 14 15 … … import org.openstreetmap.josm.tools.bugreport.BugReport; 28 29 * @author Michael Zangl 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 /** 34 37 * A flag indicating that the point is outside to the top of the map view. … … public final class MapViewState { 54 57 */ 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; 60 63 private final int viewHeight; -
new file src/org/openstreetmap/josm/gui/draw/MapPath2D.java
diff --git a/src/org/openstreetmap/josm/gui/draw/MapPath2D.java b/src/org/openstreetmap/josm/gui/draw/MapPath2D.java new file mode 100644 index 0000000..4675cce
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.draw; 3 4 import java.awt.geom.Path2D; 5 6 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 7 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; 8 9 /** 10 * An extension of {@link Path2D} with special methods for map positions. 11 * @author Michael Zangl 12 * @since 10827 13 */ 14 public class MapPath2D extends Path2D.Double { 15 /** 16 * Create a new, empty path. 17 */ 18 public MapPath2D() { 19 // no default definitions 20 } 21 22 /** 23 * Move the path to the view position of given point 24 * @param p The point 25 * @return this for easy chaining. 26 */ 27 public MapPath2D moveTo(MapViewPoint p) { 28 moveTo(p.getInViewX(), p.getInViewY()); 29 return this; 30 } 31 32 /** 33 * Draw a line to the view position of given point 34 * @param p The point 35 * @return this for easy chaining. 36 */ 37 public MapPath2D lineTo(MapViewPoint p) { 38 lineTo(p.getInViewX(), p.getInViewY()); 39 return this; 40 } 41 42 /** 43 * Add the given shape centered around the given point 44 * @param p The point to draw around 45 * @param symbol The symbol type 46 * @param size The size of the symbol in pixel 47 * @return this for easy chaining. 48 */ 49 public MapPath2D shapeAround(MapViewPoint p, SymbolShape symbol, double size) { 50 append(symbol.shapeAround(p.getInViewX(), p.getInViewY(), size), false); 51 return this; 52 } 53 } -
new file src/org/openstreetmap/josm/gui/draw/MapViewPath.java
diff --git a/src/org/openstreetmap/josm/gui/draw/MapViewPath.java b/src/org/openstreetmap/josm/gui/draw/MapViewPath.java new file mode 100644 index 0000000..7b2fb49
- + 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.draw; 3 4 import org.openstreetmap.josm.data.coor.EastNorth; 5 import org.openstreetmap.josm.data.osm.Node; 6 import org.openstreetmap.josm.gui.MapViewState; 7 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 8 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; 9 10 /** 11 * This is a version of a java Path2D that allows you to add points to it by simply giving their east/north, lat/lon or node coordinates. 12 * @author Michael Zangl 13 * @since xxx 14 */ 15 public class MapViewPath extends MapPath2D { 16 17 private final MapViewState state; 18 19 /** 20 * Create a new path 21 * @param state The state to use for coordinate conversion. 22 */ 23 public MapViewPath(MapViewState state) { 24 this.state = state; 25 } 26 27 /** 28 * Move the cursor to the given node. 29 * @param n The node 30 * @return this for easy chaining. 31 */ 32 public MapViewPath moveTo(Node n) { 33 moveTo(n.getEastNorth()); 34 return this; 35 } 36 37 /** 38 * Move the cursor to the given position. 39 * @param eastNorth The position 40 * @return this for easy chaining. 41 */ 42 public MapViewPath moveTo(EastNorth eastNorth) { 43 moveTo(state.getPointFor(eastNorth)); 44 return this; 45 } 46 47 @Override 48 public MapViewPath moveTo(MapViewPoint p) { 49 super.moveTo(p); 50 return this; 51 } 52 53 /** 54 * Draw a line to the node. 55 * @param n The node 56 * @return this for easy chaining. 57 */ 58 public MapViewPath lineTo(Node n) { 59 lineTo(n.getEastNorth()); 60 return this; 61 } 62 63 /** 64 * Draw a line to the position. 65 * @param eastNorth The position 66 * @return this for easy chaining. 67 */ 68 public MapViewPath lineTo(EastNorth eastNorth) { 69 lineTo(state.getPointFor(eastNorth)); 70 return this; 71 } 72 73 @Override 74 public MapViewPath lineTo(MapViewPoint p) { 75 super.lineTo(p); 76 return this; 77 } 78 79 /** 80 * Add the given shape centered around the current node. 81 * @param p1 The point to draw around 82 * @param symbol The symbol type 83 * @param size The size of the symbol in pixel 84 * @return this for easy chaining. 85 */ 86 public MapViewPath shapeAround(Node p1, SymbolShape symbol, double size) { 87 shapeAround(p1.getEastNorth(), symbol, size); 88 return this; 89 } 90 91 /** 92 * Add the given shape centered around the current position. 93 * @param eastNorth The point to draw around 94 * @param symbol The symbol type 95 * @param size The size of the symbol in pixel 96 * @return this for easy chaining. 97 */ 98 public MapViewPath shapeAround(EastNorth eastNorth, SymbolShape symbol, double size) { 99 shapeAround(state.getPointFor(eastNorth), symbol, size); 100 return this; 101 } 102 103 @Override 104 public MapViewPath shapeAround(MapViewPoint p, SymbolShape symbol, double size) { 105 super.shapeAround(p, symbol, size); 106 return this; 107 } 108 109 /** 110 * Append a list of nodes 111 * @param nodes The nodes to append 112 * @param connect <code>true</code> if we should use a lineTo as first command. 113 * @return this for easy chaining. 114 */ 115 public MapViewPath append(Iterable<Node> nodes, boolean connect) { 116 appendWay(nodes, connect, false); 117 return this; 118 } 119 120 /** 121 * Append a list of nodes as closed way. 122 * @param nodes The nodes to append 123 * @param connect <code>true</code> if we should use a lineTo as first command. 124 * @return this for easy chaining. 125 */ 126 public MapViewPath appendClosed(Iterable<Node> nodes, boolean connect) { 127 appendWay(nodes, connect, true); 128 return this; 129 } 130 131 private void appendWay(Iterable<Node> nodes, boolean connect, boolean close) { 132 boolean useMoveTo = !connect; 133 Node first = null; 134 for (Node n : nodes) { 135 if (useMoveTo) { 136 moveTo(n); 137 } else { 138 lineTo(n); 139 } 140 if (close && first == null) { 141 first = n; 142 } 143 useMoveTo = false; 144 } 145 if (first != null) { 146 lineTo(first); 147 } 148 } 149 } -
src/org/openstreetmap/josm/gui/mappaint/styleelement/Symbol.java
diff --git a/src/org/openstreetmap/josm/gui/mappaint/styleelement/Symbol.java b/src/org/openstreetmap/josm/gui/mappaint/styleelement/Symbol.java index 6699102..0e70090 100644
a b public class Symbol { 85 85 * @return The symbol shape. 86 86 */ 87 87 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; 88 return symbolShape.shapeAround(x, y, size); 119 89 } 120 90 121 91 /** … … public class Symbol { 171 141 } 172 142 173 143 /** 144 * Create the path for this shape around the given position 145 * @param x The x position 146 * @param y The y position 147 * @param size The size (width for rect, diameter for rest) 148 * @return The symbol. 149 */ 150 public Shape shapeAround(double x, double y, double size) { 151 double radius = size / 2; 152 Shape shape; 153 switch (this) { 154 case SQUARE: 155 // optimize for performance reasons 156 shape = new Rectangle2D.Double(x - radius, y - radius, size, size); 157 break; 158 case CIRCLE: 159 shape = new Ellipse2D.Double(x - radius, y - radius, size, size); 160 break; 161 default: 162 shape = buildPolygon(x, y, radius); 163 break; 164 } 165 return shape; 166 } 167 168 private Shape buildPolygon(double cx, double cy, double radius) { 169 GeneralPath polygon = new GeneralPath(); 170 for (int i = 0; i < sides; i++) { 171 double angle = ((2 * Math.PI / sides) * i) - rotation; 172 double x = cx + radius * Math.cos(angle); 173 double y = cy + radius * Math.sin(angle); 174 if (i == 0) { 175 polygon.moveTo(x, y); 176 } else { 177 polygon.lineTo(x, y); 178 } 179 } 180 polygon.closePath(); 181 return polygon; 182 } 183 184 /** 174 185 * Gets the number of normally straight sides this symbol has. Returns 1 for a circle. 175 186 * @return The sides of the symbol 176 187 */
