- Timestamp:
- 2007-09-03T00:24:58+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r298 r315 4 4 import java.awt.Color; 5 5 import java.awt.Graphics; 6 import java.awt.Graphics2D; 6 7 import java.awt.Point; 8 import java.awt.Polygon; 7 9 import java.awt.Rectangle; 10 import java.awt.geom.GeneralPath; 8 11 import java.awt.geom.Line2D; 9 12 … … 28 31 public final static Color darkblue = new Color(0,0,128); 29 32 public final static Color darkgreen = new Color(0,128,0); 30 33 31 34 /** 32 35 * The environment to paint to. … … 39 42 40 43 public boolean inactive; 41 44 42 45 protected static final double PHI = Math.toRadians(20); 43 46 47 /** 48 * Preferences 49 */ 50 protected Color inactiveColor; 51 protected Color selectedColor; 52 protected Color nodeColor; 53 protected Color segmentColor; 54 protected Color dfltWayColor; 55 protected Color incompleteColor; 56 protected Color backgroundColor; 57 protected boolean showDirectionArrow; 58 protected boolean showOrderNumber; 59 60 /** 61 * Draw subsequent segments of same color as one Path 62 */ 63 protected Color currentColor = null; 64 protected GeneralPath currrentPath = new GeneralPath(); 65 44 66 public void visitAll(DataSet data) { 67 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY); 68 selectedColor = getPreferencesColor("selected", Color.WHITE); 69 nodeColor = getPreferencesColor("node", Color.RED); 70 segmentColor = getPreferencesColor("segment", darkgreen); 71 dfltWayColor = getPreferencesColor("way", darkblue); 72 incompleteColor = getPreferencesColor("incomplete way", darkerblue); 73 backgroundColor = getPreferencesColor("background", Color.BLACK); 74 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction"); 75 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number"); 76 45 77 for (final OsmPrimitive osm : data.segments) 46 78 if (!osm.deleted && !osm.selected) … … 49 81 if (!osm.deleted && !osm.selected) 50 82 osm.visit(this); 83 displaySegments(null); // Flush segment cache before nodes 51 84 for (final OsmPrimitive osm : data.nodes) 52 85 if (!osm.deleted && !osm.selected) … … 55 88 if (!osm.deleted) 56 89 osm.visit(this); 90 displaySegments(null); 57 91 } 58 92 … … 66 100 Color color = null; 67 101 if (inactive) 68 color = getPreferencesColor("inactive", Color.DARK_GRAY);102 color = inactiveColor; 69 103 else if (n.selected) 70 color = getPreferencesColor("selected", Color.WHITE);104 color = selectedColor; 71 105 else 72 color = getPreferencesColor("node", Color.RED);106 color = nodeColor; 73 107 drawNode(n, color); 74 108 } … … 81 115 Color color; 82 116 if (inactive) 83 color = getPreferencesColor("inactive", Color.DARK_GRAY);117 color = inactiveColor; 84 118 else if (ls.selected) 85 color = getPreferencesColor("selected", Color.WHITE);119 color = selectedColor; 86 120 else 87 color = getPreferencesColor("segment", darkgreen);88 drawSegment(ls, color, Main.pref.getBoolean("draw.segment.direction"));121 color = segmentColor; 122 drawSegment(ls, color, showDirectionArrow); 89 123 } 90 124 … … 96 130 Color wayColor; 97 131 if (inactive) 98 wayColor = getPreferencesColor("inactive", Color.DARK_GRAY);132 wayColor = inactiveColor; 99 133 else { 100 wayColor = getPreferencesColor("way", darkblue);134 wayColor = dfltWayColor; 101 135 for (Segment ls : w.segments) { 102 136 if (ls.incomplete) { 103 wayColor = getPreferencesColor("incompleteway", darkerblue);137 wayColor = incompleteColor; 104 138 break; 105 139 } … … 107 141 } 108 142 109 boolean showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");110 boolean showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");111 143 int orderNumber = 0; 112 144 for (Segment ls : w.segments) { 113 145 orderNumber++; 114 146 if (!ls.selected) // selected already in good color 115 drawSegment(ls, w.selected && !inactive ? getPreferencesColor("selected", Color.WHITE): wayColor, showDirectionArrow);147 drawSegment(ls, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow); 116 148 if (!ls.incomplete && showOrderNumber) 117 149 drawOrderNumber(ls, orderNumber); … … 132 164 if (screen.contains(x,y)) { 133 165 Color c = g.getColor(); 134 g.setColor( getPreferencesColor("background", Color.BLACK));166 g.setColor(backgroundColor); 135 167 g.fillRect(x-1, y-12, 8*strlen+1, 14); 136 168 g.setColor(c); … … 160 192 if (ls.incomplete) 161 193 return; 162 g.setColor(col); 194 if (col != currentColor) { 195 displaySegments(col); 196 } 197 163 198 Point p1 = nc.getPoint(ls.from.eastNorth); 164 199 Point p2 = nc.getPoint(ls.to.eastNorth); 165 200 166 Rectangle screen = g.getClipBounds(); 201 Rectangle screen = g.getClipBounds(); 167 202 Line2D line = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); 168 203 if (screen.contains(p1.x, p1.y, p2.x, p2.y) || screen.intersectsLine(line)) 169 204 { 170 g.drawLine(p1.x, p1.y, p2.x, p2.y); 205 currrentPath.moveTo(p1.x, p1.y); 206 currrentPath.lineTo(p2.x, p2.y); 171 207 172 208 if (showDirection) { 173 209 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 174 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 175 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 176 } 210 currrentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 211 currrentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 212 currrentPath.lineTo(p2.x, p2.y); } 213 } 214 } 215 216 protected void displaySegments(Color newColor) { 217 if (currrentPath != null) { 218 g.setColor(currentColor); 219 ((Graphics2D) g).draw(currrentPath); 220 currrentPath = new GeneralPath(); 221 currentColor = newColor; 177 222 } 178 223 }
Note:
See TracChangeset
for help on using the changeset viewer.