001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.preferences.sources;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.util.Collection;
007import java.util.Collections;
008import java.util.HashMap;
009import java.util.Map;
010
011/**
012 * Helper class for tagging presets preferences.
013 * @since 12649 (extracted from gui.preferences package)
014 */
015public class PresetPrefHelper extends SourcePrefHelper {
016
017    /**
018     * The unique instance.
019     */
020    public static final PresetPrefHelper INSTANCE = new PresetPrefHelper();
021
022    /**
023     * Constructs a new {@code PresetPrefHelper}.
024     */
025    public PresetPrefHelper() {
026        super("taggingpreset.entries", SourceType.TAGGING_PRESET);
027    }
028
029    @Override
030    public Collection<ExtendedSourceEntry> getDefault() {
031        ExtendedSourceEntry i = new ExtendedSourceEntry(type, "defaultpresets.xml", "resource://data/defaultpresets.xml");
032        i.title = tr("Internal Preset");
033        i.description = tr("The default preset for JOSM");
034        return Collections.singletonList(i);
035    }
036
037    @Override
038    public Map<String, String> serialize(SourceEntry entry) {
039        Map<String, String> res = new HashMap<>();
040        res.put("url", entry.url);
041        res.put("title", entry.title == null ? "" : entry.title);
042        return res;
043    }
044
045    @Override
046    public SourceEntry deserialize(Map<String, String> s) {
047        return new SourceEntry(type, s.get("url"), null, s.get("title"), true);
048    }
049}