I want to wrap a CanvasElement (<canvas> in HTML) in an Canvas widget.

Many widgets (e.g. Label) have a static method SomeWidget.wrap(Element) for 
wrapping an existing DOM element.
I imagine Canvas does not feature such a method because not all browser 
support <canvas> and therefore the user should be forced to go 
through createIfSupported().

Unfortunately the constructor in Canvas is private, which means that Canvas 
can not be subclassed. (There isn't any constructor available in the derived 
class.)

Code snippets of createIfSupported and the constructor in Canvas:

  public static Canvas createIfSupported() {
    // check if canvas is supported; if it is not supported: return null
    return new Canvas(element);
  }

  private Canvas(CanvasElement element) {
    setElement(element);
  }

I ended up copying the Canvas class and making the constructor public.

Is there a better way to do this?
If not, what is the reasoning behind it (besides that it might not be 
supported)?

I am using version 2.4.0.rc1.

Thanks,
Julian

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/MpcJQFQy4BAJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to