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

Last change on this file was 16976, checked in by Klumbumbus, 4 years ago

see #19726 - Update OSM wiki object type icons (taken from e.g. https://wiki.openstreetmap.org/wiki/File:Osm_element_closedway.svg), resized, adapt our multipolygon variant, all PD and CC0 licensed

  • 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 java.util.Arrays;
5
6import org.openstreetmap.josm.data.osm.IPrimitive;
7import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
8
9/**
10 * Enumeration of OSM primitive types associated with names and icons
11 * @since 6068
12 */
13public enum TaggingPresetType {
14 /** Node */
15 NODE(/* ICON */ "Osm_element_node", "node"),
16 /** Way */
17 WAY(/* ICON */ "Osm_element_way", "way"),
18 /** Relation */
19 RELATION(/* ICON */ "Osm_element_relation", "relation"),
20 /** Closed way */
21 CLOSEDWAY(/* ICON */ "Osm_element_closedway", "closedway"),
22 /** Multipolygon */
23 MULTIPOLYGON(/* ICON */ "Osm_element_multipolygon", "multipolygon");
24 private final String iconName;
25 private final String name;
26
27 TaggingPresetType(String iconName, String name) {
28 this.iconName = iconName + ".svg";
29 this.name = name;
30 }
31
32 /**
33 * Replies the SVG icon name.
34 * @return the SVG icon name
35 */
36 public String getIconName() {
37 return iconName;
38 }
39
40 /**
41 * Replies the name, as used in XML presets.
42 * @return the name: "node", "way", "relation" or "closedway"
43 */
44 public String getName() {
45 return name;
46 }
47
48 /**
49 * Determines the {@code TaggingPresetType} of a given primitive.
50 * @param p The OSM primitive
51 * @return the {@code TaggingPresetType} of {@code p}
52 */
53 public static TaggingPresetType forPrimitive(IPrimitive p) {
54 return forPrimitiveType(p.getDisplayType());
55 }
56
57 /**
58 * Determines the {@code TaggingPresetType} of a given primitive type.
59 * @param type The OSM primitive type
60 * @return the {@code TaggingPresetType} of {@code type}
61 */
62 public static TaggingPresetType forPrimitiveType(OsmPrimitiveType type) {
63 if (type == OsmPrimitiveType.NODE)
64 return NODE;
65 if (type == OsmPrimitiveType.WAY)
66 return WAY;
67 if (type == OsmPrimitiveType.CLOSEDWAY)
68 return CLOSEDWAY;
69 if (type == OsmPrimitiveType.MULTIPOLYGON)
70 return MULTIPOLYGON;
71 if (type == OsmPrimitiveType.RELATION)
72 return RELATION;
73 throw new IllegalArgumentException("Unexpected primitive type: " + type);
74 }
75
76 /**
77 * Determines the {@code TaggingPresetType} from a given string.
78 * @param type The OSM primitive type as string ("node", "way", "relation" or "closedway")
79 * @return the {@code TaggingPresetType} from {@code type}
80 */
81 public static TaggingPresetType fromString(String type) {
82 return Arrays.stream(TaggingPresetType.values())
83 .filter(t -> t.getName().equals(type))
84 .findFirst().orElse(null);
85 }
86}
Note: See TracBrowser for help on using the repository browser.