1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging.presets;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
5 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Enumeration of OSM primitive types associated with names and icons
|
---|
9 | * @since 6068
|
---|
10 | */
|
---|
11 | public enum TaggingPresetType {
|
---|
12 | /** Node */
|
---|
13 | NODE(/* ICON */ "Mf_node", "node"),
|
---|
14 | /** Way */
|
---|
15 | WAY(/* ICON */ "Mf_way", "way"),
|
---|
16 | /** Relation */
|
---|
17 | RELATION(/* ICON */ "Mf_relation", "relation"),
|
---|
18 | /** Closed way */
|
---|
19 | CLOSEDWAY(/* ICON */ "Mf_closedway", "closedway");
|
---|
20 | private final String iconName;
|
---|
21 | private final String name;
|
---|
22 |
|
---|
23 | TaggingPresetType(String iconName, String name) {
|
---|
24 | this.iconName = iconName + ".svg";
|
---|
25 | this.name = name;
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Replies the SVG icon name.
|
---|
30 | * @return the SVG icon name
|
---|
31 | */
|
---|
32 | public String getIconName() {
|
---|
33 | return iconName;
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Replies the name, as used in XML presets.
|
---|
38 | * @return the name: "node", "way", "relation" or "closedway"
|
---|
39 | */
|
---|
40 | public String getName() {
|
---|
41 | return name;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Determines the {@code TaggingPresetType} of a given primitive.
|
---|
46 | * @param p The OSM primitive
|
---|
47 | * @return the {@code TaggingPresetType} of {@code p}
|
---|
48 | */
|
---|
49 | public static TaggingPresetType forPrimitive(OsmPrimitive p) {
|
---|
50 | return forPrimitiveType(p.getDisplayType());
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Determines the {@code TaggingPresetType} of a given primitive type.
|
---|
55 | * @param type The OSM primitive type
|
---|
56 | * @return the {@code TaggingPresetType} of {@code type}
|
---|
57 | */
|
---|
58 | public static TaggingPresetType forPrimitiveType(OsmPrimitiveType type) {
|
---|
59 | if (type == OsmPrimitiveType.NODE) return NODE;
|
---|
60 | if (type == OsmPrimitiveType.WAY) return WAY;
|
---|
61 | if (type == OsmPrimitiveType.CLOSEDWAY) return CLOSEDWAY;
|
---|
62 | if (type == OsmPrimitiveType.RELATION || type == OsmPrimitiveType.MULTIPOLYGON)
|
---|
63 | return RELATION;
|
---|
64 | throw new IllegalArgumentException("Unexpected primitive type: " + type);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Determines the {@code TaggingPresetType} from a given string.
|
---|
69 | * @param type The OSM primitive type as string ("node", "way", "relation" or "closedway")
|
---|
70 | * @return the {@code TaggingPresetType} from {@code type}
|
---|
71 | */
|
---|
72 | public static TaggingPresetType fromString(String type) {
|
---|
73 | for (TaggingPresetType t : TaggingPresetType.values()) {
|
---|
74 | if (t.getName().equals(type)) {
|
---|
75 | return t;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | return null;
|
---|
79 | }
|
---|
80 | }
|
---|