1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging;
|
---|
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("Mf_node", "node"), WAY("Mf_way", "way"), RELATION("Mf_relation", "relation"), CLOSEDWAY("Mf_closedway", "closedway");
|
---|
13 | private final String iconName;
|
---|
14 | private final String name;
|
---|
15 |
|
---|
16 | TaggingPresetType(String iconName, String name) {
|
---|
17 | this.iconName = iconName;
|
---|
18 | this.name = name;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public String getIconName() {
|
---|
22 | return iconName;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public String getName() {
|
---|
26 | return name;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public static TaggingPresetType forPrimitive(OsmPrimitive p) {
|
---|
30 | return forPrimitiveType(p.getDisplayType());
|
---|
31 | }
|
---|
32 |
|
---|
33 | public static TaggingPresetType forPrimitiveType(OsmPrimitiveType type) {
|
---|
34 | if (type == OsmPrimitiveType.NODE) return NODE;
|
---|
35 | if (type == OsmPrimitiveType.WAY) return WAY;
|
---|
36 | if (type == OsmPrimitiveType.CLOSEDWAY) return CLOSEDWAY;
|
---|
37 | if (type == OsmPrimitiveType.RELATION || type == OsmPrimitiveType.MULTIPOLYGON)
|
---|
38 | return RELATION;
|
---|
39 | throw new IllegalArgumentException("Unexpected primitive type: " + type);
|
---|
40 | }
|
---|
41 |
|
---|
42 | public static TaggingPresetType fromString(String type) {
|
---|
43 | for (TaggingPresetType t : TaggingPresetType.values()) {
|
---|
44 | if (t.getName().equals(type)) {
|
---|
45 | return t;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | return null;
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|