1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwtwidgets.client.ui;
18
19 import org.gwtwidgets.client.ui.impl.PNGImageImpl;
20 import com.google.gwt.core.client.GWT;
21 import com.google.gwt.user.client.Event;
22 import com.google.gwt.user.client.ui.Image;
23
24
25 /***
26 * Image widget that overcomes PNG browser incompatabilities.
27 * Although meant for PNG images, it will work with any image
28 * format supported by the browser. If the image file ends
29 * with ".png" or ".PNG" it will use the PNG specific routines,
30 * otherwise will use generic non-PNG specific routines.
31 *
32 * The URL, width, and height are required at the creation of the
33 * widget, and may not be updated via the widget methogs. Calling
34 * setUrl() will throw a RuntimeException. This is in part due to
35 * the workarounds required for IE 5.5 and IE6.
36 *
37 * @author rhanson
38 */
39 public class PNGImage extends Image
40 {
41 private PNGImageImpl impl;
42
43
44 public PNGImage (String url, int width, int height)
45 {
46 impl = (PNGImageImpl) GWT.create(PNGImageImpl.class);
47
48 setElement(impl.createElement(url, width, height));
49 sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONLOAD | Event.ONERROR);
50 }
51
52
53 public String getUrl ()
54 {
55 return impl.getUrl(this);
56 }
57
58 /***
59 * Should not be used. Throws RuntimeException
60 */
61 public void setUrl (String url)
62 {
63 throw new RuntimeException("Not allowed to set url for a PNG image");
64 }
65 }