33import org .renjin .sexp .StringVector ;
44
55import processing .core .PApplet ;
6+ import rprocessing .exception .NotFoundException ;
7+
8+ import javax .script .ScriptEngine ;
9+ import javax .script .ScriptEngineManager ;
10+ import javax .script .ScriptException ;
11+
12+ import org .renjin .parser .RParser ;
13+ import org .renjin .script .RenjinScriptEngine ;
14+ import org .renjin .sexp .Closure ;
15+ import org .renjin .sexp .ExpressionVector ;
16+ import org .renjin .sexp .FunctionCall ;
17+ import org .renjin .sexp .SEXP ;
18+ import org .renjin .sexp .Symbol ;
619
720/**
821 * BuiltinApplet is the type to refactor the function calls.
@@ -14,6 +27,20 @@ public class BuiltinApplet extends PApplet {
1427 /*
1528 * TODO: Check for the cast.
1629 */
30+ /** Engine to interpret R code */
31+ protected final RenjinScriptEngine renjinEngine ;
32+
33+ public BuiltinApplet () throws NotFoundException {
34+ // Create a script engine manager.
35+ ScriptEngineManager manager = new ScriptEngineManager ();
36+ // Create a Renjin engine.
37+ ScriptEngine engine = manager .getEngineByName ("Renjin" );
38+ // Check if the engine has loaded correctly.
39+ if (engine == null ) {
40+ throw new NotFoundException ("Renjin Script Engine not found on the classpath." );
41+ }
42+ this .renjinEngine = (RenjinScriptEngine ) engine ;
43+ }
1744
1845 public void size (double width , double height ) {
1946 super .size ((int ) width , (int ) height );
@@ -34,4 +61,37 @@ public boolean getFocused() {
3461 public double getPI () {
3562 return PI ;
3663 }
64+
65+ /**
66+ *
67+ * @see processing.core.PApplet#focusGained()
68+ */
69+ @ Override
70+ public void focusGained () {
71+ super .focusGained ();
72+ this .renjinEngine .put ("focused" ,super .focused );
73+ }
74+
75+ /**
76+ *
77+ * @see processing.core.PApplet#focusLost()
78+ */
79+ @ Override
80+ public void focusLost () {
81+ super .focusLost ();
82+ this .renjinEngine .put ("focused" ,super .focused );
83+ }
84+
85+ @ Override
86+ public void mouseMoved () {
87+ wrapMouseVariables ();
88+ }
89+
90+ protected void wrapMouseVariables () {
91+ this .renjinEngine .put ("mouseX" , mouseX );
92+ this .renjinEngine .put ("mouseY" , mouseY );
93+ this .renjinEngine .put ("pmouseX" , pmouseX );
94+ this .renjinEngine .put ("pmouseY" , pmouseY );
95+ //this.renjinEngine.put("mouseButton", mouseButton);
96+ }
3797}
0 commit comments