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

Last change on this file was 15668, checked in by Don-vip, 4 years ago

fix #18540 - use correct primitive icons in validator dialog

  • Property svn:eol-style set to native
File size: 2.3 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.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.data.osm.Way;
14import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
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 OsmPrimitiveVisitor {
23
24 /**
25 * The name of the item class
26 */
27 public String className;
28
29 /**
30 * The plural name of the item class
31 */
32 public String classNamePlural;
33
34 /**
35 * The name of this item.
36 */
37 public String name = "";
38
39 /**
40 * The icon of this item.
41 */
42 public Icon icon;
43
44 protected void setIcon(OsmPrimitive p) {
45 icon = ImageProvider.get(p.getDisplayType());
46 }
47
48 /**
49 * If the node has a name-key or id-key, this is displayed. If not, (lat,lon) is displayed.
50 */
51 @Override
52 public void visit(Node n) {
53 name = n.getDisplayName(DefaultNameFormatter.getInstance());
54 setIcon(n);
55 className = "node";
56 classNamePlural = trn("node", "nodes", 2);
57 }
58
59 /**
60 * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
61 * is displayed with x being the number of nodes in the way.
62 */
63 @Override
64 public void visit(Way w) {
65 name = w.getDisplayName(DefaultNameFormatter.getInstance());
66 setIcon(w);
67 className = "way";
68 classNamePlural = trn("way", "ways", 2);
69 }
70
71 @Override
72 public void visit(Relation e) {
73 name = e.getDisplayName(DefaultNameFormatter.getInstance());
74 setIcon(e);
75 className = "relation";
76 classNamePlural = trn("relation", "relations", 2);
77 }
78
79 /**
80 * Returns an horizontal {@code JLabel} with icon and name.
81 * @return horizontal {@code JLabel} with icon and name
82 */
83 public JLabel toLabel() {
84 return new JLabel(name, icon, JLabel.HORIZONTAL);
85 }
86}
Note: See TracBrowser for help on using the repository browser.