Changeset 8492 in josm for trunk/src/org
- Timestamp:
- 2015-06-19T16:57:12+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r8444 r8492 33 33 import java.util.EventObject; 34 34 import java.util.HashMap; 35 import java.util.HashSet;36 35 import java.util.Iterator; 36 import java.util.LinkedHashSet; 37 37 import java.util.List; 38 38 import java.util.Map; … … 1579 1579 */ 1580 1580 public final Set<String> getActiveUrls() { 1581 Set<String> urls = new HashSet<>();1581 Set<String> urls = new LinkedHashSet<>(); // retain order 1582 1582 for (SourceEntry e : get()) { 1583 1583 if (e.active) { -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r8444 r8492 124 124 } 125 125 126 /** 127 * Returns the translated name of this preset, prefixed with the group names it belongs to. 128 */ 126 129 public String getName() { 127 130 return group != null ? group.getName() + "/" + getLocaleName() : getLocaleName(); 128 131 } 132 133 /** 134 * Returns the non translated name of this preset, prefixed with the (non translated) group names it belongs to. 135 */ 129 136 public String getRawName() { 130 137 return group != null ? group.getRawName() + "/" + name : name; -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetMenu.java
r8345 r8492 13 13 import java.util.Comparator; 14 14 import java.util.List; 15 import java.util.Objects; 15 16 16 17 import javax.swing.Action; … … 36 37 return AlphanumComparator.getInstance().compare(o1.getText(), o2.getText()); 37 38 } 39 } 40 41 /** 42 * {@code TaggingPresetMenu} are considered equivalent if (and only if) their {@link #getRawName()} match. 43 */ 44 @Override 45 public boolean equals(Object o) { 46 if (this == o) return true; 47 if (o == null || getClass() != o.getClass()) return false; 48 TaggingPresetMenu that = (TaggingPresetMenu) o; 49 return Objects.equals(getRawName(), that.getRawName()); 50 } 51 52 @Override 53 public int hashCode() { 54 return Objects.hash(getRawName()); 38 55 } 39 56 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r8338 r8492 16 16 import java.util.HashMap; 17 17 import java.util.Iterator; 18 import java.util.LinkedHashSet; 18 19 import java.util.LinkedList; 19 20 import java.util.List; … … 27 28 import org.openstreetmap.josm.io.CachedFile; 28 29 import org.openstreetmap.josm.io.UTFInputStreamReader; 30 import org.openstreetmap.josm.tools.Predicates; 31 import org.openstreetmap.josm.tools.Utils; 29 32 import org.openstreetmap.josm.tools.XmlObjectParser; 30 33 import org.xml.sax.SAXException; … … 97 100 } 98 101 102 static class HashSetWithLast<E> extends LinkedHashSet<E> { 103 protected E last = null; 104 105 @Override 106 public boolean add(E e) { 107 last = e; 108 return super.add(e); 109 } 110 111 /** 112 * Returns the last inserted element. 113 */ 114 public E getLast() { 115 return last; 116 } 117 } 118 99 119 /** 100 120 * Reads all tagging presets from the input reader. … … 105 125 */ 106 126 public static Collection<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException { 127 return readAll(in, validate, new HashSetWithLast<TaggingPreset>()); 128 } 129 130 /** 131 * Reads all tagging presets from the input reader. 132 * @param in The input reader 133 * @param validate if {@code true}, XML validation will be performed 134 * @param all the accumulator for parsed tagging presets 135 * @return the accumulator 136 * @throws SAXException if any XML error occurs 137 */ 138 static Collection<TaggingPreset> readAll(Reader in, boolean validate, HashSetWithLast<TaggingPreset> all) throws SAXException { 107 139 XmlObjectParser parser = buildParser(); 108 140 109 Deque<TaggingPreset> all = new LinkedList<>();141 /** to detect end of {@code <group>} */ 110 142 TaggingPresetMenu lastmenu = null; 143 /** to detect end of reused {@code <group>} */ 144 TaggingPresetMenu lastmenuOriginal = null; 111 145 TaggingPresetItems.Roles lastrole = null; 112 146 final List<TaggingPresetItems.Check> checks = new LinkedList<>(); … … 173 207 if (o instanceof TaggingPresetMenu) { 174 208 TaggingPresetMenu tp = (TaggingPresetMenu) o; 175 if (tp == lastmenu ) {209 if (tp == lastmenu || tp == lastmenuOriginal) { 176 210 lastmenu = tp.group; 177 211 } else { 178 212 tp.group = lastmenu; 179 tp.setDisplayName(); 213 if (all.contains(tp)) { 214 lastmenuOriginal = tp; 215 tp = (TaggingPresetMenu) Utils.filter(all, Predicates.<TaggingPreset>equalTo(tp)).iterator().next(); 216 lastmenuOriginal.group = null; 217 } else { 218 tp.setDisplayName(); 219 all.add(tp); 220 lastmenuOriginal = null; 221 } 180 222 lastmenu = tp; 181 all.add(tp);182 223 } 183 224 lastrole = null; … … 253 294 */ 254 295 public static Collection<TaggingPreset> readAll(String source, boolean validate) throws SAXException, IOException { 296 return readAll(source, validate, new HashSetWithLast<TaggingPreset>()); 297 } 298 299 /** 300 * Reads all tagging presets from the given source. 301 * @param source a given filename, URL or internal resource 302 * @param validate if {@code true}, XML validation will be performed 303 * @param all the accumulator for parsed tagging presets 304 * @return the accumulator 305 * @throws SAXException if any XML error occurs 306 * @throws IOException if any I/O error occurs 307 */ 308 static Collection<TaggingPreset> readAll(String source, boolean validate, HashSetWithLast<TaggingPreset> all) throws SAXException, IOException { 255 309 Collection<TaggingPreset> tp; 256 310 CachedFile cf = new CachedFile(source).setHttpAccept(PRESET_MIME_TYPES); … … 263 317 } 264 318 try (InputStreamReader r = UTFInputStreamReader.create(zip == null ? cf.getInputStream() : zip)) { 265 tp = readAll(new BufferedReader(r), validate );319 tp = readAll(new BufferedReader(r), validate, all); 266 320 } 267 321 } … … 287 341 */ 288 342 public static Collection<TaggingPreset> readAll(Collection<String> sources, boolean validate, boolean displayErrMsg) { 289 List<TaggingPreset> allPresets = new LinkedList<>();343 HashSetWithLast<TaggingPreset> allPresets = new HashSetWithLast<>(); 290 344 for(String source : sources) { 291 345 try { 292 allPresets.addAll(readAll(source, validate));346 readAll(source, validate, allPresets); 293 347 } catch (IOException e) { 294 348 Main.error(e, false);
Note:
See TracChangeset
for help on using the changeset viewer.