[6068] | 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
|
---|
[6074] | 9 | * @since 6068
|
---|
[6068] | 10 | */
|
---|
| 11 | public enum TaggingPresetType {
|
---|
[8484] | 12 | /** Node */
|
---|
[7668] | 13 | NODE(/* ICON */ "Mf_node", "node"),
|
---|
[8484] | 14 | /** Way */
|
---|
[7668] | 15 | WAY(/* ICON */ "Mf_way", "way"),
|
---|
[8484] | 16 | /** Relation */
|
---|
[7668] | 17 | RELATION(/* ICON */ "Mf_relation", "relation"),
|
---|
[8484] | 18 | /** Closed way */
|
---|
[7668] | 19 | CLOSEDWAY(/* ICON */ "Mf_closedway", "closedway");
|
---|
[6068] | 20 | private final String iconName;
|
---|
| 21 | private final String name;
|
---|
| 22 |
|
---|
| 23 | TaggingPresetType(String iconName, String name) {
|
---|
[8484] | 24 | this.iconName = iconName + ".svg";
|
---|
[6068] | 25 | this.name = name;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[8484] | 28 | /**
|
---|
| 29 | * Replies the SVG icon name.
|
---|
| 30 | * @return the SVG icon name
|
---|
| 31 | */
|
---|
[6068] | 32 | public String getIconName() {
|
---|
| 33 | return iconName;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[8484] | 36 | /**
|
---|
| 37 | * Replies the name, as used in XML presets.
|
---|
| 38 | * @return the name: "node", "way", "relation" or "closedway"
|
---|
| 39 | */
|
---|
[6068] | 40 | public String getName() {
|
---|
| 41 | return name;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[8484] | 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 | */
|
---|
[6068] | 49 | public static TaggingPresetType forPrimitive(OsmPrimitive p) {
|
---|
| 50 | return forPrimitiveType(p.getDisplayType());
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[8484] | 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 | */
|
---|
[6068] | 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 |
|
---|
[8484] | 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 | */
|
---|
[6068] | 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 | }
|
---|