Ignore:
Timestamp:
2014-11-15T21:45:22+01:00 (9 years ago)
Author:
bastiK
Message:

autocomplete: remember user input and prefer recently entered strings

It bugged my, that in tag add dialog, JOSM always autocompletes addr:h to
addr:housename. But addr:housenumber is what I want.

Now it remembers the last tags that have been entered in a session
and gives those the highest priority in autocompletion.
More recent entries are preferred.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionItemPriority.java

    r6830 r7725  
    3737    public static final AutoCompletionItemPriority UNKNOWN = new AutoCompletionItemPriority(false, false, false);
    3838
     39    private final static int NO_USER_INPUT = Integer.MAX_VALUE;
     40
     41    private final int userInput;
    3942    private final boolean inDataSet;
    4043    private final boolean inStandard;
    4144    private final boolean selected;
     45   
    4246
    43     public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected) {
     47    /**
     48     * Create new AutoCompletionItemPriority object.
     49     *
     50     * @param inDataSet true, if the item is found in the currently active data layer
     51     * @param inStandard true, if the item is a standard tag, e.g. from the presets.
     52     * @param selected true, if it is found on an object that is currently selected
     53     * @param userInput null, if the user hasn't entered this tag so far. A number when
     54     * the tag key / value has been entered by the user before. A lower number means
     55     * this happened more recently and beats a higher number in priority.
     56     */
     57    public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected, Integer userInput) {
    4458        this.inDataSet = inDataSet;
    4559        this.inStandard = inStandard;
    4660        this.selected = selected;
     61        this.userInput = userInput == null ? NO_USER_INPUT : userInput;
     62    }
     63
     64    public AutoCompletionItemPriority(boolean inDataSet, boolean inStandard, boolean selected) {
     65        this(inDataSet, inStandard, selected, NO_USER_INPUT);
    4766    }
    4867
     
    5978    }
    6079
     80    public Integer getUserInput() {
     81        return userInput == NO_USER_INPUT ? null : userInput;
     82    }
     83   
    6184    /**
    6285     * Imposes an ordering on the priorities.
     
    6588    @Override
    6689    public int compareTo(AutoCompletionItemPriority other) {
     90        int ui = -Integer.compare(userInput, other.userInput);
     91        if (ui != 0) return ui;
     92
    6793        int sel = Boolean.valueOf(selected).compareTo(other.selected);
    6894        if (sel != 0) return sel;
     
    85111                inDataSet || other.inDataSet,
    86112                inStandard || other.inStandard,
    87                 selected || other.selected);
     113                selected || other.selected,
     114                Math.min(userInput, other.userInput));
    88115    }
    89116
    90117    @Override public String toString() {
    91         return String.format("<Priority; inDataSet: %b, inStandard: %b, selected: %b>", inDataSet, inStandard, selected);
     118        return String.format("<Priority; userInput: %s, inDataSet: %b, inStandard: %b, selected: %b>",
     119                userInput == NO_USER_INPUT ? "no" : Integer.toString(userInput), inDataSet, inStandard, selected);
    92120    }
    93121}
Note: See TracChangeset for help on using the changeset viewer.