Skip to content

Commit 5333b99

Browse files
author
Uemit Seren
committed
removed script inclusion in gwt.xml file and inject script via ScriptInjector. Processing can be used with xsiframe linker
1 parent b4159d0 commit 5333b99

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/at/gmi/nordborglab/processingjs/client/Processing.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package at.gmi.nordborglab.processingjs.client;
22

33
import com.google.gwt.canvas.client.Canvas;
4+
import com.google.gwt.core.client.ScriptInjector;
5+
import com.google.gwt.core.shared.GWT;
46
import com.google.gwt.http.client.Request;
57
import com.google.gwt.http.client.RequestBuilder;
68
import com.google.gwt.http.client.RequestCallback;
79
import com.google.gwt.http.client.RequestException;
810
import com.google.gwt.http.client.Response;
11+
import com.google.gwt.resources.client.ClientBundle;
912
import com.google.gwt.resources.client.ExternalTextResource;
1013
import com.google.gwt.resources.client.ResourceCallback;
1114
import com.google.gwt.resources.client.ResourceException;
@@ -16,6 +19,12 @@
1619

1720
public class Processing <I extends ProcessingInstance> extends Widget {
1821

22+
interface ProcessingClientBundle extends ClientBundle {
23+
ProcessingClientBundle INSTANCE = GWT.create(ProcessingClientBundle.class);
24+
25+
@Source("resources/processing.js")
26+
TextResource processingjs();
27+
}
1928

2029
protected String url;
2130
protected I p_instance;
@@ -24,6 +33,7 @@ public class Processing <I extends ProcessingInstance> extends Widget {
2433

2534
public Processing() {
2635
super();
36+
injectScript();
2737
canvas = createElement();
2838
setElement(canvas.getElement());
2939
}
@@ -91,14 +101,26 @@ public boolean isLoaded()
91101
protected native I init(String programm,Element elem) /*-{
92102
93103
instance = new $wnd.Processing(elem,programm);
94-
//$wnd.Processing.addInstance(instance);
95104
return instance;
96105
}-*/;
97106

98107

99108
public Canvas getCanvas() {
100109
return canvas;
101110
}
111+
112+
private void injectScript() {
113+
if (!isInjected()) {
114+
ScriptInjector.fromString(ProcessingClientBundle.INSTANCE.processingjs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
115+
}
116+
}
117+
118+
private native final boolean isInjected() /*-{
119+
if (!(typeof $wnd.Processing === "undefined") && !(null===$wnd.Processing)) {
120+
return true;
121+
}
122+
return false;
123+
}-*/;
102124
}
103125

104126

src/main/resources/at/gmi/nordborglab/processingjs/Processing.gwt.xml

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
<module rename-to='processing'>
33
<inherits name='com.google.gwt.user.User'/>
44
<source path='client'/>
5-
<script src="processing.js"></script>
65
</module>
76

0 commit comments

Comments
 (0)