1 20 package org.enhydra.barracuda.core.comp.scripting; 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.*; 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 import org.enhydra.barracuda.plankton.data.*; 36 37 38 51 public class BScript extends BComponent { 52 53 protected static final Logger logger = Logger.getLogger(BScript.class.getName()); 55 56 public static final int REPLACE = 0; 58 public static final int PREPEND = 1; 59 public static final int APPEND = 2; 60 61 public static final String ON_CLICK = "onclick"; 64 public static final String ON_DBL_CLICK = "ondblclick"; 65 public static final String ON_MOUSE_DOWN = "onmousedown"; 66 public static final String ON_MOUSE_UP = "onmouseup"; 67 public static final String ON_MOUSE_OVER = "onmouseover"; 68 public static final String ON_MOUSE_MOVE = "onmousemove"; 69 public static final String ON_MOUSE_OUT = "onmouseout"; 70 public static final String ON_KEY_PRESS = "onkeypress"; 71 public static final String ON_KEY_DOWN = "onkeydown"; 72 public static final String ON_KEY_UP = "onkeyup"; 73 public static final String ON_LOAD = "onload"; 75 public static final String ON_UNLOAD = "onunload"; 76 public static final String ON_FOCUS = "onfocus"; 78 public static final String ON_BLUR = "onblur"; 79 public static final String ON_SELECT = "onselect"; 81 public static final String ON_CHANGE = "onchange"; 83 public static final String ON_SUBMIT = "onsubmit"; 85 public static final String ON_RESET = "onreset"; 86 87 protected String jscmd = null; 89 protected String jsattr = null; 90 protected int mode = REPLACE; 91 protected List resources = null; 92 93 97 public BScript() {} 98 99 113 public BScript(String jsattr, String jscmd) { 114 this(jsattr, jscmd, REPLACE); 115 } 116 117 126 public BScript(String jsattr, String jscmd, int mode) { 127 this (jsattr, jscmd, mode, null); 128 } 129 130 140 public BScript(String jsattr, String jscmd, int mode, String resource) { 141 if (jsattr!=null) setAttr(jsattr); 142 if (jscmd!=null) setCmd(jscmd); 143 setMode(mode); 144 if (resource!=null) addResource(resource); 145 } 146 147 151 static { 152 HTMLRendererFactory rfHTML = new HTMLRendererFactory(); 153 installRendererFactory(rfHTML, BScript.class, HTMLElement.class); 154 installRendererFactory(rfHTML, BScript.class, HTMLDocument.class); 155 160 } 161 162 165 static class HTMLRendererFactory implements RendererFactory { 166 public Renderer getInstance() {return new HTMLScriptRenderer();} 167 } 168 169 170 171 177 public void setAttr(String ijsattr) { 178 jsattr = ijsattr; 179 invalidate(); 180 } 181 182 187 public String getAttr() { 188 return jsattr; 189 } 190 191 196 public void setCmd(String ijscmd) { 197 jscmd = ijscmd; 198 invalidate(); 199 } 200 201 206 public String getCmd() { 207 return jscmd; 208 } 209 210 219 public void setMode(int imode) { 220 if (imode!=PREPEND && imode!=APPEND) imode = REPLACE; 221 mode = imode; 222 invalidate(); 223 } 224 225 230 public int getMode() { 231 return mode; 232 } 233 234 240 public void addResource(String resource) { 241 if (resources==null) resources = new ArrayList(); 242 resources.add(resource); 243 invalidate(); 244 } 245 246 251 public void removeResource(String resource) { 252 if (resources==null) return; 253 resources.remove(resource); 254 invalidate(); 255 } 256 257 262 public List getResources() { 263 return resources; 264 } 265 266 267 275 290 293 public String toString() { 294 return jsattr+"=\""+jscmd+"\""; 295 } 296 297 } | Popular Tags |