Changeset 343 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor
- Timestamp:
- 2007-10-07T13:20:27+02:00 (18 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java
r298 r343 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 /**3 */4 2 package org.openstreetmap.josm.data.osm.visitor; 5 3 6 4 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm. Segment;5 import org.openstreetmap.josm.data.osm.Relation; 8 6 import org.openstreetmap.josm.data.osm.Node; 9 7 import org.openstreetmap.josm.data.osm.Way; … … 27 25 ds.nodes.add(n); 28 26 } 29 public void visit(Segment s) {30 ds.segments.add(s);31 }32 27 public void visit(Way w) { 33 28 ds.ways.add(w); 34 29 } 30 public void visit(Relation e) { 31 ds.relations.add(e); 32 } 35 33 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java
r298 r343 5 5 import java.util.HashSet; 6 6 7 import org.openstreetmap.josm.data.osm.Segment; 7 import org.openstreetmap.josm.data.osm.Relation; 8 import org.openstreetmap.josm.data.osm.RelationMember; 8 9 import org.openstreetmap.josm.data.osm.Node; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 30 31 31 32 /** 32 * Line segments haveexactly two nodes: from and to.33 * Ways have their way nodes. 33 34 */ 34 public void visit(Segment ls) { 35 if (!ls.incomplete) { 36 visit(ls.from); 37 visit(ls.to); 38 } 35 public void visit(Way w) { 36 for (Node n : w.nodes) 37 visit(n); 39 38 } 40 39 41 40 /** 42 * Ways have all nodes from their segments. 41 * Relations may have any number of nodes. 42 * FIXME: do we want to collect nodes from segs/ways that are relation members? 43 * if so, use AutomatchVisitor! 43 44 */ 44 public void visit( Way w) {45 for ( Segment ls : w.segments)46 visit(ls);45 public void visit(Relation e) { 46 for (RelationMember m : e.members) 47 if (m.member instanceof Node) visit((Node)m.member); 47 48 } 48 49 49 /** 50 50 * @return All nodes the given primitive has. -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r298 r343 5 5 import org.openstreetmap.josm.data.Bounds; 6 6 import org.openstreetmap.josm.data.coor.EastNorth; 7 import org.openstreetmap.josm.data.osm. Segment;7 import org.openstreetmap.josm.data.osm.Relation; 8 8 import org.openstreetmap.josm.data.osm.Node; 9 9 import org.openstreetmap.josm.data.osm.Way; … … 22 22 } 23 23 24 public void visit(Segment ls) { 25 if (!ls.incomplete) { 26 visit(ls.from); 27 visit(ls.to); 28 } 24 public void visit(Way w) { 25 for (Node n : w.nodes) 26 visit(n); 29 27 } 30 28 31 public void visit(Way w) { 32 for (Segment ls : w.segments) 33 visit(ls); 29 public void visit(Relation e) { 30 // relations have no bounding box. 34 31 } 35 32 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r298 r343 6 6 7 7 import org.openstreetmap.josm.data.osm.DataSet; 8 import org.openstreetmap.josm.data.osm.Segment; 8 import org.openstreetmap.josm.data.osm.Relation; 9 import org.openstreetmap.josm.data.osm.RelationMember; 9 10 import org.openstreetmap.josm.data.osm.Node; 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 12 13 13 14 /** 14 * Helper that collect all segments a node is part of, all ways 15 * a node or segment is part of and all areas a node is part of. 15 * Helper that collect all ways a node is part of. 16 16 * 17 17 * Deleted objects are not collected. … … 41 41 if (w.deleted) 42 42 continue; 43 for (Segment ls : w.segments) { 44 if (ls.incomplete) 45 continue; 46 if (ls.from == n || ls.to == n) { 43 for (Node n2 : w.nodes) { 44 if (n == n2) { 47 45 data.add(w); 46 } 47 } 48 } 49 checkRelationMembership(n); 50 } 51 52 public void visit(Way w) { 53 checkRelationMembership(w); 54 } 55 56 public void visit(Relation r) { 57 checkRelationMembership(r); 58 } 59 60 private void checkRelationMembership(OsmPrimitive p) { 61 // FIXME - this might be a candidate for optimisation 62 // if OSM primitives are made to hold a list of back 63 // references. 64 for (Relation r : ds.relations) { 65 for (RelationMember m : r.members) { 66 if (m.member == p) { 67 data.add(r); 68 // move up the tree (there might be relations 69 // referring to this relation) 70 checkRelationMembership(r); 48 71 break; 49 72 } 50 73 } 51 74 } 52 for (Segment ls : ds.segments) {53 if (ls.deleted || ls.incomplete)54 continue;55 if (ls.from == n || ls.to == n)56 data.add(ls);57 }58 75 } 59 public void visit(Segment ls) {60 for (Way w : ds.ways) {61 if (w.deleted)62 continue;63 if (w.segments.contains(ls))64 data.add(w);65 }66 }67 public void visit(Way w) {}68 76 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java
r298 r343 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 /**3 */4 2 package org.openstreetmap.josm.data.osm.visitor; 5 3 6 4 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm. Segment;5 import org.openstreetmap.josm.data.osm.Relation; 8 6 import org.openstreetmap.josm.data.osm.Node; 9 7 import org.openstreetmap.josm.data.osm.Way; … … 27 25 ds.nodes.remove(n); 28 26 } 29 public void visit(Segment ls) {30 ds.segments.remove(ls);31 }32 27 public void visit(Way w) { 33 28 ds.ways.remove(w); 34 29 } 30 public void visit(Relation e) { 31 ds.relations.remove(e); 32 } 35 33 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r298 r343 10 10 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.Relation; 13 import org.openstreetmap.josm.data.osm.RelationMember; 12 14 import org.openstreetmap.josm.data.osm.Node; 13 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.Segment;15 16 import org.openstreetmap.josm.data.osm.Way; 16 17 … … 25 26 /** 26 27 * Map from primitives in the database to visited primitives. (Attention: The other way 27 * round than mergedNodes and mergedSegments)28 * round than mergedNodes) 28 29 */ 29 30 public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>(); … … 38 39 */ 39 40 private final Map<Node, Node> mergedNodes = new HashMap<Node, Node>(); 40 /**41 * A list of all segments that got replaced with others.42 * Key is the segment in the other's dataset and the value is the one that is now43 * in ds.segments.44 */45 private final Map<Segment, Segment> mergedSegments = new HashMap<Segment, Segment>();46 41 47 42 public MergeVisitor(DataSet ds, DataSet mergeds) { … … 81 76 82 77 /** 83 * Merge the segment if id matches or if both nodes are the same (and the 84 * id is zero of either segment). Nodes are the "same" when they @see match 85 */ 86 public void visit(Segment other) { 87 if (mergeAfterId(mergedSegments, ds.segments, other)) 88 return; 89 90 Segment my = null; 91 for (Segment ls : ds.segments) { 92 if (match(other, ls) && ((mergeds == null) || (!mergeds.segments.contains(ls)))) { 93 my = ls; 94 break; 95 } 96 } 97 98 if (my == null) 99 ds.segments.add(other); 100 else if (my.incomplete && !other.incomplete) { 101 mergedSegments.put(other, my); 102 my.cloneFrom(other); 103 } else if (!other.incomplete) { 104 mergedSegments.put(other, my); 105 mergeCommon(my, other); 106 if (my.modified && !other.modified) 107 return; 108 if (!match(my.from, other.from)) { 109 my.from = other.from; 110 my.modified = other.modified; 111 } 112 if (!match(my.to, other.to)) { 113 my.to = other.to; 114 my.modified = other.modified; 115 } 116 } 117 } 118 78 * Simply calls cloneFrom() for now. 79 * Might be useful to keep around to facilitate merge with the relations 80 * branch. 81 */ 119 82 private <T extends OsmPrimitive> void cloneFromExceptIncomplete(T myOsm, T otherOsm) { 120 if (!(myOsm instanceof Way)) 121 myOsm.cloneFrom(otherOsm); 122 else { 123 Way my = (Way)myOsm; 124 Way other = (Way)otherOsm; 125 HashMap<Long, Segment> copy = new HashMap<Long, Segment>(); 126 for (Segment s : my.segments) 127 copy.put(s.id, s); 128 my.cloneFrom(other); 129 my.segments.clear(); 130 for (Segment s : other.segments) { 131 Segment myS = copy.get(s.id); 132 if (s.incomplete && myS != null && !myS.incomplete) { 133 mergedSegments.put(s, myS); 134 my.segments.add(myS); 135 } else 136 my.segments.add(s); 137 } 138 } 83 myOsm.cloneFrom(otherOsm); 139 84 } 140 85 141 86 /** 142 * Merge the way if id matches or if all segments matchesand the87 * Merge the way if id matches or if all nodes match and the 143 88 * id is zero of either way. 144 89 */ … … 155 100 } 156 101 if (my == null) { 157 // Add the way and replace any incomplete segments that we already have158 102 ds.ways.add(other); 159 for (Segment s : other.segments) { 160 if (s.incomplete) { 103 } else { 104 mergeCommon(my, other); 105 if (my.modified && !other.modified) 106 return; 107 boolean same = true; 108 Iterator<Node> it = other.nodes.iterator(); 109 for (Node n : my.nodes) { 110 if (!match(n, it.next())) 111 same = false; 112 } 113 if (!same) { 114 my.nodes.clear(); 115 my.nodes.addAll(other.nodes); 116 my.modified = other.modified; 117 } 118 } 119 } 120 121 /** 122 * Merge the relation if id matches or if all members match and the 123 * id of either relation is zero. 124 */ 125 public void visit(Relation other) { 126 if (mergeAfterId(null, ds.relations, other)) 127 return; 128 129 Relation my = null; 130 for (Relation e : ds.relations) { 131 if (match(other, e) && ((mergeds == null) || (!mergeds.relations.contains(e)))) { 132 my = e; 133 break; 134 } 135 } 136 137 if (my == null) { 138 // Add the relation and replace any incomplete segments that we already have 139 ds.relations.add(other); 140 // FIXME unclear! 141 /* 142 for (RelationMember em : other.getMembers()) { 143 if (em.member.incomplete) { 161 144 for (Segment ourSegment : ds.segments) { 162 145 if (ourSegment.id == s.id) { … … 166 149 } 167 150 } 168 } 151 }*/ 169 152 } else { 170 153 mergeCommon(my, other); … … 172 155 return; 173 156 boolean same = true; 174 Iterator<Segment> it = other.segments.iterator(); 175 for (Segment ls : my.segments) { 176 if (!match(ls, it.next())) 157 if (other.members.size() != my.members.size()) { 177 158 same = false; 178 } 159 } else { 160 for (RelationMember em : my.members) { 161 if (!other.members.contains(em)) { 162 same = false; 163 break; 164 } 165 } 166 } 167 // FIXME Unclear 168 /* 179 169 if (!same) { 180 170 HashMap<Long, Segment> copy = new HashMap<Long, Segment>(); … … 192 182 my.modified = other.modified; 193 183 } 184 */ 194 185 } 195 186 } … … 200 191 */ 201 192 public void fixReferences() { 202 for (Segment s : ds.segments)203 fixSegment(s);204 for (OsmPrimitive osm : conflicts.values())205 if (osm instanceof Segment)206 fixSegment((Segment)osm);207 193 for (Way w : ds.ways) 208 194 fixWay(w); … … 214 200 private void fixWay(Way w) { 215 201 boolean replacedSomething = false; 216 LinkedList< Segment> newSegments = new LinkedList<Segment>();217 for ( Segment ls : w.segments) {218 Segment otherLs= mergedSegments.get(ls);219 new Segments.add(otherLs== null ?ls: otherLs);220 if (other Ls!= null)202 LinkedList<Node> newNodes = new LinkedList<Node>(); 203 for (Node n : w.nodes) { 204 Node otherN = mergedNodes.get(n); 205 newNodes.add(otherN == null ? n : otherN); 206 if (otherN != null) 221 207 replacedSomething = true; 222 208 } 223 209 if (replacedSomething) { 224 w.segments.clear(); 225 w.segments.addAll(newSegments); 226 } 227 for (Segment ls : w.segments) 228 fixSegment(ls); 210 w.nodes.clear(); 211 w.nodes.addAll(newNodes); 229 212 } 230 231 private void fixSegment(Segment ls) {232 233 if (mergedNodes.containsKey(ls.from))234 ls.from = mergedNodes.get(ls.from);235 236 if (mergedNodes.containsKey(ls.to))237 ls.to = mergedNodes.get(ls.to);238 239 213 } 240 214 241 215 /** 242 * @return Whether the nodes match es(in sense of "be mergable").216 * @return Whether the nodes match (in sense of "be mergable"). 243 217 */ 244 218 private boolean match(Node n1, Node n2) { … … 249 223 250 224 /** 251 * @return Whether the segments matches (in sense of "be mergable"). 252 */ 253 private boolean match(Segment ls1, Segment ls2) { 254 if (ls1.id == ls2.id && ls1.id != 0) 255 return true; 256 //if (ls1.id != 0 && ls2.id != 0) 257 // return false; 258 if (ls1.incomplete || ls2.incomplete) 259 return false; 260 return match(ls1.from, ls2.from) && match(ls1.to, ls2.to); 261 } 262 263 /** 264 * @return Whether the ways matches (in sense of "be mergable"). 225 * @return Whether the ways match (in sense of "be mergable"). 265 226 */ 266 227 private boolean match(Way w1, Way w2) { 267 228 if (w1.id == 0 || w2.id == 0) { 268 if (w1. segments.size() != w2.segments.size())269 270 Iterator< Segment> it = w1.segments.iterator();271 for ( Segment ls : w2.segments)272 if (!match( ls, it.next()))229 if (w1.nodes.size() != w2.nodes.size()) 230 return false; 231 Iterator<Node> it = w1.nodes.iterator(); 232 for (Node n : w2.nodes) 233 if (!match(n, it.next())) 273 234 return false; 274 235 return true; … … 276 237 return w1.id == w2.id; 277 238 } 239 /** 240 * @return Whether the relations match (in sense of "be mergable"). 241 */ 242 private boolean match(Relation w1, Relation w2) { 243 // FIXME this is not perfect yet... 244 if (w1.id == 0 || w2.id == 0) { 245 if (w1.members.size() != w2.members.size()) 246 return false; 247 for (RelationMember em : w1.members) { 248 if (!w2.members.contains(em)) { 249 return false; 250 } 251 } 252 return true; 253 } 254 return w1.id == w2.id; 255 } 256 278 257 279 258 /** … … 327 306 } 328 307 if (my.id == other.id && my.id != 0) { 329 if (my instanceof Segment && ((Segment)my).incomplete)330 return false; // merge always over an incomplete331 308 if (my.modified && other.modified) { 332 309 conflicts.put(my, other); -
trunk/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java
r298 r343 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 3 2 package org.openstreetmap.josm.data.osm.visitor; 4 3 … … 13 12 14 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.osm.Relation; 15 15 import org.openstreetmap.josm.data.osm.Node; 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Segment;18 17 import org.openstreetmap.josm.data.osm.Way; 19 18 import org.openstreetmap.josm.tools.ImageProvider; … … 41 40 42 41 /** 43 * If the segment has a key named "name", its value is displayed.44 * Otherwise, if it has "id", this is used. If none of these available,45 * "(x1,y1) -> (x2,y2)" is displayed with the nodes coordinates.46 */47 public void visit(Segment ls) {48 name = ls.get("name");49 if (name == null) {50 if (ls.incomplete)51 name = ls.id == 0 ? tr("new") : ls.id+" ("+tr("unknown")+")";52 else53 name = (ls.id==0?"":ls.id+" ")+"("+ls.from.coor.lat()+","+ls.from.coor.lon()+") -> ("+ls.to.coor.lat()+","+ls.to.coor.lon()+")";54 }55 addId(ls);56 icon = ImageProvider.get("data", "segment");57 trn("segment", "segments", 0); // no marktrn available58 className = "segment";59 }60 61 /**62 42 * If the node has a name-key or id-key, this is displayed. If not, (lat,lon) 63 43 * is displayed. … … 81 61 if (name == null) name = w.get("ref"); 82 62 if (name == null) { 83 AllNodesVisitor.getAllNodes(w.segments);84 Set<Node> nodes = new HashSet<Node>();85 for (Segment ls : w.segments) {86 if (!ls.incomplete) {87 nodes.add(ls.from);88 nodes.add(ls.to);89 }90 }91 63 String what = (w.get("highway") != null) ? "highway " : (w.get("railway") != null) ? "railway " : (w.get("waterway") != null) ? "waterway " : ""; 92 name = what + trn("{0} node", "{0} nodes", nodes.size(), nodes.size()); 64 name = what + trn("{0} node", "{0} nodes", w.nodes.size(), w.nodes.size()); 93 65 } 94 if (w.isIncomplete())95 name += " ("+tr("incomplete")+")";96 66 addId(w); 97 67 icon = ImageProvider.get("data", "way"); 98 68 trn("way", "ways", 0); // no marktrn available 99 69 className = "way"; 70 } 71 72 /** 73 */ 74 public void visit(Relation e) { 75 name = e.get("type"); 76 // FIXME add names of members 77 if (name == null) 78 name = "relation"; 79 addId(e); 80 icon = ImageProvider.get("data", "relation"); 81 trn("relation", "relations", 0); // no marktrn available 82 className = "relation"; 100 83 } 101 84 -
trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r319 r343 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.osm.Relation; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.Segment;17 17 import org.openstreetmap.josm.data.osm.Way; 18 18 import org.openstreetmap.josm.gui.NavigatableComponent; … … 30 30 public final static Color darkblue = new Color(0,0,128); 31 31 public final static Color darkgreen = new Color(0,128,0); 32 32 33 33 /** 34 34 * The environment to paint to. … … 41 41 42 42 public boolean inactive; 43 43 44 44 protected static final double PHI = Math.toRadians(20); 45 45 46 46 /** 47 47 * Preferences 48 48 */ 49 49 protected Color inactiveColor; 50 50 protected Color selectedColor; 51 51 protected Color nodeColor; 52 protected Color segmentColor;53 52 protected Color dfltWayColor; 54 53 protected Color incompleteColor; … … 61 60 */ 62 61 protected Color currentColor = null; 63 protected GeneralPath curr rentPath = new GeneralPath();64 62 protected GeneralPath currentPath = new GeneralPath(); 63 65 64 public void visitAll(DataSet data) { 65 66 66 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY); 67 67 selectedColor = getPreferencesColor("selected", Color.WHITE); 68 68 nodeColor = getPreferencesColor("node", Color.RED); 69 segmentColor = getPreferencesColor("segment", darkgreen);70 69 dfltWayColor = getPreferencesColor("way", darkblue); 71 70 incompleteColor = getPreferencesColor("incomplete way", darkerblue); … … 74 73 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number"); 75 74 76 for (final OsmPrimitive osm : data.segments)77 if (!osm.deleted && !osm.selected)78 osm.visit(this);79 75 for (final OsmPrimitive osm : data.ways) 80 76 if (!osm.deleted && !osm.selected) 81 77 osm.visit(this); 82 displaySegments(null); // Flush segment cache before nodes78 displaySegments(null); 83 79 for (final OsmPrimitive osm : data.nodes) 84 80 if (!osm.deleted && !osm.selected) … … 108 104 109 105 /** 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 }123 124 /**125 106 * Draw a darkblue line for all segments. 126 107 * @param w The way to draw. … … 132 113 else { 133 114 wayColor = dfltWayColor; 134 for (Segment ls : w.segments) { 135 if (ls.incomplete) { 136 wayColor = incompleteColor; 137 break; 138 } 115 } 116 117 int orderNumber = 0; 118 Node lastN = null; 119 for (Node n : w.nodes) { 120 if (lastN == null) { 121 lastN = n; 122 continue; 139 123 } 140 }141 142 int orderNumber = 0;143 for (Segment ls : w.segments) {144 124 orderNumber++; 145 if (!ls.selected) // selected already in good color 146 drawSegment(ls, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow); 147 if (!ls.incomplete && showOrderNumber) 148 drawOrderNumber(ls, orderNumber); 149 } 150 } 151 152 /** 153 * Draw an number of the order of the segment within the parents way 154 */ 155 protected void drawOrderNumber(Segment ls, int orderNumber) { 125 drawSegment(lastN, n, w.selected && !inactive ? selectedColor : wayColor, showDirectionArrow); 126 if (showOrderNumber) 127 drawOrderNumber(lastN, n, orderNumber); 128 lastN = n; 129 } 130 } 131 132 public void visit(Relation e) { 133 // relations are not (yet?) drawn. 134 } 135 136 /** 137 * Draw an number of the order of the two consecutive nodes within the 138 * parents way 139 */ 140 protected void drawOrderNumber(Node n1, Node n2, int orderNumber) { 156 141 int strlen = (""+orderNumber).length(); 157 Point p1 = nc.getPoint( ls.from.eastNorth);158 Point p2 = nc.getPoint( ls.to.eastNorth);142 Point p1 = nc.getPoint(n1.eastNorth); 143 Point p2 = nc.getPoint(n2.eastNorth); 159 144 int x = (p1.x+p2.x)/2 - 4*strlen; 160 145 int y = (p1.y+p2.y)/2 + 4; … … 181 166 Rectangle screen = g.getClipBounds(); 182 167 183 if ( 168 if (screen.contains(p.x, p.y)) 184 169 g.drawRect(p.x-1, p.y-1, 2, 2); 185 170 } … … 188 173 * Draw a line with the given color. 189 174 */ 190 protected void drawSegment(Segment ls, Color col, boolean showDirection) { 191 if (ls.incomplete) 192 return; 175 protected void drawSegment(Node n1, Node n2, Color col, boolean showDirection) { 176 193 177 if (col != currentColor) { 194 178 displaySegments(col); 195 179 } 196 180 197 Point p1 = nc.getPoint( ls.from.eastNorth);198 Point p2 = nc.getPoint( ls.to.eastNorth);199 200 Rectangle screen = g.getClipBounds(); 181 Point p1 = nc.getPoint(n1.eastNorth); 182 Point p2 = nc.getPoint(n2.eastNorth); 183 184 Rectangle screen = g.getClipBounds(); 201 185 Line2D line = new Line2D.Double(p1.x, p1.y, p2.x, p2.y); 202 186 if (screen.contains(p1.x, p1.y, p2.x, p2.y) || screen.intersectsLine(line)) 203 187 { 204 curr rentPath.moveTo(p1.x, p1.y);205 curr rentPath.lineTo(p2.x, p2.y);206 188 currentPath.moveTo(p1.x, p1.y); 189 currentPath.lineTo(p2.x, p2.y); 190 207 191 if (showDirection) { 208 192 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; 193 currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 194 currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 195 currentPath.lineTo(p2.x, p2.y); 196 } 221 197 } 222 198 } … … 230 206 return ColorHelper.html2color(colStr); 231 207 } 232 233 208 234 209 public void setGraphics(Graphics g) { 235 210 this.g = g; … … 239 214 this.nc = nc; 240 215 } 216 217 protected void displaySegments(Color newColor) { 218 if (currentPath != null) { 219 g.setColor(currentColor); 220 ((Graphics2D) g).draw(currentPath); 221 currentPath = new GeneralPath(); 222 currentColor = newColor; 223 } 224 } 241 225 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/Visitor.java
r298 r343 2 2 package org.openstreetmap.josm.data.osm.visitor; 3 3 4 import org.openstreetmap.josm.data.osm.Relation; 4 5 import org.openstreetmap.josm.data.osm.Node; 5 import org.openstreetmap.josm.data.osm.Segment;6 6 import org.openstreetmap.josm.data.osm.Way; 7 7 … … 14 14 public interface Visitor { 15 15 void visit(Node n); 16 void visit(Segment s);17 16 void visit(Way w); 17 void visit(Relation e); 18 18 }
Note:
See TracChangeset
for help on using the changeset viewer.