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.trn;
|
---|
5 |
|
---|
6 | import javax.swing.Icon;
|
---|
7 | import javax.swing.JLabel;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.osm.Node;
|
---|
10 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
11 | import org.openstreetmap.josm.data.osm.Way;
|
---|
12 | import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
|
---|
13 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
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 | //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
|
---|
22 | public 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 | }
|
---|