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.renderer.*; 29 import org.enhydra.barracuda.core.comp.renderer.html.*; 30 import org.enhydra.barracuda.core.comp.renderer.xml.*; 31 import org.enhydra.barracuda.core.event.*; 32 import org.enhydra.barracuda.core.util.dom.DOMUtil; 33 import org.enhydra.barracuda.core.view.*; 34 import org.enhydra.barracuda.plankton.*; 35 36 48 public class BInput extends BComponent { 49 50 protected static final Logger logger = Logger.getLogger(BInput.class.getName()); 52 53 public static final String TEXT = "text"; 55 public static final String PASSWORD = "password"; 56 public static final String SUBMIT = "submit"; 57 public static final String RESET = "reset"; 58 public static final String FILE = "file"; 59 public static final String HIDDEN = "hidden"; 60 public static final String IMAGE = "image"; 61 public static final String BUTTON = "button"; 62 public static final String RADIO = "radio"; 63 public static final String CHECKBOX = "checkbox"; 64 65 protected List listeners = null; 67 protected String type = null; 68 protected String value = null; 69 protected boolean disableBackButton = false; 70 protected BAction baction = null; 72 75 private ListenerFactory lnkListenerFactory; 76 77 81 public BInput() {} 82 83 99 public BInput(String itype, String iname, String ivalue) { 100 this(itype, iname, ivalue, null, null); 101 } 102 103 123 BInput(String itype, String iname, String ivalue, View iview, ViewContext idvc) { 124 if (idvc!=null) setDefaultViewContext(idvc); 125 if (itype!=null) setType(itype); 126 if (iname!=null) setName(iname); 127 if (ivalue!=null) setValue(ivalue); 128 if (iview!=null) setView(iview); 129 } 130 131 132 133 134 138 static { 139 HTMLRendererFactory rfHTML = new HTMLRendererFactory(); 140 installRendererFactory(rfHTML, BInput.class, HTMLElement.class); 141 installRendererFactory(rfHTML, BInput.class, HTMLDocument.class); 142 143 } 144 145 148 static class HTMLRendererFactory implements RendererFactory { 149 public Renderer getInstance() {return new HTMLInputRenderer();} 150 } 151 152 153 154 155 165 public void setType(String itype) { 166 itype = itype.toLowerCase(); 167 if (itype!=null && !itype.equals(TEXT) && !itype.equals(PASSWORD) && 168 !itype.equals(SUBMIT) && !itype.equals(RESET) && 169 !itype.equals(FILE) && !itype.equals(HIDDEN) && 170 !itype.equals(IMAGE) && !itype.equals(BUTTON) && 171 !itype.equals(RADIO) && !itype.equals(CHECKBOX)) { 172 itype = TEXT; 173 } 174 type = itype; 175 invalidate(); 176 } 177 178 184 public String getType() { 185 return type; 186 } 187 188 194 public void setValue(Object ivalue) { 195 setValue(ivalue!=null ? ivalue.toString() : (String ) null); 196 } 197 198 207 public void setValue(String ivalue) { 208 value = ivalue; 209 invalidate(); 210 } 211 212 218 public String getValue() { 219 return value; 220 } 221 222 228 public void setAction(BAction ibaction) { 229 baction = ibaction; 230 } 231 232 238 public BAction getAction() { 239 return baction; 240 } 241 242 247 public void addEventListener(ListenerFactory lf) { 248 addEventListener(lf, false); 249 } 250 251 258 public void addEventListener(ListenerFactory lf, boolean idisableBackButton) { 259 if (lf==null) return; 260 disableBackButton = idisableBackButton; 261 if (listeners==null) listeners = new ArrayList(5); 262 listeners.add(lf); 263 invalidate(); 264 } 265 266 271 public void removeEventListener(ListenerFactory lf) { 272 if (lf==null) return; 273 if (listeners==null) return; 274 listeners.remove(lf); 275 invalidate(); 276 } 277 278 283 protected void preRender(ViewContext vc, int depth) { 284 if (baction!=null) this.addStepChild(baction, true); 287 if (listeners!=null) { 290 Iterator it = listeners.iterator(); 292 while (it.hasNext()) { 293 ListenerFactory lf = (ListenerFactory) it.next(); 294 295 326 BAction baComp = new BAction(); 327 baComp.setDisableBackButton(disableBackButton); 328 baComp.addEventListener(lf); 329 this.addStepChild(baComp, true); 330 } 332 } 333 } 334 335 343 358 } | Popular Tags |