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 * Data class representing one entry in the filter dialog.
011 *
012 * @author Petr_DlouhĂ˝
013 */
014public class Filter extends SearchSetting {
015    private static final String version = "1";
016
017    public boolean enable = true;
018    public boolean hiding;
019    public boolean inverted;
020
021    /**
022     * Constructs a new {@code Filter}.
023     */
024    public Filter() {
025        super();
026        mode = SearchMode.add;
027    }
028
029    public Filter(FilterPreferenceEntry e) {
030        this();
031        text = e.text;
032        if ("replace".equals(e.mode)) {
033            mode = SearchMode.replace;
034        } else if ("add".equals(e.mode)) {
035            mode = SearchMode.add;
036        } else if ("remove".equals(e.mode)) {
037            mode = SearchMode.remove;
038        } else  if ("in_selection".equals(e.mode)) {
039            mode = SearchMode.in_selection;
040        }
041        caseSensitive = e.case_sensitive;
042        regexSearch = e.regex_search;
043        mapCSSSearch = e.mapCSS_search;
044        enable = e.enable;
045        hiding = e.hiding;
046        inverted = e.inverted;
047    }
048
049    public static class FilterPreferenceEntry {
050        @pref @writeExplicitly public String version = "1";
051        @pref public String text;
052        @pref @writeExplicitly public String mode = "add";
053        @pref public boolean case_sensitive;
054        @pref public boolean regex_search;
055        @pref public boolean mapCSS_search;
056        @pref @writeExplicitly public boolean enable = true;
057        @pref @writeExplicitly public boolean hiding;
058        @pref @writeExplicitly public boolean inverted;
059    }
060
061    public FilterPreferenceEntry getPreferenceEntry() {
062        FilterPreferenceEntry e = new FilterPreferenceEntry();
063        e.version = version;
064        e.text = text;
065        e.mode = mode.toString();
066        e.case_sensitive = caseSensitive;
067        e.regex_search = regexSearch;
068        e.mapCSS_search = mapCSSSearch;
069        e.enable = enable;
070        e.hiding = hiding;
071        e.inverted = inverted;
072        return e;
073    }
074}