Changeset 12042 in josm for trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java
- Timestamp:
- 2017-05-03T11:19:04+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java
r11386 r12042 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Collections; 6 7 import java.util.HashMap; 8 import java.util.HashSet; 7 9 import java.util.Map; 10 import java.util.Set; 8 11 9 12 import javax.swing.JMenu; … … 14 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 18 import org.openstreetmap.josm.gui.MenuScroller; 16 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 19 import org.openstreetmap.josm.gui.tagging.presets.items.CheckGroup; 20 import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem; 21 import org.openstreetmap.josm.gui.tagging.presets.items.Roles; 22 import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role; 23 import org.openstreetmap.josm.tools.MultiMap; 17 24 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 18 25 … … 26 33 private static final Collection<TaggingPreset> taggingPresets = new ArrayList<>(); 27 34 35 /** cache for key/value pairs found in the preset */ 36 private static final MultiMap<String, String> PRESET_TAG_CACHE = new MultiMap<>(); 37 /** cache for roles found in the preset */ 38 private static final Set<String> PRESET_ROLE_CACHE = new HashSet<>(); 39 28 40 /** The collection of listeners */ 29 41 private static final Collection<TaggingPresetListener> listeners = new ArrayList<>(); … … 39 51 taggingPresets.clear(); 40 52 taggingPresets.addAll(TaggingPresetReader.readFromPreferences(false, false)); 53 cachePresets(taggingPresets); 41 54 } 42 55 … … 54 67 Main.main.menu.presetsMenu.setVisible(false); 55 68 } else { 56 AutoCompletionManager.cachePresets(taggingPresets);57 69 Map<TaggingPresetMenu, JMenu> submenus = new HashMap<>(); 58 70 for (final TaggingPreset p : taggingPresets) { … … 88 100 89 101 /** 102 * Initialize the cache for presets. This is done only once. 103 * @param presets Tagging presets to cache 104 */ 105 private static void cachePresets(Collection<TaggingPreset> presets) { 106 for (final TaggingPreset p : presets) { 107 for (TaggingPresetItem item : p.data) { 108 cachePresetItem(p, item); 109 } 110 } 111 } 112 113 private static void cachePresetItem(TaggingPreset p, TaggingPresetItem item) { 114 if (item instanceof KeyedItem) { 115 KeyedItem ki = (KeyedItem) item; 116 if (ki.key != null && ki.getValues() != null) { 117 try { 118 PRESET_TAG_CACHE.putAll(ki.key, ki.getValues()); 119 } catch (NullPointerException e) { 120 Main.error(e, p + ": Unable to cache " + ki); 121 } 122 } 123 } else if (item instanceof Roles) { 124 Roles r = (Roles) item; 125 for (Role i : r.roles) { 126 if (i.key != null) { 127 PRESET_ROLE_CACHE.add(i.key); 128 } 129 } 130 } else if (item instanceof CheckGroup) { 131 for (KeyedItem check : ((CheckGroup) item).checks) { 132 cachePresetItem(p, check); 133 } 134 } 135 } 136 137 /** 90 138 * Replies a new collection containing all tagging presets. 91 139 * @return a new collection containing all tagging presets. Empty if presets are not initialized (never null) 92 140 */ 93 141 public static Collection<TaggingPreset> getTaggingPresets() { 94 return new ArrayList<>(taggingPresets); 142 return Collections.unmodifiableCollection(taggingPresets); 143 } 144 145 /** 146 * Replies a set of all roles in the tagging presets. 147 * @return a set of all roles in the tagging presets. 148 */ 149 public static Set<String> getPresetRoles() { 150 return Collections.unmodifiableSet(PRESET_ROLE_CACHE); 151 } 152 153 /** 154 * Replies a set of all keys in the tagging presets. 155 * @return a set of all keys in the tagging presets. 156 */ 157 public static Set<String> getPresetKeys() { 158 return Collections.unmodifiableSet(PRESET_TAG_CACHE.keySet()); 159 } 160 161 /** 162 * Return set of values for a key in the tagging presets 163 * @param key the key 164 * @return set of values for a key in the tagging presets or null if none is found 165 */ 166 public static Set<String> getPresetValues(String key) { 167 Set<String> values = PRESET_TAG_CACHE.get(key); 168 if (values != null) 169 return Collections.unmodifiableSet(values); 170 return null; 95 171 } 96 172
Note:
See TracChangeset
for help on using the changeset viewer.