source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetType.java@ 16282

Last change on this file since 16282 was 13564, checked in by Don-vip, 6 years ago

introduce PrimitiveRenderer to replace OsmPrimitivRenderer (now deprecated). Change NameFormatter API to support IPrimitive instead of OsmPrimitive. Enhances interfaces in consequence.

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