Menu

#43 PNGImage (GWT-WL 0.2.0) Bug in GWT 1.5RC1

open
nobody
None
5
2008-06-06
2008-06-06
Anonymous
No

Error occurred while initializing PNGImage:

[ERROR] Unable to load module entry point class org.example.Main (see associated exception for details)
java.lang.AssertionError: Element may only be set once
at com.google.gwt.user.client.ui.UIObject.setElement(UIObject.java:802)
at org.gwtwidgets.client.ui.PNGImage.<init>(PNGImage.java:48)
at org.gwtwidgets.client.ui.LightBox.show(LightBox.java:85)
...

Because of this error LightBox.show() also generates error.

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Agree, please fix this.

     
  • Nobody/Anonymous

    Logged In: NO

    +1

     
  • Nobody/Anonymous

    Logged In: NO

    +1
    Does someone look into it?

     
  • Nobody/Anonymous

    Please solve this problem or suggest a workaround, it is an annoying situation not being able to use LightBox anymore...

     
  • Nobody/Anonymous

    looks like the only workaround is to:

    1. move PNGImage to the com.google.gwt.user.client.ui package
    2. use replaceElement instead of setElement in the PNGImage constructor

     
  • Nobody/Anonymous

    I was able to get thsi working by rewriting PNGImage to be a Composite:

    public class PNGImage extends Composite {
    private PNGImageImpl impl;
    private Widget widget;
    public PNGImage(String url, int width, int height) {
    impl = (PNGImageImpl) GWT.create(PNGImageImpl.class);
    impl.createImage(url,height,width);
    initWidget(impl.getWidget());
    sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONLOAD | Event.ONER
    ROR);
    }
    public String getUrl() {
    return impl.getUrl();
    }

    /**
    * Should not be used. Throws RuntimeException
    */
    public void setUrl (String url) {
    throw new RuntimeException("Not allowed to set url for a PNG image");
    }

    }

    and changing both Impls:

    public class PNGImageImpl {
    protected Widget img = null;

    public void createImage(String url, int height, int width) {
    if (img == null) {
    img = new Image(url);
    }
    DOM.setElementPropertyInt(img.getElement(), "width", width);
    DOM.setElementPropertyInt(img.getElement(), "height", height);
    }

    public String getUrl() {
    return DOM.getElementProperty(img.getElement(), "src");
    }

    public Widget getWidget() {
    return img;
    }
    }

    public class PNGImageImplIE6 extends PNGImageImpl {
    private String url;

    public void createImage(String url, int height, int width) {
    this.url = url;

    boolean isPNG = url.endsWith(".png") || url.endsWith(".PNG");

    if (img == null) {
    if (isPNG) {
    final Element div = DOM.createDiv();
    DOM.setInnerHTML(div, "<span style=\"display:inline-block;wi
    dth:" +
    width + "px;height:" + height +
    "px;filter:progid:DXImageTransform.Microsoft.Alp
    haImageLoader(src='" +
    url + "', sizingMethod='scale')\"></span>");
    img = new Widget(){
    {
    setElement(DOM.getFirstChild(div));
    }
    };

    } else {
    super.createImage(url, height, width);
    }
    }

    }

    public String getUrl() {
    return url;
    }
    }

    Unfortunately, this breaks ImageButton and ToggleButton, but I wasn't using those.

    Hope this helps.
    Dan

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.