1
1
package at .gmi .nordborglab .processingjs .client ;
2
2
3
3
import com .google .gwt .canvas .client .Canvas ;
4
+ import com .google .gwt .core .client .ScriptInjector ;
5
+ import com .google .gwt .core .shared .GWT ;
4
6
import com .google .gwt .http .client .Request ;
5
7
import com .google .gwt .http .client .RequestBuilder ;
6
8
import com .google .gwt .http .client .RequestCallback ;
7
9
import com .google .gwt .http .client .RequestException ;
8
10
import com .google .gwt .http .client .Response ;
11
+ import com .google .gwt .resources .client .ClientBundle ;
9
12
import com .google .gwt .resources .client .ExternalTextResource ;
10
13
import com .google .gwt .resources .client .ResourceCallback ;
11
14
import com .google .gwt .resources .client .ResourceException ;
16
19
17
20
public class Processing <I extends ProcessingInstance > extends Widget {
18
21
22
+ interface ProcessingClientBundle extends ClientBundle {
23
+ ProcessingClientBundle INSTANCE = GWT .create (ProcessingClientBundle .class );
24
+
25
+ @ Source ("resources/processing.js" )
26
+ TextResource processingjs ();
27
+ }
19
28
20
29
protected String url ;
21
30
protected I p_instance ;
@@ -24,6 +33,7 @@ public class Processing <I extends ProcessingInstance> extends Widget {
24
33
25
34
public Processing () {
26
35
super ();
36
+ injectScript ();
27
37
canvas = createElement ();
28
38
setElement (canvas .getElement ());
29
39
}
@@ -91,14 +101,26 @@ public boolean isLoaded()
91
101
protected native I init (String programm ,Element elem ) /*-{
92
102
93
103
instance = new $wnd.Processing(elem,programm);
94
- //$wnd.Processing.addInstance(instance);
95
104
return instance;
96
105
}-*/ ;
97
106
98
107
99
108
public Canvas getCanvas () {
100
109
return canvas ;
101
110
}
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
+ }-*/ ;
102
124
}
103
125
104
126
0 commit comments