Ticket #6096: 6096.patch

File 6096.patch, 3.9 KB (added by simon04, 14 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
    index fe00fb8..996d001 100644
    a b public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    269269        });
    270270        values.setEditable(true);
    271271
     272        final Map<String, Integer> m = (Map<String, Integer>) propertyData.getValueAt(row, 1);
     273
     274        Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() {
     275
     276            @Override
     277            public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) {
     278                boolean c1 = m.containsKey(o1.getValue());
     279                boolean c2 = m.containsKey(o2.getValue());
     280                if (c1 == c2) {
     281                    return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
     282                } else if (c1) {
     283                    return -1;
     284                } else {
     285                    return +1;
     286                }
     287            }
     288        };
     289
    272290        List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
    273         Collections.sort(valueList, defaultACItemComparator);
     291        Collections.sort(valueList, usedValuesAwareComparator);
    274292
    275293        values.setPossibleACItems(valueList);
    276         Map<String, Integer> m=(Map<String, Integer>)propertyData.getValueAt(row, 1);
    277294        final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey();
    278295        values.setSelectedItem(selection);
    279296        values.getEditor().setItem(selection);
    280297        p.add(new JLabel(tr("Value")), GBC.std());
    281298        p.add(Box.createHorizontalStrut(10), GBC.std());
    282299        p.add(values, GBC.eol().fill(GBC.HORIZONTAL));
    283         addFocusAdapter(row, keys, values, autocomplete);
     300        addFocusAdapter(row, keys, values, autocomplete, usedValuesAwareComparator);
    284301
    285302        final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) {
    286303            @Override public void selectInitialValue() {
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    474491            }
    475492        }
    476493
    477         FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete);
     494        FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator);
    478495        // fire focus event in advance or otherwise the popup list will be too small at first
    479496        focus.focusGained(null);
    480497
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    505522     * @param keys
    506523     * @param values
    507524     */
    508     private FocusAdapter addFocusAdapter(final int row, final AutoCompletingComboBox keys, final AutoCompletingComboBox values, final AutoCompletionManager autocomplete) {
     525    private FocusAdapter addFocusAdapter(final int row,
     526            final AutoCompletingComboBox keys, final AutoCompletingComboBox values,
     527            final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) {
    509528        // get the combo box' editor component
    510529        JTextComponent editor = (JTextComponent)values.getEditor()
    511530                .getEditorComponent();
    public class PropertiesDialog extends ToggleDialog implements SelectionChangedLi  
    515534                String key = keys.getEditor().getItem().toString();
    516535
    517536                List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
    518                 Collections.sort(valueList, defaultACItemComparator);
     537                Collections.sort(valueList, comparator);
    519538
    520539                values.setPossibleACItems(valueList);
    521540                objKey=key;