Ignore:
Timestamp:
2011-02-16T16:39:09+01:00 (15 years ago)
Author:
bastiK
Message:

new preference type (list of structs). Should be more flexible when preference options are added and dropped for a list like features. (Not sure how far we get with this key=value approach, maybe it's time for xml preferences.) Fixes #5850 - Filter entries are mixed up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Filter.java

    r3719 r3908  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.openstreetmap.josm.tools.Utils.equal;
     5
    46import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
    57import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
     8import org.openstreetmap.josm.data.Preferences.pref;
     9import org.openstreetmap.josm.data.Preferences.writeExplicitly;
     10import org.openstreetmap.josm.tools.Utils;
    611
    712/**
     
    2429    }
    2530
     31    @Deprecated
    2632    public Filter(String prefText) {
    2733        super("", SearchMode.add, false, false, false);
     
    4955    }
    5056
    51     public String getPrefString(){
    52         return version + ";" +
    53         text + ";" + mode + ";" + caseSensitive + ";" + regexSearch + ";" +
    54         "legacy" + ";" + enable + ";" + hiding + ";" +
    55         inverted + ";" +
    56         "false"; // last parameter is not used any more (was: applyForChildren)
     57    public Filter(FilterPreferenceEntry e) {
     58        super(e.text, SearchMode.add, false, false, false);
     59        if (equal(e.mode, "replace")) {
     60            mode = SearchMode.replace;
     61        } else if (equal(e.mode, "add")) {
     62            mode = SearchMode.add;
     63        } else if (equal(e.mode, "remove")) {
     64            mode = SearchMode.remove;
     65        } else  if (equal(e.mode, "in_selection")) {
     66            mode = SearchMode.in_selection;
     67        }
     68        caseSensitive = e.case_sensitive;
     69        regexSearch = e.regex_search;
     70        enable = e.enable;
     71        hiding = e.hiding;
     72        inverted = e.inverted;
     73    }
     74
     75    public static class FilterPreferenceEntry {
     76        @pref @writeExplicitly public String version = "1";
     77        @pref public String text = null;
     78        @pref @writeExplicitly public String mode = "add";
     79        @pref public boolean case_sensitive = false;
     80        @pref public boolean regex_search = false;
     81        @pref @writeExplicitly public boolean enable = true;
     82        @pref @writeExplicitly public boolean hiding = false;
     83        @pref @writeExplicitly public boolean inverted = false;
     84    }
     85
     86    public FilterPreferenceEntry getPreferenceEntry() {
     87        FilterPreferenceEntry e = new FilterPreferenceEntry();
     88        e.version = version;
     89        e.text = text;
     90        e.mode = mode.toString();
     91        e.case_sensitive = caseSensitive;
     92        e.regex_search = regexSearch;
     93        e.enable = enable;
     94        e.hiding = hiding;
     95        e.inverted = inverted;
     96        return e;
    5797    }
    5898}
Note: See TracChangeset for help on using the changeset viewer.