This is what I effectively have today, but my point was that JSO's
can't subclass CanvasImpl. It is not the Canvas object that needs to
be a JSO, it's the CanvasImpl object, because it is the CanvasImpl
object that has the JSNI methods on it which directly interact with
the browser's native canvas.

Today, I have a wrapper for CanvasImpl, it looks sorta like this:

public class BrowserCanvasImpl extends CanvasImpl {
  private JavaScriptObject ctx;

  public native void moveTo(int x, int y) /*-{
    [EMAIL PROTECTED]::ctx.moveTo(x,y);
  }-*/;
}

What I really want is this:

public class BrowserCanvasImpl extends JavaScriptObject {
   public native void moveTo(int x, int y) /*-{
     this.moveTo(x,y);
  }-*/;
}

public class FlashCanvasImpl extends JavaScriptObject {
  public native void moveTo(int x, int y) /*-{
      flashObject.drawCommand('m', x, y);
  }-*/;
}

And the ability to bind either one of these based on deferred binding.
This returns the generated JavaScript output from:

foo.ctx.moveTo(x,y);

to

foo.moveTo(x,y);  or foo.drawCommand('m', x,y);


Here's a question. What if CanvasImpl was a JSO with a bunch of stub
methods (non-final), and each subclass of CanvasImpl overrode every
stub method with a final method, would it still work?   Actually, the
final isn't needed. In a sense, if due to a deferred binding, only a
single concrete subclass implementation exists, and no method dispatch
on CanvasImpl is ever polymorphic, then everything is "effectively"
final and it should work.  Couldn't the JSO restriction checker be a
little more lenient and just prove in each permutation that no virtual
dispatches occur?

-Ray


On Fri, Aug 29, 2008 at 3:40 PM, Scott Blum <[EMAIL PROTECTED]> wrote:
> What about this?
> public final class Canvas extends JavaScriptObject {
>   private static CanvasImpl impl = GWT.create(CanvasImpl.class);
>   public static Canvas create()  {
>     return impl.create();
>   }
>   public void moveTo(int x, int y)  {
>     return impl.moveTo(this, x, y);
>   }
> }
> Then you just create several subclasses of CanvasImpl, for Canvas, Flash,
> SVG, etc.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to