1 21 24 package org.lobobrowser.html.domimpl; 25 26 import java.util.*; 27 28 import org.lobobrowser.html.js.*; 29 import org.mozilla.javascript.Function; 30 import org.w3c.dom.html2.HTMLImageElement; 31 32 public class HTMLImageElementImpl extends HTMLAbstractUIElement implements 33 HTMLImageElement { 34 public HTMLImageElementImpl() { 35 super("IMG"); 36 } 37 38 public HTMLImageElementImpl(String name) { 39 super(name); 40 } 41 42 public String getName() { 43 return this.getAttribute("name"); 44 } 45 46 public void setName(String name) { 47 this.setAttribute("name", name); 48 } 49 50 public String getAlign() { 51 return this.getAttribute("align"); 52 } 53 54 public void setAlign(String align) { 55 this.setAttribute("align", align); 56 } 57 58 public String getAlt() { 59 return this.getAttribute("alt"); 60 } 61 62 public void setAlt(String alt) { 63 this.setAttribute("alt", alt); 64 } 65 66 public String getBorder() { 67 return this.getAttribute("border"); 68 } 69 70 public void setBorder(String border) { 71 this.setAttribute("border", border); 72 } 73 74 public int getHeight() { 75 UINode r = this.uiNode; 76 return r == null ? 0 : r.getBounds().height; 77 } 78 79 public void setHeight(int height) { 80 this.setAttribute("height", String.valueOf(height)); 81 } 82 83 public int getHspace() { 84 return this.getAttributeAsInt("hspace", 0); 85 } 86 87 public void setHspace(int hspace) { 88 this.setAttribute("hspace", String.valueOf("hspace")); 89 } 90 91 public boolean getIsMap() { 92 return this.getAttributeAsBoolean("isMap"); 93 } 94 95 public void setIsMap(boolean isMap) { 96 this.setAttribute("isMap", isMap ? "isMap" : null); 97 } 98 99 public String getLongDesc() { 100 return this.getAttribute("longDesc"); 101 } 102 103 public void setLongDesc(String longDesc) { 104 this.setAttribute("longDesc", longDesc); 105 } 106 107 public String getSrc() { 108 return this.getAttribute("src"); 109 } 110 111 116 public void setSrc(String src) { 117 this.setAttribute("src", src); 118 } 119 120 public String getUseMap() { 121 return this.getAttribute("useMap"); 122 } 123 124 public void setUseMap(String useMap) { 125 this.setAttribute("useMap", useMap); 126 } 127 128 public int getVspace() { 129 return this.getAttributeAsInt("vspace", 0); 130 } 131 132 public void setVspace(int vspace) { 133 this.setAttribute("vspace", String.valueOf(vspace)); 134 } 135 136 public int getWidth() { 137 UINode r = this.uiNode; 138 return r == null ? 0 : r.getBounds().width; 139 } 140 141 public void setWidth(int width) { 142 this.setAttribute("width", String.valueOf(width)); 143 } 144 145 159 173 177 215 216 protected void assignAttributeField(String normalName, String value) { 217 super.assignAttributeField(normalName, value); 218 if("src".equals(normalName)) { 219 this.loadImage(value); 220 } 221 } 222 223 private Function onload; 224 225 public Function getOnload() { 226 return this.getEventFunction(this.onload, "onload"); 227 } 228 229 public void setOnload(Function onload) { 230 this.onload = onload; 231 } 232 233 private java.awt.Image image = null; 234 private String imageSrc; 235 236 private void loadImage(String src) { 237 HTMLDocumentImpl document = (HTMLDocumentImpl) this.document; 238 if(document != null) { 239 synchronized(this.listeners) { 240 this.imageSrc = src; 241 this.image = null; 242 } 243 if(src != null) { 244 document.loadImage(src, new LocalImageListener(src)); 245 } 246 } 247 } 248 249 public final java.awt.Image getImage() { 250 synchronized(this.listeners) { 251 return this.image; 252 } 253 } 254 255 private final ArrayList listeners = new ArrayList(1); 256 257 263 public void addImageListener(ImageListener listener) { 264 ArrayList l = this.listeners; 265 java.awt.Image currentImage; 266 synchronized(l) { 267 currentImage = this.image; 268 l.add(listener); 269 } 270 if(currentImage != null) { 271 listener.imageLoaded(new ImageEvent(this, currentImage)); 274 } 277 } 278 279 public void removeImageListener(ImageListener listener) { 280 ArrayList l = this.listeners; 281 synchronized(l) { 282 l.remove(l); 283 } 284 } 285 286 private void dispatchEvent(String expectedImgSrc, ImageEvent event) { 287 ArrayList l = this.listeners; 288 ImageListener[] listenerArray; 289 synchronized(l) { 290 if(!expectedImgSrc.equals(this.imageSrc)) { 291 return; 292 } 293 this.image = event.image; 294 listenerArray = (ImageListener[]) l.toArray(ImageListener.EMPTY_ARRAY); 296 } 297 int llength = listenerArray.length; 298 for(int i = 0; i < llength; i++) { 299 listenerArray[i].imageLoaded(event); 301 } 302 Function onload = this.getOnload(); 303 if(onload != null) { 304 Executor.executeFunction(HTMLImageElementImpl.this, onload, null); 306 } 307 } 308 309 private class LocalImageListener implements ImageListener { 310 private final String expectedImgSrc; 311 312 public LocalImageListener(String imgSrc) { 313 this.expectedImgSrc = imgSrc; 314 } 315 316 public void imageLoaded(ImageEvent event) { 317 dispatchEvent(this.expectedImgSrc, event); 318 } 319 } 320 } 321 | Popular Tags |