Changeset 5520 in josm


Ignore:
Timestamp:
2012-09-30T18:18:27+02:00 (12 years ago)
Author:
Don-vip
Message:

fix #8088 - Width of edit box for long values

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r5484 r5520  
    260260        Collections.sort(keyList, defaultACItemComparator);
    261261
    262         final AutoCompletingComboBox keys = new AutoCompletingComboBox();
     262        final AutoCompletingComboBox keys = new AutoCompletingComboBox(key);
    263263        keys.setPossibleACItems(keyList);
    264264        keys.setEditable(true);
     
    269269        p.add(keys, GBC.eol().fill(GBC.HORIZONTAL));
    270270
    271         final AutoCompletingComboBox values = new AutoCompletingComboBox();
     271        final Map<String, Integer> m = (Map<String, Integer>) propertyData.getValueAt(row, 1);
     272
     273        Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() {
     274
     275            @Override
     276            public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) {
     277                boolean c1 = m.containsKey(o1.getValue());
     278                boolean c2 = m.containsKey(o2.getValue());
     279                if (c1 == c2)
     280                    return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
     281                else if (c1)
     282                    return -1;
     283                else
     284                    return +1;
     285            }
     286        };
     287
     288        List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
     289        Collections.sort(valueList, usedValuesAwareComparator);
     290
     291        final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey();
     292       
     293        final AutoCompletingComboBox values = new AutoCompletingComboBox(selection);
    272294        values.setRenderer(new DefaultListCellRenderer() {
    273295            @Override public Component getListCellRendererComponent(JList list,
     
    289311            }
    290312        });
     313       
    291314        values.setEditable(true);
    292 
    293         final Map<String, Integer> m = (Map<String, Integer>) propertyData.getValueAt(row, 1);
    294 
    295         Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() {
    296 
    297             @Override
    298             public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) {
    299                 boolean c1 = m.containsKey(o1.getValue());
    300                 boolean c2 = m.containsKey(o2.getValue());
    301                 if (c1 == c2)
    302                     return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
    303                 else if (c1)
    304                     return -1;
    305                 else
    306                     return +1;
    307             }
    308         };
    309 
    310         List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
    311         Collections.sort(valueList, usedValuesAwareComparator);
    312 
    313315        values.setPossibleACItems(valueList);
    314         final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey();
    315316        values.setSelectedItem(selection);
    316317        values.getEditor().setItem(selection);
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r5483 r5520  
    146146    }
    147147
     148    /**
     149     * Creates a <code>AutoCompletingComboBox</code> with a default prototype display value.
     150     */
    148151    public AutoCompletingComboBox() {
    149         super(new AutoCompletionListItem(JosmComboBox.DEFAULT_PROTOTYPE_DISPLAY_VALUE));
     152        this(JosmComboBox.DEFAULT_PROTOTYPE_DISPLAY_VALUE);
     153    }
     154
     155    /**
     156     * Creates a <code>AutoCompletingComboBox</code> with the specified prototype display value.
     157     * @param prototype the <code>Object</code> used to compute the maximum number of elements to be displayed at once before displaying a scroll bar.
     158     *                  It also affects the initial width of the combo box.
     159     * @since 5520
     160     */
     161    public AutoCompletingComboBox(String prototype) {
     162        super(new AutoCompletionListItem(prototype));
    150163        setRenderer(new AutoCompleteListCellRenderer());
    151164        final JTextComponent editor = (JTextComponent) this.getEditor().getEditorComponent();
Note: See TracChangeset for help on using the changeset viewer.