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(/* ICON */ "Mf_node", "node"), 013 WAY(/* ICON */ "Mf_way", "way"), 014 RELATION(/* ICON */ "Mf_relation", "relation"), 015 CLOSEDWAY(/* ICON */ "Mf_closedway", "closedway"); 016 private final String iconName; 017 private final String name; 018 019 TaggingPresetType(String iconName, String name) { 020 this.iconName = iconName; 021 this.name = name; 022 } 023 024 public String getIconName() { 025 return iconName; 026 } 027 028 public String getName() { 029 return name; 030 } 031 032 public static TaggingPresetType forPrimitive(OsmPrimitive p) { 033 return forPrimitiveType(p.getDisplayType()); 034 } 035 036 public static TaggingPresetType forPrimitiveType(OsmPrimitiveType type) { 037 if (type == OsmPrimitiveType.NODE) return NODE; 038 if (type == OsmPrimitiveType.WAY) return WAY; 039 if (type == OsmPrimitiveType.CLOSEDWAY) return CLOSEDWAY; 040 if (type == OsmPrimitiveType.RELATION || type == OsmPrimitiveType.MULTIPOLYGON) 041 return RELATION; 042 throw new IllegalArgumentException("Unexpected primitive type: " + type); 043 } 044 045 public static TaggingPresetType fromString(String type) { 046 for (TaggingPresetType t : TaggingPresetType.values()) { 047 if (t.getName().equals(type)) { 048 return t; 049 } 050 } 051 return null; 052 } 053 054}