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

Last change on this file since 804 was 756, checked in by stoecker, 16 years ago

i18n fix I overlooked

  • Property svn:eol-style set to native
File size: 1.9 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 javax.swing.Icon;
8import javax.swing.JLabel;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.osm.Node;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.Relation;
14import org.openstreetmap.josm.data.osm.Way;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * Able to create a name and an icon for each data element.
19 *
20 * @author imi
21 */
22public class NameVisitor implements Visitor {
23
24 /**
25 * The name of the item class
26 */
27 public String className;
28 public String classNamePlural;
29 /**
30 * The name of this item.
31 */
32 public String name;
33 /**
34 * The icon of this item.
35 */
36 public Icon icon;
37
38 /**
39 * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
40 * is displayed.
41 */
42 public void visit(Node n) {
43 name = n.getName();
44 addId(n);
45 icon = ImageProvider.get("data", "node");
46 className = "node";
47 classNamePlural = trn("node", "nodes", 2);
48 }
49
50 /**
51 * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
52 * is displayed with x being the number of nodes in the way.
53 */
54 public void visit(Way w) {
55 name = w.getName();
56 addId(w);
57 icon = ImageProvider.get("data", "way");
58 className = "way";
59 classNamePlural = trn("way", "ways", 2);
60 }
61
62 /**
63 */
64 public void visit(Relation e) {
65 name = e.getName();
66 addId(e);
67 icon = ImageProvider.get("data", "relation");
68 className = "relation";
69 classNamePlural = trn("relation", "relations", 2);
70 }
71
72 public JLabel toLabel() {
73 return new JLabel(name, icon, JLabel.HORIZONTAL);
74 }
75
76
77 private void addId(OsmPrimitive osm) {
78 if (Main.pref.getBoolean("osm-primitives.showid"))
79 name += tr(" [id: {0}]", osm.id);
80 }
81}
Note: See TracBrowser for help on using the repository browser.