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