Changeset 4327 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Timestamp:
- 2011-08-21T13:12:53+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r4319 r4327 35 35 import org.openstreetmap.josm.data.osm.RelationMember; 36 36 import org.openstreetmap.josm.data.osm.Way; 37 import org.openstreetmap.josm.data.osm.WaySegment; 37 38 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 38 39 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; 39 40 import org.openstreetmap.josm.gui.NavigatableComponent; 40 41 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle; 42 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle; 43 import org.openstreetmap.josm.gui.mappaint.TextElement; 41 44 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.HorizontalTextAlignment; 42 45 import org.openstreetmap.josm.gui.mappaint.BoxTextElemStyle.VerticalTextAlignment; 43 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle;44 46 import org.openstreetmap.josm.gui.mappaint.NodeElemStyle.Symbol; 45 import org.openstreetmap.josm.gui.mappaint.TextElement;46 47 import org.openstreetmap.josm.tools.ImageProvider; 47 48 import org.openstreetmap.josm.tools.Pair; … … 53 54 private final boolean inactive; 54 55 private final MapPaintSettings settings; 56 private final Collection<WaySegment> highlightWaySegments; 55 57 56 58 private final boolean useStrokes; … … 64 66 private final Color relationSelectedColor; 65 67 private final Color nodeColor; 68 private final Color highlightColor; 69 private final Color highlightColorTransparent; 66 70 private final Color backgroundColor; 67 71 … … 81 85 public MapPainter(MapPaintSettings settings, Graphics2D g, 82 86 boolean inactive, NavigatableComponent nc, boolean virtual, 83 double circum, boolean leftHandTraffic){ 87 double circum, boolean leftHandTraffic, 88 Collection<WaySegment> highlightWaySegments){ 84 89 this.settings = settings; 85 90 this.g = g; 86 91 this.inactive = inactive; 87 92 this.nc = nc; 93 this.highlightWaySegments = highlightWaySegments; 88 94 this.useStrokes = settings.getUseStrokesDistance() > circum; 89 95 this.showNames = settings.getShowNamesDistance() > circum; … … 96 102 this.relationSelectedColor = PaintColors.RELATIONSELECTED.get(); 97 103 this.nodeColor = PaintColors.NODE.get(); 104 this.highlightColor = PaintColors.HIGHLIGHT.get(); 105 this.highlightColorTransparent = new Color(highlightColor.getRed(), highlightColor.getGreen(), highlightColor.getBlue(), 100); 98 106 this.backgroundColor = PaintColors.getBackgroundColor(); 99 107 … … 131 139 List<Node> wayNodes = way.getNodes(); 132 140 if (wayNodes.size() < 2) return; 133 134 Iterator<Point> it = new OffsetIterator(way.getNodes(), offset); 141 142 // only highlight the segment if the way itself is not highlighted 143 if(!way.isHighlighted()) { 144 GeneralPath highlightSegs = null; 145 for(WaySegment ws : highlightWaySegments) { 146 if(ws.way != way || ws.lowerIndex < offset) { 147 continue; 148 } 149 if(highlightSegs == null) { 150 highlightSegs = new GeneralPath(); 151 } 152 153 Point p1 = nc.getPoint(ws.getFirstNode()); 154 Point p2 = nc.getPoint(ws.getSecondNode()); 155 highlightSegs.moveTo(p1.x, p1.y); 156 highlightSegs.lineTo(p2.x, p2.y); 157 } 158 159 drawPathHighlight(highlightSegs, line); 160 } 161 162 163 Iterator<Point> it = new OffsetIterator(wayNodes, offset); 135 164 while (it.hasNext()) { 136 165 Point p = it.next(); … … 209 238 lastPoint = p; 210 239 } 240 if(way.isHighlighted()) { 241 drawPathHighlight(path, line); 242 } 211 243 displaySegments(path, orientationArrows, onewayArrows, onewayArrowsCasing, color, line, dashes, dashedColor); 212 244 } … … 221 253 */ 222 254 public class OffsetIterator implements Iterator<Point> { 223 255 224 256 private List<Node> nodes; 225 257 private int offset; 226 258 private int idx; 227 259 228 260 private Point prev = null; 229 261 /* 'prev0' is a point that has distance 'offset' from 'prev' and the … … 238 270 idx = 0; 239 271 } 240 272 241 273 @Override 242 274 public boolean hasNext() { … … 247 279 public Point next() { 248 280 if (offset == 0) return nc.getPoint(nodes.get(idx++)); 249 281 250 282 Point current = nc.getPoint(nodes.get(idx)); 251 283 252 284 if (idx == nodes.size() - 1) { 253 285 ++idx; … … 277 309 int dx_prev = current.x - prev.x; 278 310 int dy_prev = current.y - prev.y; 279 311 280 312 // determine intersection of the lines parallel to the two 281 313 // segments 282 314 int det = dx_next*dy_prev - dx_prev*dy_next; 283 315 284 316 if (det == 0) { 285 317 ++idx; … … 292 324 int m = dx_next*(y_current0 - y_prev0) - dy_next*(x_current0 - x_prev0); 293 325 294 int cx_ = x_prev0 + (int)Math.round(m * dx_prev / det);295 int cy_ = y_prev0 + (int)Math.round(m * dy_prev / det);326 int cx_ = x_prev0 + Math.round(m * dx_prev / det); 327 int cy_ = y_prev0 + Math.round(m * dy_prev / det); 296 328 ++idx; 297 329 prev = current; … … 307 339 } 308 340 } 309 341 310 342 private void displaySegments(GeneralPath path, GeneralPath orientationArrows, GeneralPath onewayArrows, GeneralPath onewayArrowsCasing, 311 343 Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) { … … 337 369 if(useStrokes) { 338 370 g.setStroke(new BasicStroke()); 371 } 372 } 373 374 /** 375 * highlights a given GeneralPath using the settings from BasicStroke to match the line's 376 * style. Width of the highlight is hard coded. 377 * @param path 378 * @param line 379 */ 380 private void drawPathHighlight(GeneralPath path, BasicStroke line) { 381 if(path == null) 382 return; 383 g.setColor(highlightColorTransparent); 384 float w = (line.getLineWidth() + 4); 385 while(w >= line.getLineWidth()) { 386 g.setStroke(new BasicStroke(w, line.getEndCap(), line.getLineJoin(), line.getMiterLimit())); 387 g.draw(path); 388 w -= 4; 339 389 } 340 390 } … … 498 548 public void drawNodeIcon(Node n, ImageIcon icon, float iconAlpha, boolean selected, boolean member) { 499 549 Point p = nc.getPoint(n); 500 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 501 502 int w = icon.getIconWidth(), h=icon.getIconHeight(); 550 551 final int w = icon.getIconWidth(), h=icon.getIconHeight(); 552 if(n.isHighlighted()) { 553 drawPointHighlight(p, Math.max(w, h)); 554 } 555 503 556 if (iconAlpha != 1f) { 504 557 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha)); … … 530 583 public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor) { 531 584 Point p = nc.getPoint(n); 532 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;533 585 int radius = s.size / 2; 586 587 if(n.isHighlighted()) { 588 drawPointHighlight(p, s.size); 589 } 534 590 535 591 if (fillColor != null) { … … 612 668 */ 613 669 public void drawNode(Node n, Color color, int size, boolean fill) { 670 if(size <= 0 && !n.isHighlighted()) 671 return; 672 673 Point p = nc.getPoint(n); 674 675 if(n.isHighlighted()) { 676 drawPointHighlight(p, size); 677 } 678 614 679 if (size > 1) { 615 Point p = nc.getPoint(n);616 680 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 617 681 int radius = size / 2; … … 623 687 } 624 688 if (fill) { 625 g.fillRect(p.x - radius, p.y - radius, size + 1, size + 1);689 g.fillRect(p.x-radius-1, p.y-radius-1, size + 1, size + 1); 626 690 } else { 627 g.drawRect(p.x - radius, p.y - radius, size, size); 628 } 691 g.drawRect(p.x-radius-1, p.y-radius-1, size, size); 692 } 693 } 694 } 695 696 /** 697 * highlights a given point by drawing a rounded rectangle around it. Give the 698 * size of the object you want to be highlighted, width is added automatically. 699 */ 700 private void drawPointHighlight(Point p, int size) { 701 g.setColor(highlightColorTransparent); 702 int s = size + 7; 703 while(s >= size) { 704 int r = (int) Math.floor(s/2); 705 g.fillRoundRect(p.x-r, p.y-r, s, s, r, r); 706 s -= 4; 629 707 } 630 708 } … … 633 711 if (!isShowNames() || bs == null) 634 712 return; 635 636 Point p = nc.getPoint( (Node)n);713 714 Point p = nc.getPoint(n); 637 715 TextElement text = bs.text; 638 716 String s = text.labelCompositionStrategy.compose(n); … … 823 901 824 902 public void drawRestriction(Relation r, NodeElemStyle icon) { 825 826 903 Way fromWay = null; 827 904 Way toWay = null; … … 998 1075 } 999 1076 1000 public void drawVirtualNodes(Collection<Way> ways) { 1001 1002 if (virtualNodeSize != 0) { 1003 GeneralPath path = new GeneralPath(); 1004 for (Way osm: ways){ 1005 if (osm.isUsable() && !osm.isDisabled()) { 1006 visitVirtual(path, osm); 1007 } 1008 } 1009 g.setColor(nodeColor); 1010 g.draw(path); 1011 } 1077 public void drawVirtualNodes(Collection<Way> ways, Collection<WaySegment> highlightVirtualNodes) { 1078 if (virtualNodeSize == 0) 1079 return; 1080 // print normal virtual nodes 1081 GeneralPath path = new GeneralPath(); 1082 for (Way osm: ways){ 1083 if (osm.isUsable() && !osm.isDisabled()) { 1084 visitVirtual(path, osm); 1085 } 1086 } 1087 g.setColor(nodeColor); 1088 g.draw(path); 1089 // print highlighted virtual nodes. Since only the color changes, simply 1090 // drawing them over the existing ones works fine (at least in their current 1091 // simple style) 1092 path = new GeneralPath(); 1093 for (WaySegment wseg: highlightVirtualNodes){ 1094 if (wseg.way.isUsable() && !wseg.way.isDisabled()) { 1095 visitVirtual(path, wseg.toWay()); 1096 } 1097 } 1098 g.setColor(highlightColor); 1099 g.draw(path); 1012 1100 } 1013 1101 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java
r3896 r4327 10 10 import org.openstreetmap.josm.data.Preferences.ColorKey; 11 11 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 12 import org.openstreetmap.josm.gui.mappaint.StyleSource; 12 13 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 13 import org.openstreetmap.josm.gui.mappaint.StyleSource;14 14 15 15 public enum PaintColors implements ColorKey { … … 26 26 INCOMPLETE_WAY(marktr("incomplete way"), new Color(0,0,96)), // darker blue 27 27 BACKGROUND(marktr("background"), Color.BLACK), 28 HIGHLIGHT(marktr("highlight"), new Color(0, 255, 186)), // lighteal28 HIGHLIGHT(marktr("highlight"), SELECTED.get()), 29 29 30 30 UNTAGGED(marktr("untagged"),Color.GRAY), -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r4317 r4327 5 5 import java.awt.RenderingHints; 6 6 import java.util.ArrayList; 7 import java.util.Collection; 7 8 import java.util.Collections; 8 9 import java.util.List; … … 16 17 import org.openstreetmap.josm.data.osm.Relation; 17 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.data.osm.WaySegment; 18 20 import org.openstreetmap.josm.gui.NavigatableComponent; 19 21 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; … … 220 222 RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); 221 223 222 this.painter = new MapPainter(paintSettings, g, isInactiveMode, nc, renderVirtualNodes, circum, leftHandTraffic); 224 Collection<WaySegment> hws = data.getHighlightedWaySegments(); 225 226 this.painter = new MapPainter(paintSettings, g, isInactiveMode, nc, renderVirtualNodes, circum, leftHandTraffic, hws); 223 227 224 228 StyleCollector sc = new StyleCollector(drawArea, drawMultipolygon, drawRestriction); … … 229 233 sc.drawAll(); 230 234 sc = null; 231 painter.drawVirtualNodes(data.searchWays(bbox) );235 painter.drawVirtualNodes(data.searchWays(bbox), data.getHighlightedVirtualNodes()); 232 236 233 237 //long now = System.currentTimeMillis(); -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java
r4087 r4327 25 25 import org.openstreetmap.josm.data.osm.RelationMember; 26 26 import org.openstreetmap.josm.data.osm.Way; 27 import org.openstreetmap.josm.data.osm.WaySegment; 27 28 import org.openstreetmap.josm.data.osm.visitor.Visitor; 28 29 import org.openstreetmap.josm.gui.NavigatableComponent; … … 168 169 } 169 170 } 170 drawVirtualNodes(data.searchWays(bbox)); 171 drawVirtualNodes(data.searchWays(bbox), data.getHighlightedVirtualNodes()); 172 173 // draw highlighted way segments over the already drawn ways. Otherwise each 174 // way would have to be checked if it contains a way segment to highlight when 175 // in most of the cases there won't be more than one segment. Since the wireframe 176 // renderer does not feature any transparency there should be no visual difference. 177 for(final WaySegment wseg : data.getHighlightedWaySegments()) { 178 drawSegment(nc.getPoint(wseg.getFirstNode()), nc.getPoint(wseg.getSecondNode()), highlightColor, false); 179 } 180 displaySegments(); 171 181 } 172 182 … … 228 238 } 229 239 230 public void drawVirtualNodes(Collection<Way> ways) { 231 232 if (virtualNodeSize != 0) { 233 GeneralPath path = new GeneralPath(); 234 for (Way osm: ways){ 235 if (osm.isUsable() && !osm.isDisabledAndHidden() && !osm.isDisabled()) { 236 visitVirtual(path, osm); 237 } 238 } 239 g.setColor(nodeColor); 240 g.draw(path); 241 } 240 public void drawVirtualNodes(Collection<Way> ways, Collection<WaySegment> highlightVirtualNodes) { 241 if (virtualNodeSize == 0) 242 return; 243 // print normal virtual nodes 244 GeneralPath path = new GeneralPath(); 245 for (Way osm : ways) { 246 if (osm.isUsable() && !osm.isDisabledAndHidden() && !osm.isDisabled()) { 247 visitVirtual(path, osm); 248 } 249 } 250 g.setColor(nodeColor); 251 g.draw(path); 252 // print highlighted virtual nodes. Since only the color changes, simply 253 // drawing them over the existing ones works fine (at least in their current 254 // simple style) 255 path = new GeneralPath(); 256 for (WaySegment wseg: highlightVirtualNodes){ 257 if (wseg.way.isUsable() && !wseg.way.isDisabled()) { 258 visitVirtual(path, wseg.toWay()); 259 } 260 } 261 g.setColor(highlightColor); 262 g.draw(path); 242 263 } 243 264
Note:
See TracChangeset
for help on using the changeset viewer.