source: josm/trunk/src/org/openstreetmap/josm/data/validation/util/NameVisitor.java@ 3775

Last change on this file since 3775 was 3671, checked in by bastiK, 13 years ago

adapt coding style (to some degree); there shouldn't be any semantic changes in this commit

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.data.validation.util;
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.data.osm.visitor.AbstractVisitor;
16import org.openstreetmap.josm.gui.DefaultNameFormatter;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Able to create a name and an icon for each data element.
21 *
22 * @author imi
23 */
24//TODO This class used to be in JOSM but it was removed. MultipleNameVisitor depends on it so I copied it here, but MultipleNameVisitor should be refactored instead of using this class
25public class NameVisitor extends AbstractVisitor {
26
27 /**
28 * The name of the item class
29 */
30 public String className;
31 public String classNamePlural;
32 /**
33 * The name of this item.
34 */
35 public String name;
36 /**
37 * The icon of this item.
38 */
39 public Icon icon;
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 @Override
46 public void visit(Node n) {
47 name = n.getDisplayName(DefaultNameFormatter.getInstance());
48 addId(n);
49 icon = ImageProvider.get("data", "node");
50 className = "node";
51 classNamePlural = trn("node", "nodes", 2);
52 }
53
54 /**
55 * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
56 * is displayed with x being the number of nodes in the way.
57 */
58 @Override
59 public void visit(Way w) {
60 name = w.getDisplayName(DefaultNameFormatter.getInstance());
61 addId(w);
62 icon = ImageProvider.get("data", "way");
63 className = "way";
64 classNamePlural = trn("way", "ways", 2);
65 }
66
67 /**
68 */
69 @Override
70 public void visit(Relation e) {
71 name = e.getDisplayName(DefaultNameFormatter.getInstance());
72 addId(e);
73 icon = ImageProvider.get("data", "relation");
74 className = "relation";
75 classNamePlural = trn("relation", "relations", 2);
76 }
77
78 public JLabel toLabel() {
79 return new JLabel(name, icon, JLabel.HORIZONTAL);
80 }
81
82 private void addId(OsmPrimitive osm) {
83 if (Main.pref.getBoolean("osm-primitives.showid")) {
84 name += tr(" [id: {0}]", osm.getId());
85 }
86 }
87}
Note: See TracBrowser for help on using the repository browser.