001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.tagging;
003
004import org.openstreetmap.josm.data.osm.OsmPrimitive;
005import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
006
007/**
008 * Enumeration of OSM primitive types associated with names and icons
009 * @since 6068
010 */
011public enum TaggingPresetType {
012    NODE("Mf_node", "node"), WAY("Mf_way", "way"), RELATION("Mf_relation", "relation"), CLOSEDWAY("Mf_closedway", "closedway");
013    private final String iconName;
014    private final String name;
015
016    TaggingPresetType(String iconName, String name) {
017        this.iconName = iconName;
018        this.name = name;
019    }
020
021    public String getIconName() {
022        return iconName;
023    }
024
025    public String getName() {
026        return name;
027    }
028
029    public static TaggingPresetType forPrimitive(OsmPrimitive p) {
030        return forPrimitiveType(p.getDisplayType());
031    }
032
033    public static TaggingPresetType forPrimitiveType(OsmPrimitiveType type) {
034        if (type == OsmPrimitiveType.NODE) return NODE;
035        if (type == OsmPrimitiveType.WAY) return WAY;
036        if (type == OsmPrimitiveType.CLOSEDWAY) return CLOSEDWAY;
037        if (type == OsmPrimitiveType.RELATION || type == OsmPrimitiveType.MULTIPOLYGON)
038                return RELATION;
039        throw new IllegalArgumentException("Unexpected primitive type: " + type);
040    }
041
042    public static TaggingPresetType fromString(String type) {
043        for (TaggingPresetType t : TaggingPresetType.values()) {
044            if (t.getName().equals(type)) {
045                return t;
046            }
047        }
048        return null;
049    }
050
051}