001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm;
003
004import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
005import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
006import org.openstreetmap.josm.data.Preferences.pref;
007import org.openstreetmap.josm.data.Preferences.writeExplicitly;
008
009/**
010 *
011 * @author Petr_DlouhĂ˝
012 */
013public class Filter extends SearchSetting {
014    private static final String version = "1";
015
016    public boolean enable = true;
017    public boolean hiding;
018    public boolean inverted;
019
020    /**
021     * Constructs a new {@code Filter}.
022     */
023    public Filter() {
024        super();
025        mode = SearchMode.add;
026    }
027
028    public Filter(FilterPreferenceEntry e) {
029        this();
030        text = e.text;
031        if ("replace".equals(e.mode)) {
032            mode = SearchMode.replace;
033        } else if ("add".equals(e.mode)) {
034            mode = SearchMode.add;
035        } else if ("remove".equals(e.mode)) {
036            mode = SearchMode.remove;
037        } else  if ("in_selection".equals(e.mode)) {
038            mode = SearchMode.in_selection;
039        }
040        caseSensitive = e.case_sensitive;
041        regexSearch = e.regex_search;
042        mapCSSSearch = e.mapCSS_search;
043        enable = e.enable;
044        hiding = e.hiding;
045        inverted = e.inverted;
046    }
047
048    public static class FilterPreferenceEntry {
049        @pref @writeExplicitly public String version = "1";
050        @pref public String text;
051        @pref @writeExplicitly public String mode = "add";
052        @pref public boolean case_sensitive;
053        @pref public boolean regex_search;
054        @pref public boolean mapCSS_search;
055        @pref @writeExplicitly public boolean enable = true;
056        @pref @writeExplicitly public boolean hiding;
057        @pref @writeExplicitly public boolean inverted;
058    }
059
060    public FilterPreferenceEntry getPreferenceEntry() {
061        FilterPreferenceEntry e = new FilterPreferenceEntry();
062        e.version = version;
063        e.text = text;
064        e.mode = mode.toString();
065        e.case_sensitive = caseSensitive;
066        e.regex_search = regexSearch;
067        e.mapCSS_search = mapCSSSearch;
068        e.enable = enable;
069        e.hiding = hiding;
070        e.inverted = inverted;
071        return e;
072    }
073}