1 20 package org.enhydra.barracuda.core.comp; 21 22 import java.util.*; 23 24 import org.apache.log4j.*; 25 import org.w3c.dom.*; 26 import org.w3c.dom.html.*; 27 28 import org.enhydra.barracuda.core.comp.model.*; 29 import org.enhydra.barracuda.core.comp.renderer.*; 30 import org.enhydra.barracuda.core.comp.renderer.html.*; 31 import org.enhydra.barracuda.core.comp.renderer.xml.*; 32 import org.enhydra.barracuda.core.util.dom.DOMUtil; 33 import org.enhydra.barracuda.core.view.*; 34 import org.enhydra.barracuda.plankton.*; 35 36 46 public class BList extends BComponent { 47 48 protected static final Logger logger = Logger.getLogger(BList.class.getName()); 50 51 protected ListModel model = null; 53 private LocalModelListener callback = null; 54 55 59 public BList() {} 60 61 67 public BList(ListModel imodel) { 68 this(imodel, null); 69 } 70 71 84 BList(ListModel imodel, View iview) { 85 if (imodel!=null) setModel(imodel); 86 if (iview!=null) this.addView(iview); 87 } 88 89 90 91 92 96 static { 97 HTMLRendererFactory rfHTML = new HTMLRendererFactory(); 98 installRendererFactory(rfHTML, BList.class, HTMLElement.class); 99 installRendererFactory(rfHTML, BList.class, HTMLDocument.class); 100 } 101 102 105 static class HTMLRendererFactory implements RendererFactory { 106 public Renderer getInstance() {return new HTMLListRenderer();} 107 } 108 109 110 111 119 public void setModel(ListModel imodel) { 120 121 if (model!=null && callback!=null) { 123 model.removeModelListener(callback); 124 } 125 126 model = imodel; 128 invalidate(); 129 130 if (model!=null) { 132 if (callback==null) callback = new LocalModelListener(); 133 model.addModelListener(callback); 134 } 135 136 } 144 145 150 public ListModel getModel() { 151 if (model==null) setModel(new DefaultListModel()); 152 return model; 153 } 154 155 162 public void setListData(Object [] list) { 163 DefaultListModel lm = new DefaultListModel(); 164 if (list!=null) for (int i=0,max=list.length; i<max; i++) { 165 lm.add(list[i]); 166 } 167 setModel(lm); 168 } 169 170 176 public void setListData(Iterator it) { 177 DefaultListModel lm = new DefaultListModel(); 178 while (it.hasNext()) { 179 lm.add(it.next()); 180 } 181 setModel(lm); 182 } 183 184 192 208 209 210 211 216 public void destroyCycle() { 217 super.destroyCycle(); 219 220 setModel(null); 225 } 226 227 228 229 230 243 class LocalModelListener implements ModelListener { 244 public void modelChanged(Model m) { 246 invalidate(); 247 } 248 } 249 } | Popular Tags |