Changeset 329 in josm for branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
- Timestamp:
- 2007-09-24T01:36:24+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r319 r329 4 4 import java.awt.Color; 5 5 import java.awt.Graphics; 6 import java.awt.Graphics2D;7 6 import java.awt.Point; 8 7 import java.awt.Rectangle; 9 import java.awt.geom.GeneralPath;10 8 import java.awt.geom.Line2D; 11 9 12 10 import org.openstreetmap.josm.Main; 13 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.Relation; 14 13 import org.openstreetmap.josm.data.osm.Node; 15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.Segment;17 15 import org.openstreetmap.josm.data.osm.Way; 18 16 import org.openstreetmap.josm.gui.NavigatableComponent; … … 30 28 public final static Color darkblue = new Color(0,0,128); 31 29 public final static Color darkgreen = new Color(0,128,0); 32 30 33 31 /** 34 32 * The environment to paint to. … … 41 39 42 40 public boolean inactive; 43 41 44 42 protected static final double PHI = Math.toRadians(20); 45 43 46 /**47 * Preferences48 */49 protected Color inactiveColor;50 protected Color selectedColor;51 protected Color nodeColor;52 protected Color segmentColor;53 protected Color dfltWayColor;54 protected Color incompleteColor;55 protected Color backgroundColor;56 protected boolean showDirectionArrow;57 protected boolean showOrderNumber;58 59 /**60 * Draw subsequent segments of same color as one Path61 */62 protected Color currentColor = null;63 protected GeneralPath currrentPath = new GeneralPath();64 65 44 public void visitAll(DataSet data) { 66 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY);67 selectedColor = getPreferencesColor("selected", Color.WHITE);68 nodeColor = getPreferencesColor("node", Color.RED);69 segmentColor = getPreferencesColor("segment", darkgreen);70 dfltWayColor = getPreferencesColor("way", darkblue);71 incompleteColor = getPreferencesColor("incomplete way", darkerblue);72 backgroundColor = getPreferencesColor("background", Color.BLACK);73 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");74 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");75 76 for (final OsmPrimitive osm : data.segments)77 if (!osm.deleted && !osm.selected)78 osm.visit(this);79 45 for (final OsmPrimitive osm : data.ways) 80 46 if (!osm.deleted && !osm.selected) 81 47 osm.visit(this); 82 displaySegments(null); // Flush segment cache before nodes83 48 for (final OsmPrimitive osm : data.nodes) 84 49 if (!osm.deleted && !osm.selected) … … 87 52 if (!osm.deleted) 88 53 osm.visit(this); 89 displaySegments(null);90 54 } 91 55 … … 99 63 Color color = null; 100 64 if (inactive) 101 color = inactiveColor;65 color = getPreferencesColor("inactive", Color.DARK_GRAY); 102 66 else if (n.selected) 103 color = selectedColor;67 color = getPreferencesColor("selected", Color.WHITE); 104 68 else 105 color = nodeColor;69 color = getPreferencesColor("node", Color.RED); 106 70 drawNode(n, color); 107 }108 109 /**110 * Draw just a line between the points.111 * White if selected (as always) or green otherwise.112 */113 public void visit(Segment ls) {114 Color color;115 if (inactive)116 color = inactiveColor;117 else if (ls.selected)118 color = selectedColor;119 else120 color = segmentColor;121 drawSegment(ls, color, showDirectionArrow);122 71 } 123 72 … … 129 78 Color wayColor; 130 79 if (inactive) 131 wayColor = inactiveColor;80 wayColor = getPreferencesColor("inactive", Color.DARK_GRAY); 132 81 else { 133 wayColor = dfltWayColor; 134 for (Segment ls : w.segments) { 135 if (ls.incomplete) { 136 wayColor = incompleteColor; 137 break; 138 } 139 } 82 wayColor = getPreferencesColor("way", darkblue); 140 83 } 141 84 85 boolean showDirectionArrow = Main.pref.getBoolean("draw.segment.direction"); 86 boolean showOrderNumber = Main.pref.getBoolean("draw.segment.order_number"); 142 87 int orderNumber = 0; 143 for (Segment ls : w.segments) { 88 Node lastN = null; 89 for (Node n : w.nodes) { 90 if (lastN == null) { 91 lastN = n; 92 continue; 93 } 144 94 orderNumber++; 145 if (!ls.selected) // selected already in good color146 drawSegment(ls, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow);147 if (!ls.incomplete && showOrderNumber)148 drawOrderNumber(ls, orderNumber);95 drawSegment(lastN, n, w.selected && !inactive ? getPreferencesColor("selected", Color.WHITE) : wayColor, showDirectionArrow); 96 if (showOrderNumber) 97 drawOrderNumber(lastN, n, orderNumber); 98 lastN = n; 149 99 } 150 100 } 151 101 102 public void visit(Relation e) { 103 // relations are not drawn. 104 } 152 105 /** 153 * Draw an number of the order of the segment within the parents way 106 * Draw an number of the order of the two consecutive nodes within the 107 * parents way 154 108 */ 155 protected void drawOrderNumber( Segment ls, int orderNumber) {109 protected void drawOrderNumber(Node n1, Node n2, int orderNumber) { 156 110 int strlen = (""+orderNumber).length(); 157 Point p1 = nc.getPoint( ls.from.eastNorth);158 Point p2 = nc.getPoint( ls.to.eastNorth);111 Point p1 = nc.getPoint(n1.eastNorth); 112 Point p2 = nc.getPoint(n2.eastNorth); 159 113 int x = (p1.x+p2.x)/2 - 4*strlen; 160 114 int y = (p1.y+p2.y)/2 + 4; … … 163 117 if (screen.contains(x,y)) { 164 118 Color c = g.getColor(); 165 g.setColor( backgroundColor);119 g.setColor(getPreferencesColor("background", Color.BLACK)); 166 120 g.fillRect(x-1, y-12, 8*strlen+1, 14); 167 121 g.setColor(c); … … 188 142 * Draw a line with the given color. 189 143 */ 190 protected void drawSegment(Segment ls, Color col, boolean showDirection) { 191 if (ls.incomplete) 192 return; 193 if (col != currentColor) { 194 displaySegments(col); 195 } 144 protected void drawSegment(Node n1, Node n2, Color col, boolean showDirection) { 145 g.setColor(col); 146 Point p1 = nc.getPoint(n1.eastNorth); 147 Point p2 = nc.getPoint(n2.eastNorth); 196 148 197 Point p1 = nc.getPoint(ls.from.eastNorth); 198 Point p2 = nc.getPoint(ls.to.eastNorth); 199 200 Rectangle screen = g.getClipBounds(); 149 Rectangle screen = g.getClipBounds(); 201 150 Line2D line = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); 202 151 if (screen.contains(p1.x, p1.y, p2.x, p2.y) || screen.intersectsLine(line)) 203 152 { 204 currrentPath.moveTo(p1.x, p1.y); 205 currrentPath.lineTo(p2.x, p2.y); 153 g.drawLine(p1.x, p1.y, p2.x, p2.y); 206 154 207 155 if (showDirection) { 208 156 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 209 currrentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 210 currrentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 211 currrentPath.lineTo(p2.x, p2.y); } 212 } 213 } 214 215 protected void displaySegments(Color newColor) { 216 if (currrentPath != null) { 217 g.setColor(currentColor); 218 ((Graphics2D) g).draw(currrentPath); 219 currrentPath = new GeneralPath(); 220 currentColor = newColor; 157 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 158 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 159 } 221 160 } 222 161 }
Note:
See TracChangeset
for help on using the changeset viewer.