var draw = SVG('drawing').size(300, 300)var rect = draw.rect(100, 100).attr({ fill: '#f06' })
--
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-tool...@googlegroups.com.
To post to this group, send email to google-we...@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.
Also have a look at http://snapsvg.io/
The Cross-Site-Iframe linker does not support <script> tags in the gwt.xml files
var draw = SVG('drawing').size(300, 300)var rect = draw.rect(100, 100).attr({ fill: '#f06' })
FlowPanel p = new FlowPanel ();
myClientBundle.executeJSCode();p.add(???); // how to connect it???
--
One solution could be to create a GWT widget based on a DIV element and call the JSNI in the onLoad method.I did something similar with a Google Map widget.
FlowPanel p = new FlowPanel ();
myClientBundle.executeJSCode();
--
private native void setUpMap(Element div, JavaScriptObject mapOptions)/*-{var map = new $wnd.google.maps.Map(div, mapOptions);this.@com.emitrom.pilot.maps.client.GMapWidget::map = @com.emitrom.pilot.maps.client.GMap::new(Lcom/google/gwt/core/client/JavaScriptObject;)(map);}-*/;
If this script is used only under certain conditions, you can inject it when necessary using a ScriptInjector.
Both approaches work well.
But when call testSVG I get the following error:com.google.gwt.core.client.JavaScriptException: (ReferenceError) @wgp.client.lib.GraphicsPanel::test()([]): SVG is not defined
[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:34277com.google.gwt.core.client.JavaScriptException: (TypeError) @wgp.client.lib.GraphicsPanel::test()([]): Cannot read property 'nodeName' of null
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 ()
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::test1()([]): 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);
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);}-*/;}
In your GraphicsPanel.javatry to usevar draw = $wnd.SVG('drawing') instead of SVG
Object [object global] has no method 'SVG'
public class SvgEntryPoint implements EntryPoint { public class SvgWidget extends Widget { public SvgWidget() { setElement(Document.get().createDivElement()); // SVG library should draw inside the widget's container element drawExample(getElement()); } private native void drawExample(Element container) /*-{ var draw = SVG(container) // Must be used if JS is injected to top window, see below. // var draw = $wnd.SVG(container) draw.text('SVG.JS') }-*/; } public interface MyBundle extends ClientBundle { @Source("svg.min.js") TextResource svgJs(); } public void onModuleLoad() { MyBundle bundle = GWT.create(MyBundle.class); // Injects JS code into the GWT iframe. SvgWidget.drawExample() can use SVG() then. ScriptInjector.fromString(bundle.svgJs().getText()).inject(); // Injects JS code into the top level window. Now SvgWidget.drawExample() MUST use $wnd.SVG() // to reference the top level window. Only calling SVG() would mean to call it on the GWT iframe // to which the JS code has never been injected to. //ScriptInjector.fromString(bundle.svgJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject(); RootPanel.get().add(new SvgWidget()); } }
Working example: