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

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

see #15182 - move NameFormatter* from gui to data.osm

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
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.DefaultNameFormatter;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.data.osm.Way;
13import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
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 */
21public class NameVisitor extends AbstractVisitor {
22
23 /**
24 * The name of the item class
25 */
26 public String className;
27
28 /**
29 * The plural name of the item class
30 */
31 public String classNamePlural;
32
33 /**
34 * The name of this item.
35 */
36 public String name = "";
37
38 /**
39 * The icon of this item.
40 */
41 public Icon icon;
42
43 /**
44 * If the node has a name-key or id-key, this is displayed. If not, (lat,lon) is displayed.
45 */
46 @Override
47 public void visit(Node n) {
48 name = n.getDisplayName(DefaultNameFormatter.getInstance());
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 icon = ImageProvider.get("data", "way");
62 className = "way";
63 classNamePlural = trn("way", "ways", 2);
64 }
65
66 @Override
67 public void visit(Relation e) {
68 name = e.getDisplayName(DefaultNameFormatter.getInstance());
69 icon = ImageProvider.get("data", "relation");
70 className = "relation";
71 classNamePlural = trn("relation", "relations", 2);
72 }
73
74 /**
75 * Returns an horizontal {@code JLabel} with icon and name.
76 * @return horizontal {@code JLabel} with icon and name
77 */
78 public JLabel toLabel() {
79 return new JLabel(name, icon, JLabel.HORIZONTAL);
80 }
81}
Note: See TracBrowser for help on using the repository browser.