- Timestamp:
- 2007-12-17T01:35:58+01:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r486 r493 7 7 import java.awt.Point; 8 8 import java.awt.Rectangle; 9 import java.awt.Stroke;10 9 import java.awt.geom.GeneralPath; 11 import java.awt.geom.Line2D; 12 10 11 import java.util.Iterator; 13 12 import org.openstreetmap.josm.Main; 14 13 import org.openstreetmap.josm.data.osm.DataSet; … … 64 63 protected GeneralPath currentPath = new GeneralPath(); 65 64 65 private Rectangle screen; 66 Rectangle bbox = new Rectangle(); 67 66 68 public void visitAll(DataSet data) { 67 68 69 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY); 69 70 selectedColor = getPreferencesColor("selected", Color.WHITE); … … 97 98 osm.visit(this); 98 99 displaySegments(null); 99 100 } 100 101 101 102 /** … … 135 136 } 136 137 137 int orderNumber = 0; 138 Node lastN = null; 139 for (Node n : w.nodes) { 140 if (lastN == null) { 141 lastN = n; 142 continue; 138 Iterator<Node> it = w.nodes.iterator(); 139 if (it.hasNext()) { 140 Point lastP = nc.getPoint(it.next().eastNorth); 141 for (int orderNumber = 0; it.hasNext(); orderNumber++) { 142 Point p = nc.getPoint(it.next().eastNorth); 143 orderNumber++; 144 drawSegment(lastP, p, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow || w.selected); 145 if (showOrderNumber) 146 drawOrderNumber(lastP, p, orderNumber); 147 lastP = p; 143 148 } 144 orderNumber++;145 drawSegment(lastN, n, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow);146 if (showOrderNumber)147 drawOrderNumber(lastN, n, orderNumber);148 lastN = n;149 149 } 150 150 } … … 158 158 * parents way 159 159 */ 160 protected void drawOrderNumber( Node n1, Node n2, int orderNumber) {160 protected void drawOrderNumber(Point p1, Point p2, int orderNumber) { 161 161 int strlen = (""+orderNumber).length(); 162 Point p1 = nc.getPoint(n1.eastNorth);163 Point p2 = nc.getPoint(n2.eastNorth);164 162 int x = (p1.x+p2.x)/2 - 4*strlen; 165 163 int y = (p1.y+p2.y)/2 + 4; 166 164 167 Rectangle screen = g.getClipBounds();168 165 if (screen.contains(x,y)) { 169 166 Color c = g.getColor(); … … 184 181 Point p = nc.getPoint(n.eastNorth); 185 182 g.setColor(color); 186 Rectangle screen = g.getClipBounds();187 183 188 184 if (screen.contains(p.x, p.y)) … … 198 194 * Draw a line with the given color. 199 195 */ 200 protected void drawSegment( Node n1, Node n2, Color col, boolean showDirection) {196 protected void drawSegment(Point p1, Point p2, Color col, boolean showDirection) { 201 197 202 198 if (col != currentColor) displaySegments(col); 203 199 204 Point p1 = nc.getPoint(n1.eastNorth); 205 Point p2 = nc.getPoint(n2.eastNorth); 206 207 Rectangle screen = g.getClipBounds(); 208 Line2D line = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); 209 if (screen.contains(p1.x, p1.y, p2.x, p2.y) || screen.intersectsLine(line)) 210 { 200 if (onScreen(p1, p2)) { 211 201 currentPath.moveTo(p1.x, p1.y); 212 202 currentPath.lineTo(p2.x, p2.y); … … 220 210 } 221 211 } 212 213 private boolean onScreen(Point p1, Point p2) { 214 bbox.setBounds(p1.x, p1.y, 0, 0); 215 bbox.add(p2); 216 if (bbox.height + bbox.width < 1) return false; 217 bbox.width++; 218 bbox.height++; 219 return screen.intersects(bbox); 220 } 222 221 223 222 public static Color getPreferencesColor(String colName, Color def) { … … 231 230 232 231 public void setGraphics(Graphics g) { 233 this.g = g; 234 } 232 this.g = g; 233 screen = g.getClipBounds(); 234 } 235 235 236 236 public void setNavigatableComponent(NavigatableComponent nc) {
Note:
See TracChangeset
for help on using the changeset viewer.