Wednesday, February 26, 2014

Re: GWT and SVG, the 125th... :-)

Hi,

ok, I used the GWT ScriptInjector, and now also the identifier "SVG" can be resolved.
This brought me one step further, but now I get another error message:

[ERROR] [wgp] - Failed to load module 'wgp' from user agent 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36' at localhost:34277
com.google.gwt.core.client.JavaScriptException: (TypeError) @wgp.client.lib.GraphicsPanel::test()([]): Cannot read property 'nodeName' of null


I cannot debug JS code, but by tracing ($wnd.alert) I can verify that it happens at the call to SVG("drawing").

The complete code is shown below. What next? :-)

Magnus


Application.java:

public class Application implements EntryPoint
{
 public void onModuleLoad()
 {
  SampleLoader l = new SampleLoader();
  l.injectScript();
  
  final DrawBox dbx = new DrawBox ();
  dbx.setText ("Dialog Box");
  dbx.show ();
  
 }
}

SampleLoader.java:

public class SampleLoader
{
 public void injectScript()
 {
  String raw = SampleAssetsBundle.instance.myScript().getText();
  
  /*
  ScriptElement e = Document.get().createScriptElement();
  e.setText(raw);
  Document.get().getBody().appendChild(e);
  */
  
  ScriptInjector.fromString(raw).inject();
 }
}

SampleAssetBundle.java:

public interface SampleAssetsBundle extends ClientBundleWithLookup {

 public static final SampleAssetsBundle instance =
GWT.create(SampleAssetsBundle .class);

 @Source("svg.min.js")
 public TextResource myScript();
}


DrawBox.java:

public class DrawBox extends DialogBox
{
 //private FlowPanel pnl = new FlowPanel ();
 private GraphicsPanel pnl = new GraphicsPanel ();
 
 public DrawBox ()
 {
  super ();
  setText ("Dialog Box");
  
  pnl.setSize ("640px","480px");
  //add (pnl);
  setWidget (pnl);
  
  
  show ();
  center ();
  
 }
}

GraphicsPanel.java

public class GraphicsPanel extends ComplexPanel
{
 public GraphicsPanel()
 {
  Element e = test();
  setElement(e);
 }

 private static native Element test ()
 /*-{
 var draw = SVG('drawing')
 
 var text = draw.text('SVG.JS').move(300, 0)

 text.font({
          family: 'Source Sans Pro'
        , size: 180
        , anchor: 'middle'
        , leading: 1
        })

 return (draw);  
 }-*/; 

}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment