source: josm/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java@ 92

Last change on this file since 92 was 92, checked in by imi, 18 years ago
  • added progress bar and cancel button to all down-/uploads
  • added url loading via command line
  • added --selection=... loading of selections via command line
File size: 2.0 KB
Line 
1
2package org.openstreetmap.josm.data.osm.visitor;
3
4import java.util.HashSet;
5import java.util.Set;
6
7import javax.swing.Icon;
8
9import org.openstreetmap.josm.data.osm.Segment;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.tools.ImageProvider;
13
14/**
15 * Able to create a name and an icon for each data element.
16 *
17 * @author imi
18 */
19public class NameVisitor implements Visitor {
20
21 /**
22 * The name of the item class
23 */
24 public String className;
25 /**
26 * The name of this item.
27 */
28 public String name;
29 /**
30 * The icon of this item.
31 */
32 public Icon icon;
33
34
35 /**
36 * If the segment has a key named "name", its value is displayed.
37 * Otherwise, if it has "id", this is used. If none of these available,
38 * "(x1,y1) -> (x2,y2)" is displayed with the nodes coordinates.
39 */
40 public void visit(Segment ls) {
41 name = ls.get("name");
42 if (name == null) {
43 if (ls.incomplete)
44 name = ls.id == 0 ? "new" : ""+ls.id;
45 else
46 name = (ls.id==0?"":ls.id+" ")+"("+ls.from.coor.lat()+","+ls.from.coor.lon()+") -> ("+ls.to.coor.lat()+","+ls.to.coor.lon()+")";
47 }
48 icon = ImageProvider.get("data", "segment");
49 className = "segment";
50 }
51
52 /**
53 * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
54 * is displayed.
55 */
56 public void visit(Node n) {
57 name = n.get("name");
58 if (name == null)
59 name = (n.id==0?"":""+n.id)+" ("+n.coor.lat()+","+n.coor.lon()+")";
60 icon = ImageProvider.get("data", "node");
61 className = "node";
62 }
63
64 /**
65 * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
66 * is displayed with x beeing the number of nodes in the way.
67 */
68 public void visit(Way w) {
69 name = w.get("name");
70 if (name == null) {
71 AllNodesVisitor.getAllNodes(w.segments);
72 Set<Node> nodes = new HashSet<Node>();
73 for (Segment ls : w.segments) {
74 if (!ls.incomplete) {
75 nodes.add(ls.from);
76 nodes.add(ls.to);
77 }
78 }
79 name = "("+nodes.size()+" nodes)";
80 }
81 icon = ImageProvider.get("data", "way");
82 className = "way";
83 }
84}
Note: See TracBrowser for help on using the repository browser.