Changeset 2671 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-12-22T09:13:07+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java
r2668 r2671 7 7 8 8 import java.awt.Color; 9 import java.awt.Graphics2D; 9 10 import java.awt.Point; 10 11 import java.awt.Polygon; 12 import java.awt.Rectangle; 11 13 import java.awt.geom.Point2D; 12 14 import java.util.ArrayList; … … 32 34 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 33 35 import org.openstreetmap.josm.gui.DefaultNameFormatter; 36 import org.openstreetmap.josm.gui.NavigatableComponent; 34 37 import org.openstreetmap.josm.gui.mappaint.AreaElemStyle; 35 38 import org.openstreetmap.josm.gui.mappaint.ElemStyle; … … 40 43 import org.openstreetmap.josm.tools.LanguageInfo; 41 44 42 public class MapPaintVisitor extends SimplePaintVisitor { 45 public class MapPaintVisitor implements PaintVisitor { 46 47 protected Graphics2D g; 48 protected NavigatableComponent nc; 49 43 50 protected boolean useRealWidth; 44 51 protected boolean zoomLevelDisplay; … … 63 70 protected Collection<String> regionalNameOrder; 64 71 72 public boolean inactive; 73 protected boolean fillSelectedNode; 74 protected boolean fillUnselectedNode; 75 protected int defaultSegmentWidth; 76 protected boolean showOrderNumber; 77 78 protected boolean showRelevantDirectionsOnly; 79 protected boolean showHeadArrowOnly; 80 protected boolean showDirectionArrow; 81 82 protected int selectedNodeRadius; 83 protected int selectedNodeSize; 84 protected int taggedNodeSize; 85 protected int taggedNodeRadius; 86 protected int unselectedNodeRadius; 87 protected int unselectedNodeSize; 88 89 protected Color selectedColor; 90 protected Color highlightColor; 91 protected Color inactiveColor; 92 protected Color nodeColor; 93 65 94 protected boolean isZoomOk(ElemStyle e) { 66 95 if (!zoomLevelDisplay) /* show everything if the user wishes so */ … … 108 137 } 109 138 110 /**111 * Draw a small rectangle.112 * White if selected (as always) or red otherwise.113 *114 * @param n The node to draw.115 */116 @Override117 public void visit(Node n) {}118 139 public void drawNode(Node n) { 119 140 /* check, if the node is visible at all */ … … 151 172 } 152 173 153 /**154 * Draw a line for all segments, according to tags.155 * @param w The way to draw.156 */157 @Override158 public void visit(Way w) {}159 174 public void drawWay(Way w, int fillAreas) { 160 175 if(w.getNodesCount() < 2) … … 453 468 } 454 469 455 @Override456 public void visit(Relation r) {}457 470 public void paintUnselectedRelation(Relation r) { 458 471 … … 982 995 } 983 996 997 protected boolean isPolygonVisible(Polygon polygon) { 998 Rectangle bounds = polygon.getBounds(); 999 if (bounds.width == 0 && bounds.height == 0) return false; 1000 if (bounds.x > nc.getWidth()) return false; 1001 if (bounds.y > nc.getHeight()) return false; 1002 if (bounds.x + bounds.width < 0) return false; 1003 if (bounds.y + bounds.height < 0) return false; 1004 return true; 1005 } 1006 984 1007 protected Polygon getPolygon(Way w) 985 1008 { … … 1054 1077 } 1055 1078 1056 @Override 1057 public void getColors() 1058 { 1059 super.getColors(); 1079 public void getColors() { 1080 selectedColor = PaintColors.SELECTED.get(); 1081 highlightColor = PaintColors.HIGHLIGHT.get(); 1082 inactiveColor = PaintColors.INACTIVE.get(); 1083 nodeColor = PaintColors.NODE.get(); 1060 1084 untaggedColor = PaintColors.UNTAGGED.get(); 1061 1085 textColor = PaintColors.TEXT.get(); … … 1083 1107 1084 1108 /* Shows areas before non-areas */ 1085 @Override1086 1109 public void visitAll(DataSet data, boolean virtual, Bounds bounds) { 1087 1110 BBox bbox = new BBox(bounds); … … 1098 1121 dist = ll1.greatCircleDistance(ll2); 1099 1122 1100 getSettings(virtual); 1123 getColors(); 1124 1125 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction", true); 1126 showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only", true); 1127 showHeadArrowOnly = Main.pref.getBoolean("draw.segment.head_only", false); 1128 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number", false); 1129 selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2; 1130 selectedNodeSize = selectedNodeRadius * 2; 1131 unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2; 1132 unselectedNodeSize = unselectedNodeRadius * 2; 1133 taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2; 1134 taggedNodeSize = taggedNodeRadius * 2; 1135 defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2); 1136 fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true); 1137 fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false); 1138 1101 1139 useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth", false); 1102 1140 zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay", false); … … 1111 1149 regionalNameOrder = Main.pref.getCollection("mappaint.nameOrder", Arrays.asList(names)); 1112 1150 1113 this.painter = new MapPainter(g, inactive, nc, useStrokes > dist );1151 this.painter = new MapPainter(g, inactive, nc, useStrokes > dist, virtual); 1114 1152 1115 1153 data.clearErrors(); … … 1194 1232 } 1195 1233 1196 drawVirtualNodes(data.searchWays(bbox));1234 painter.drawVirtualNodes(data.searchWays(bbox)); 1197 1235 } 1198 1236 … … 1204 1242 Point p1 = nc.getPoint(n1); 1205 1243 Point p2 = nc.getPoint(n2); 1206 drawOrderNumber(p1, p2, orderNumber);1244 painter.drawOrderNumber(p1, p2, orderNumber); 1207 1245 } 1208 1246 … … 1211 1249 data.addError(p, isError ? tr("Error: {0}", text) : tr("Warning: {0}", text)); 1212 1250 } 1251 1252 public void setGraphics(Graphics2D g) { 1253 this.g = g; 1254 } 1255 1256 public void setInactive(boolean inactive) { 1257 this.inactive = inactive; 1258 } 1259 1260 public void setNavigatableComponent(NavigatableComponent nc) { 1261 this.nc = nc; 1262 } 1213 1263 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r2667 r2671 13 13 import java.awt.geom.GeneralPath; 14 14 import java.awt.geom.Rectangle2D; 15 import java.util.Collection; 15 16 import java.util.Iterator; 16 17 … … 35 36 private final Color selectedColor; 36 37 private final Color areaTextColor; 37 38 private Font orderFont; 39 private int fillAlpha; 40 41 public MapPainter(Graphics2D g, boolean inactive, NavigatableComponent nc, boolean useStrokes) { 38 private final Color nodeColor; 39 private final Color backgroundColor; 40 41 private final Font orderFont; 42 private final int fillAlpha; 43 private final int virtualNodeSize; 44 private final int virtualNodeSpace; 45 private final int segmentNumberSpace; 46 47 48 public MapPainter(Graphics2D g, boolean inactive, NavigatableComponent nc, boolean useStrokes, boolean virtual) { 42 49 this.g = g; 43 50 this.inactive = inactive; … … 49 56 this.selectedColor = PaintColors.SELECTED.get(); 50 57 this.areaTextColor = PaintColors.AREA_TEXT.get(); 58 this.nodeColor = PaintColors.NODE.get(); 59 this.backgroundColor = PaintColors.BACKGROUND.get(); 51 60 52 61 this.orderFont = new Font(Main.pref.get("mappaint.font", "Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8)); 53 62 this.fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 63 this.virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 8) / 2 : 0; 64 this.virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70); 65 this.segmentNumberSpace = Main.pref.getInteger("mappaint.segmentnumber.space", 40); 54 66 } 55 67 … … 247 259 } 248 260 261 public void drawVirtualNodes(Collection<Way> ways) { 262 263 if (virtualNodeSize != 0) { 264 GeneralPath path = new GeneralPath(); 265 for (Way osm: ways){ 266 if (osm.isUsable() && !osm.isFiltered()) { 267 visitVirtual(path, osm); 268 } 269 } 270 g.setColor(nodeColor); 271 g.draw(path); 272 } 273 } 274 275 public void visitVirtual(GeneralPath path, Way w) { 276 Iterator<Node> it = w.getNodes().iterator(); 277 if (it.hasNext()) { 278 Point lastP = nc.getPoint(it.next()); 279 while(it.hasNext()) 280 { 281 Point p = nc.getPoint(it.next()); 282 if(isSegmentVisible(lastP, p) && isLargeSegment(lastP, p, virtualNodeSpace)) 283 { 284 int x = (p.x+lastP.x)/2; 285 int y = (p.y+lastP.y)/2; 286 path.moveTo(x-virtualNodeSize, y); 287 path.lineTo(x+virtualNodeSize, y); 288 path.moveTo(x, y-virtualNodeSize); 289 path.lineTo(x, y+virtualNodeSize); 290 } 291 lastP = p; 292 } 293 } 294 } 295 296 private static boolean isLargeSegment(Point p1, Point p2, int space) { 297 int xd = p1.x-p2.x; if(xd < 0) { 298 xd = -xd; 299 } 300 int yd = p1.y-p2.y; if(yd < 0) { 301 yd = -yd; 302 } 303 return (xd+yd > space); 304 } 305 306 /** 307 * Draw an number of the order of the two consecutive nodes within the 308 * parents way 309 */ 310 protected void drawOrderNumber(Point p1, Point p2, int orderNumber) { 311 if (isSegmentVisible(p1, p2) && isLargeSegment(p1, p2, segmentNumberSpace)) { 312 String on = Integer.toString(orderNumber); 313 int strlen = on.length(); 314 int x = (p1.x+p2.x)/2 - 4*strlen; 315 int y = (p1.y+p2.y)/2 + 4; 316 317 if(virtualNodeSize != 0 && isLargeSegment(p1, p2, virtualNodeSpace)) 318 { 319 y = (p1.y+p2.y)/2 - virtualNodeSize - 3; 320 } 321 322 Color c = g.getColor(); 323 g.setColor(backgroundColor); 324 g.fillRect(x-1, y-12, 8*strlen+1, 14); 325 g.setColor(c); 326 g.drawString(on, x, y); 327 } 328 } 329 249 330 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/SimplePaintVisitor.java
r2666 r2671 33 33 * @author imi 34 34 */ 35 public class SimplePaintVisitor extends AbstractVisitor {35 public class SimplePaintVisitor extends AbstractVisitor implements PaintVisitor { 36 36 /** 37 37 * The environment to paint to. … … 487 487 } 488 488 } 489 490 public void setInactive(boolean inactive) { 491 this.inactive = inactive; 492 } 489 493 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r2666 r2671 60 60 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 61 61 import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintVisitor; 62 import org.openstreetmap.josm.data.osm.visitor.paint.PaintVisitor; 62 63 import org.openstreetmap.josm.data.osm.visitor.paint.SimplePaintVisitor; 63 64 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 238 239 } 239 240 240 SimplePaintVisitor painter;241 PaintVisitor painter; 241 242 if (Main.pref.getBoolean("draw.wireframe")) { 242 243 painter = new SimplePaintVisitor(); … … 246 247 painter.setGraphics(g); 247 248 painter.setNavigatableComponent(mv); 248 painter. inactive = inactive;249 painter.setInactive(inactive); 249 250 painter.visitAll(data, virtual, box); 250 251 Main.map.conflictDialog.paintConflicts(g, mv);
Note:
See TracChangeset
for help on using the changeset viewer.