Ignore:
Timestamp:
2010-05-03T10:52:48+02:00 (14 years ago)
Author:
bastiK
Message:

fixed #4979 Exception when opening the download window; fixed #2221 - Unexcepted Exception when typing into "Change values?" box with an input method on Mac OS X

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java

    r3083 r3215  
    3535import javax.swing.DefaultComboBoxModel;
    3636
    37 public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<String> {
     37import org.openstreetmap.josm.gui.tagging.ac.*;
     38
     39public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<AutoCompletionListItem> {
    3840
    3941    private int maxSize = 10;
     
    5052    @Override
    5153    public void addElement(Object o) {
    52         String newEntry = (String)o;
     54        if (o instanceof String) {
     55            o = new AutoCompletionListItem((String) o);
     56        }
     57
     58        String newEntry = ((AutoCompletionListItem)o).getValue();
    5359
    5460        // if history contains this object already, delete it,
    5561        // so that it looks like a move to the top
    5662        for (int i = 0; i < getSize(); i++) {
    57             String oldEntry = (String) getElementAt(i);
     63            String oldEntry = ((AutoCompletionListItem) getElementAt(i)).getValue();
    5864            if(oldEntry.equals(newEntry)) {
    5965                removeElementAt(i);
     
    7581    }
    7682
    77     public Iterator<String> iterator() {
    78         return new Iterator<String>() {
     83    public Iterator<AutoCompletionListItem> iterator() {
     84        return new Iterator<AutoCompletionListItem>() {
    7985
    8086            private int position = -1;
     
    9096            }
    9197
    92             public String next() {
     98            public AutoCompletionListItem next() {
    9399                position++;
    94                 return getElementAt(position).toString();
     100                return (AutoCompletionListItem)getElementAt(position);
    95101            }
    96102
     
    98104    }
    99105
    100     public void setItems(List<String> items) {
     106    public void setItemsAsString(List<String> items) {
    101107        removeAllElements();
    102         Collections.reverse(items);
    103         for (String item : items) {
    104             addElement(item);
     108        for (int i = items.size()-1; i>=0; i--) {
     109            addElement(new AutoCompletionListItem(items.get(i)));
    105110        }
    106         Collections.reverse(items);
    107111    }
    108112
    109     public List<String> asList() {
     113    public List<String> asStringList() {
    110114        List<String> list = new ArrayList<String>(maxSize);
    111         for (String item : this) {
    112             list.add(item);
     115        for (AutoCompletionListItem item : this) {
     116            list.add(item.getValue());
    113117        }
    114118        return list;
     
    125129    private void fireHistoryChanged() {
    126130        for (HistoryChangedListener l : listeners) {
    127             l.historyChanged(asList());
     131            l.historyChanged(asStringList());
    128132        }
    129133    }
Note: See TracChangeset for help on using the changeset viewer.