Changeset 805 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
- Timestamp:
- 18.08.2008 01:27:58 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r804 r805 27 27 28 28 /** 29 * A visitor that paints a simple scheme of every primitive it visits to a 29 * A visitor that paints a simple scheme of every primitive it visits to a 30 30 * previous set graphic environment. 31 * 31 * 32 32 * @author imi 33 33 */ … … 47 47 */ 48 48 protected NavigatableComponent nc; 49 49 50 50 public boolean inactive; 51 51 52 52 protected static final double PHI = Math.toRadians(20); 53 53 54 54 /** 55 55 * Preferences … … 63 63 protected Color incompleteColor; 64 64 protected Color backgroundColor; 65 protected boolean showDirectionArrow;66 protected boolean showRelevantDirectionsOnly;65 protected boolean showDirectionArrow; 66 protected boolean showRelevantDirectionsOnly; 67 67 protected boolean showOrderNumber; 68 69 private boolean fillSelectedNode; 70 71 private boolean fillUnselectedNode; 72 73 private int selectedNodeRadius; 74 75 private int unselectedNodeRadius; 76 77 private int selectedNodeSize; 78 79 private int unselectedNodeSize; 80 81 private int defaultSegmentWidth = 2; 68 protected boolean fillSelectedNode; 69 protected boolean fillUnselectedNode; 70 protected int selectedNodeRadius; 71 protected int unselectedNodeRadius; 72 protected int selectedNodeSize; 73 protected int unselectedNodeSize; 74 protected int defaultSegmentWidth = 2; 75 protected int virtualNodeSize; 76 protected int virtualNodeSpace; 77 protected int taggedNodeRadius; 78 protected int taggedNodeSize; 82 79 83 80 /** … … 88 85 89 86 Rectangle bbox = new Rectangle(); 90 private int taggedNodeRadius; 91 private int taggedNodeSize; 92 93 public void visitAll(DataSet data) { 87 88 protected void getSettings(Boolean virtual) { 94 89 inactiveColor = Main.pref.getColor(marktr("inactive"), Color.DARK_GRAY); 95 90 selectedColor = Main.pref.getColor(marktr("selected"), Color.WHITE); … … 103 98 showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only"); 104 99 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number"); 105 106 selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 107 5) / 2; 100 selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2; 108 101 selectedNodeSize = selectedNodeRadius * 2; 109 unselectedNodeRadius = Main.pref.getInteger( 110 "mappaint.node.unselected-size", 3) / 2; 102 unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2; 111 103 unselectedNodeSize = unselectedNodeRadius * 2; 112 113 taggedNodeRadius = Main.pref.getInteger( 114 "mappaint.node.tagged-size", 5) / 2; 104 taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2; 115 105 taggedNodeSize = taggedNodeRadius * 2; 116 117 defaultSegmentWidth = Main.pref.getInteger( 118 "mappaint.segment.default-width", 2); 119 120 fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", 121 true); 122 fillUnselectedNode = Main.pref.getBoolean( 123 "mappaint.node.fill-unselected", false); 106 defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2); 107 fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true); 108 fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false); 109 virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 4) / 2 : 0; 110 virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 50); 124 111 125 112 ((Graphics2D)g) 126 .setRenderingHint( 127 RenderingHints.KEY_ANTIALIASING, 128 Main.pref.getBoolean("mappaint.use-antialiasing", true) ? RenderingHints.VALUE_ANTIALIAS_ON 129 : RenderingHints.VALUE_ANTIALIAS_OFF); 130 113 .setRenderingHint( 114 RenderingHints.KEY_ANTIALIASING, 115 Main.pref.getBoolean("mappaint.use-antialiasing", true) ? RenderingHints.VALUE_ANTIALIAS_ON 116 : RenderingHints.VALUE_ANTIALIAS_OFF); 117 } 118 119 public void visitAll(DataSet data, Boolean virtual) { 120 getSettings(virtual); 131 121 // draw tagged ways first, then untagged ways. takes 132 122 // time to iterate through list twice, OTOH does not … … 141 131 displaySegments(null); 142 132 143 for (final OsmPrimitive osm : data.ways)133 for (final OsmPrimitive osm : data.ways) 144 134 if (!osm.deleted && !osm.selected && !osm.tagged) 145 135 osm.visit(this); 146 136 displaySegments(null); 147 137 148 138 for (final OsmPrimitive osm : data.nodes) 149 139 if (!osm.deleted && !osm.selected) 150 140 osm.visit(this); 151 141 152 142 for (final OsmPrimitive osm : data.getSelected()) 153 143 if (!osm.deleted) 154 144 osm.visit(this); 155 145 displaySegments(null); 156 }157 158 /** 159 * Draw a small rectangle. 146 } 147 148 /** 149 * Draw a small rectangle. 160 150 * White if selected (as always) or red otherwise. 161 * 151 * 162 152 * @param n The node to draw. 163 153 */ … … 171 161 else if(n.tagged) 172 162 drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode); 173 else 163 else 174 164 drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode); 175 165 } … … 182 172 if (w.incomplete) return; 183 173 184 // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key185 // (even if the tag is negated as in oneway=false) or the way is selected186 187 boolean showThisDirectionArrow = w.selected188 || (showDirectionArrow189 && (!showRelevantDirectionsOnly || w.hasDirectionKeys));174 // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key 175 // (even if the tag is negated as in oneway=false) or the way is selected 176 177 boolean showThisDirectionArrow = w.selected 178 || (showDirectionArrow 179 && (!showRelevantDirectionsOnly || w.hasDirectionKeys)); 190 180 Color wayColor; 191 181 192 182 if (inactive) { 193 183 wayColor = inactiveColor; … … 254 244 } 255 245 } 256 246 257 247 /** 258 248 * Draw an number of the order of the two consecutive nodes within the … … 271 261 g.drawString(""+orderNumber, x, y); 272 262 } 273 }263 } 274 264 275 265 /** … … 283 273 Point p = nc.getPoint(n.eastNorth); 284 274 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) 285 || (p.y > nc.getHeight()))275 || (p.y > nc.getHeight())) 286 276 return; 287 277 g.setColor(color); … … 294 284 } 295 285 286 protected void drawVirtualNode(Point p1, Point p2, Color col) 287 { 288 if(virtualNodeSize > 0) 289 { 290 int xd = p2.x-p1.x; if(xd < 0) xd = -xd; 291 int yd = p2.y-p1.y; if(yd < 0) yd = -yd; 292 if(xd+yd > virtualNodeSpace) 293 { 294 int x = (p1.x+p2.x)/2; 295 int y = (p1.y+p2.y)/2; 296 currentPath.moveTo(x-5, y); 297 currentPath.lineTo(x+5, y); 298 currentPath.moveTo(x, y-5); 299 currentPath.lineTo(x, y+5); 300 } 301 } 302 } 303 296 304 /** 297 305 * Draw a line with the given color. … … 300 308 301 309 if (col != currentColor) displaySegments(col); 302 310 303 311 if (isSegmentVisible(p1, p2)) { 312 drawVirtualNode(p1, p2, col); 313 304 314 currentPath.moveTo(p1.x, p1.y); 305 315 currentPath.lineTo(p2.x, p2.y); 306 316 307 317 if (showDirection) { 308 318 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 309 319 currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 310 320 currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 311 currentPath.lineTo(p2.x, p2.y); 321 currentPath.lineTo(p2.x, p2.y); 312 322 } 313 323 } 314 324 } 315 316 privateboolean isSegmentVisible(Point p1, Point p2) {317 if ((p1.x < 0) && (p2.x < 0)) return false;318 if ((p1.y < 0) && (p2.y < 0)) return false;319 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;320 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;321 return true;322 }323 325 326 protected boolean isSegmentVisible(Point p1, Point p2) { 327 if ((p1.x < 0) && (p2.x < 0)) return false; 328 if ((p1.y < 0) && (p2.y < 0)) return false; 329 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false; 330 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false; 331 return true; 332 } 333 324 334 public void setGraphics(Graphics g) { 325 335 this.g = g; … … 327 337 328 338 public void setNavigatableComponent(NavigatableComponent nc) { 329 this.nc = nc;330 }339 this.nc = nc; 340 } 331 341 332 342 protected void displaySegments(Color newColor) { … … 338 348 } 339 349 } 340 341 /**342 * Provided for backwards compatibility only.343 * FIXME: remove this once not used by plugins any longer.344 */345 public static Color getPreferencesColor(String name, Color dflt) {346 return Main.pref.getColor(name, dflt);347 }348 350 }
Note: See TracChangeset
for help on using the changeset viewer.
