1 18 19 package org.objectweb.jac.aspects.gui; 20 21 import org.apache.log4j.Logger; 22 import org.objectweb.jac.core.Wrappee; 23 import org.objectweb.jac.core.rtti.ClassItem; 24 import org.objectweb.jac.core.rtti.CollectionItem; 25 26 28 29 public class ComboBoxModel extends LessAbstractListModel 30 implements ObjectChooserModel 31 { 32 static Logger logger = Logger.getLogger("gui.combobox"); 33 34 36 public ComboBoxModel() { 37 super(); 38 } 39 40 46 public ComboBoxModel(CollectionItem collection, Object substance) { 47 super(collection,substance); 48 } 49 50 56 public void addObject(Object object, String label) { 57 logger.debug("addChoice("+object+" -> "+label+")"); 58 String key = label; 59 int i=2; 60 while (rows.contains(key)) { 61 key = label+"<"+(i++)+">"; 62 } 63 super.addObject(object,key); 64 } 65 66 int selectedIndex = -1; 67 Object selectedObject = null; 68 Object selectedObjectString = null; 69 70 73 public Object getSelectedItem() { 74 return selectedObjectString; 75 } 76 81 public void setSelectedItem(Object object) { 82 logger.debug(this+".setSelectedItem("+object+")"); 83 selectedIndex = rows.indexOf(object); 86 selectedObjectString = object; 87 if (selectedIndex!=-1) { 88 selectedObject = objects.get(selectedIndex); 89 } else { 90 if (type!=null && Wrappee.class.isAssignableFrom(type.getActualClass())) 91 throw new RuntimeException ("ComboBoxModel: no such element '"+object+"'"); 92 selectedObject = object; 94 } 96 logger.debug(" selectedIndex="+selectedIndex); 97 logger.debug(" selectedObject="+selectedObject); 98 logger.debug(" selectedObjectString="+selectedObjectString); 99 fireContentsChanged(this,-1,-1); 100 } 101 102 107 public void setSelectedObject(Object object) { 108 logger.debug(this+".setSelectedObject("+object+")"); 109 selectedIndex = objects.indexOf(object); 112 selectedObject = object; 113 if (selectedIndex!=-1) 114 selectedObjectString = rows.get(selectedIndex); 115 else 116 selectedObjectString = GuiAC.toString(object); 117 logger.debug(" selectedIndex="+selectedIndex); 118 logger.debug(" selectedObject="+selectedObject); 119 logger.debug(" selectedObjectString="+selectedObjectString); 120 fireContentsChanged(this,-1,-1); 121 } 122 123 126 public Object getSelectedObject() { 127 return selectedObject; 128 } 129 130 132 ClassItem type; 133 public void setType(ClassItem type) { 134 this.type = type; 135 } 136 public ClassItem getType() { 137 return type; 138 } 139 } 140 | Popular Tags |