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