1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.util;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
5 |
|
---|
6 | import javax.swing.Icon;
|
---|
7 | import javax.swing.JLabel;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
|
---|
10 | import org.openstreetmap.josm.data.osm.Node;
|
---|
11 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
12 | import org.openstreetmap.josm.data.osm.Way;
|
---|
13 | import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
|
---|
14 | import 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 | public 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 | }
|
---|