source: josm/branch/0.5/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java@ 329

Last change on this file since 329 was 329, checked in by framm, 17 years ago

This commit is a manual merge of all changes that have been made to
the intermediate "core_0.5" branch on the main OSM repository,
bevore JOSM was moved to openstreetmap.de.

Changes incorporated here:

r4464@svn.openstreetmap.org
r4466@svn.openstreetmap.org
r4468@svn.openstreetmap.org
r4469@svn.openstreetmap.org
r4479@svn.openstreetmap.org

File size: 2.4 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm.visitor;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.util.HashSet;
8import java.util.Set;
9
10import javax.swing.Icon;
11import javax.swing.JLabel;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.osm.Relation;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20/**
21 * Able to create a name and an icon for each data element.
22 *
23 * @author imi
24 */
25public class NameVisitor implements Visitor {
26
27 /**
28 * The name of the item class
29 */
30 public String className;
31 /**
32 * The name of this item.
33 */
34 public String name;
35 /**
36 * The icon of this item.
37 */
38 public Icon icon;
39
40
41 /**
42 * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
43 * is displayed.
44 */
45 public void visit(Node n) {
46 name = n.get("name");
47 if (name == null)
48 name = (n.id==0?"":""+n.id)+" ("+n.coor.lat()+","+n.coor.lon()+")";
49 addId(n);
50 icon = ImageProvider.get("data", "node");
51 trn("node", "nodes", 0); // no marktrn available
52 className = "node";
53 }
54
55 /**
56 * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
57 * is displayed with x being the number of nodes in the way.
58 */
59 public void visit(Way w) {
60 name = w.get("name");
61 if (name == null) name = w.get("ref");
62 if (name == null) {
63 String what = (w.get("highway") != null) ? "highway " : (w.get("railway") != null) ? "railway " : (w.get("waterway") != null) ? "waterway " : "";
64 name = what + trn("{0} node", "{0} nodes", w.nodes.size(), w.nodes.size());
65 }
66 addId(w);
67 icon = ImageProvider.get("data", "way");
68 trn("way", "ways", 0); // no marktrn available
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";
83 }
84
85 public JLabel toLabel() {
86 return new JLabel(name, icon, JLabel.HORIZONTAL);
87 }
88
89
90 private void addId(OsmPrimitive osm) {
91 if (Main.pref.getBoolean("osm-primitives.showid"))
92 name += " (id: "+osm.id+")";
93 }
94}
Note: See TracBrowser for help on using the repository browser.