Changeset 3215 in josm for trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java
- Timestamp:
- 2010-05-03T10:52:48+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java
r3083 r3215 35 35 import javax.swing.DefaultComboBoxModel; 36 36 37 public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<String> { 37 import org.openstreetmap.josm.gui.tagging.ac.*; 38 39 public class ComboBoxHistory extends DefaultComboBoxModel implements Iterable<AutoCompletionListItem> { 38 40 39 41 private int maxSize = 10; … … 50 52 @Override 51 53 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(); 53 59 54 60 // if history contains this object already, delete it, 55 61 // so that it looks like a move to the top 56 62 for (int i = 0; i < getSize(); i++) { 57 String oldEntry = ( String) getElementAt(i);63 String oldEntry = ((AutoCompletionListItem) getElementAt(i)).getValue(); 58 64 if(oldEntry.equals(newEntry)) { 59 65 removeElementAt(i); … … 75 81 } 76 82 77 public Iterator< String> iterator() {78 return new Iterator< String>() {83 public Iterator<AutoCompletionListItem> iterator() { 84 return new Iterator<AutoCompletionListItem>() { 79 85 80 86 private int position = -1; … … 90 96 } 91 97 92 public Stringnext() {98 public AutoCompletionListItem next() { 93 99 position++; 94 return getElementAt(position).toString();100 return (AutoCompletionListItem)getElementAt(position); 95 101 } 96 102 … … 98 104 } 99 105 100 public void setItems (List<String> items) {106 public void setItemsAsString(List<String> items) { 101 107 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))); 105 110 } 106 Collections.reverse(items);107 111 } 108 112 109 public List<String> as List() {113 public List<String> asStringList() { 110 114 List<String> list = new ArrayList<String>(maxSize); 111 for ( Stringitem : this) {112 list.add(item );115 for (AutoCompletionListItem item : this) { 116 list.add(item.getValue()); 113 117 } 114 118 return list; … … 125 129 private void fireHistoryChanged() { 126 130 for (HistoryChangedListener l : listeners) { 127 l.historyChanged(as List());131 l.historyChanged(asStringList()); 128 132 } 129 133 }
Note:
See TracChangeset
for help on using the changeset viewer.