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

Last change on this file since 5118 was 5118, checked in by Don-vip, 12 years ago

fix #7534 - ID# shown twice in pre-upload Validation window

  • Property svn:eol-style set to native
File size: 2.2 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.trn;
5
6import javax.swing.Icon;
7import javax.swing.JLabel;
8
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.Relation;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
13import org.openstreetmap.josm.gui.DefaultNameFormatter;
14import org.openstreetmap.josm.tools.ImageProvider;
15
16/**
17 * Able to create a name and an icon for each data element.
18 *
19 * @author imi
20 */
21//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
22public class NameVisitor extends AbstractVisitor {
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 @Override
43 public void visit(Node n) {
44 name = n.getDisplayName(DefaultNameFormatter.getInstance());
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 @Override
55 public void visit(Way w) {
56 name = w.getDisplayName(DefaultNameFormatter.getInstance());
57 icon = ImageProvider.get("data", "way");
58 className = "way";
59 classNamePlural = trn("way", "ways", 2);
60 }
61
62 /**
63 */
64 @Override
65 public void visit(Relation e) {
66 name = e.getDisplayName(DefaultNameFormatter.getInstance());
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}
Note: See TracBrowser for help on using the repository browser.