Package g3.project.core
Class Scripting
- java.lang.Object
-
- g3.project.core.Scripting
-
public final class Scripting extends java.lang.Object
- Author:
- Group 3
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLICK_FN
static java.lang.String
DRAG_FUNCTION
static java.lang.String
KEY_PRESS_FN
static java.lang.String
LOAD_FUNCTION
static java.lang.String
MOUSE_ENTER_FN
static java.lang.String
MOUSE_EXIT_FN
static java.lang.String
MOUSE_MOVED_FN
static java.lang.String
TOOL_CLOSE_FUNCTION
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
evalElement(Scriptable element)
Evaluate the script on a given element.void
evalString(java.lang.String code, java.lang.String lang)
Evaluate a string in the top-level context.protected void
evalString(java.lang.String code, java.lang.String lang, RecursiveBindings bindings)
Evaluate a string of code.java.util.Optional<java.lang.Object>
getGlobal(java.lang.String name)
Get a global variable.static RecursiveBindings
getTopLevelBindings()
Get Scripting global/top-level bindings.void
invokeOnElement(Scriptable element, java.lang.String function, java.lang.Object... args)
Invoke function on element.void
setGlobal(java.lang.String name, java.lang.Object glob)
Add an object to global bindings.
-
-
-
Field Detail
-
CLICK_FN
public static final java.lang.String CLICK_FN
- See Also:
- Constant Field Values
-
KEY_PRESS_FN
public static final java.lang.String KEY_PRESS_FN
- See Also:
- Constant Field Values
-
MOUSE_MOVED_FN
public static final java.lang.String MOUSE_MOVED_FN
- See Also:
- Constant Field Values
-
MOUSE_ENTER_FN
public static final java.lang.String MOUSE_ENTER_FN
- See Also:
- Constant Field Values
-
MOUSE_EXIT_FN
public static final java.lang.String MOUSE_EXIT_FN
- See Also:
- Constant Field Values
-
DRAG_FUNCTION
public static final java.lang.String DRAG_FUNCTION
- See Also:
- Constant Field Values
-
LOAD_FUNCTION
public static final java.lang.String LOAD_FUNCTION
- See Also:
- Constant Field Values
-
TOOL_CLOSE_FUNCTION
public static final java.lang.String TOOL_CLOSE_FUNCTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Scripting
public Scripting(java.lang.String defaultLanguage, Engine globalEngine, java.io.Writer writer)
Constructor.- Parameters:
defaultLanguage
- Default scripting language.globalEngine
- Ref to the engine.writer
- Default Output writer.
-
-
Method Detail
-
setGlobal
public void setGlobal(java.lang.String name, java.lang.Object glob)
Add an object to global bindings.- Parameters:
name
- Object name.glob
- Object.
-
getGlobal
public java.util.Optional<java.lang.Object> getGlobal(java.lang.String name)
Get a global variable.- Parameters:
name
- Variable name.- Returns:
- Maybe variable.
-
getTopLevelBindings
public static RecursiveBindings getTopLevelBindings()
Get Scripting global/top-level bindings.- Returns:
- RecursiveBindings
-
evalElement
public void evalElement(Scriptable element) throws javax.script.ScriptException, java.io.IOException
Evaluate the script on a given element. Required before invoking any functions.- Parameters:
element
- Element to eval script of.- Throws:
javax.script.ScriptException
- Couldn't eval script.java.io.IOException
- Couldn't get script.
-
evalString
protected void evalString(java.lang.String code, java.lang.String lang, RecursiveBindings bindings) throws javax.script.ScriptException
Evaluate a string of code. Provided for testing.- Parameters:
code
- Code to eval.lang
- Language.bindings
- Bindings to use.- Throws:
javax.script.ScriptException
- Bad script.
-
evalString
public void evalString(java.lang.String code, java.lang.String lang) throws javax.script.ScriptException
Evaluate a string in the top-level context.- Parameters:
code
- Code to evaluate.lang
- Language code is.- Throws:
javax.script.ScriptException
- Bad code.
-
invokeOnElement
public void invokeOnElement(Scriptable element, java.lang.String function, java.lang.Object... args) throws javax.script.ScriptException, java.io.IOException
Invoke function on element.- Parameters:
element
- Element to start with.function
- Function to try and call.args
- Arguments to function.- Throws:
javax.script.ScriptException
- Bad Script.java.io.IOException
- Couldn't read file.
-
-