1 package org.apache.ojb.tools.swing; 2 3 17 18 19 24 public class SortingComboBoxModel extends javax.swing.AbstractListModel 25 implements javax.swing.MutableComboBoxModel 26 { 27 28 java.util.List aList; 29 Object selectedItem; 30 31 32 public SortingComboBoxModel () 33 { 34 super(); 35 } 36 37 public SortingComboBoxModel(java.util.List l) 38 { 39 super(); 40 aList = l; 41 this.setSelectedItem(getElementAt(0)); 42 } 43 44 public Object getElementAt (int param) 45 { 46 return aList.get(param); 48 } 49 50 public int getSize () 51 { 52 return aList.size(); 54 } 55 56 57 public void addElement (Object obj) 58 { 59 aList.add(obj); 61 java.util.Collections.sort(aList); 62 this.fireContentsChanged(this, 0, aList.size()); 63 } 64 65 public Object getSelectedItem() 66 { 67 return this.selectedItem; 69 } 70 71 public void insertElementAt (Object obj, int param) 72 { 73 aList.add(param, obj); 75 java.util.Collections.sort(aList); 76 this.fireContentsChanged(this, -1, aList.size()); 77 } 78 79 public void removeElement (Object obj) 80 { 81 aList.remove(obj); 82 } 83 84 public void removeElementAt (int param) 85 { 86 aList.remove(param); 87 } 88 89 public void setSelectedItem (Object obj) 90 { 91 if ( (selectedItem != null && !selectedItem.equals(obj)) 92 || (selectedItem == null && obj != null)) 93 { 94 selectedItem = obj; 95 fireContentsChanged(this, -1, -1); 96 } 97 } 99 100 public int getIndexOf(Object o) 101 { 102 return aList.indexOf(o); 104 } 105 } 106 | Popular Tags |