Changeset 4680 in josm


Ignore:
Timestamp:
Dec 21, 2011 10:18:40 AM (17 months ago)
Author:
simon04
Message:

see #6096 - "change values" dialog: show bold entries first

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r4663 r4680  
    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); 
     
    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) { 
     
    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); 
     
    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() 
     
    516535 
    517536                List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key)); 
    518                 Collections.sort(valueList, defaultACItemComparator); 
     537                Collections.sort(valueList, comparator); 
    519538 
    520539                values.setPossibleACItems(valueList); 
Note: See TracChangeset for help on using the changeset viewer.