Class JavascriptRuntime

java.lang.Object
com.dlsc.gmapsfx.javascript.JavascriptRuntime
All Implemented Interfaces:
IJavascriptRuntime

public class JavascriptRuntime
extends Object
implements IJavascriptRuntime
Class for interacting with the JavaScript environment. This class is used by the JavaScript objects, but should not need to be used directly for creating or changing maps.
Author:
Rob Terpilowski
  • Field Details

  • Constructor Details

  • Method Details

    • getInstance

      public static IJavascriptRuntime getInstance()
      Gets a singleton instance of this class, creating one if it doesn't yet exist.
      Returns:
      A singleton instance
    • setDefaultWebEngine

      public static void setDefaultWebEngine​(IWebEngine e)
      Set the WebEngine that this runtime should use.
      Parameters:
      e - The underlying WebEngine to use.
    • execute

      public JSObject execute​(String command)
      Execute the specified command returning a value (if any)
      Specified by:
      execute in interface IJavascriptRuntime
      Parameters:
      command - The JavaScript command to execute
      Returns:
      The underlying JavaScript object that was returned by the script.
    • getConstructor

      public String getConstructor​(String javascriptObjectType, Object... args)
      Gets a constructor as a string which then can be passed to the execute().
      Specified by:
      getConstructor in interface IJavascriptRuntime
      Parameters:
      javascriptObjectType - The type of JavaScript object to create
      args - The args of the constructor
      Returns:
      A string which can be passed to the JavaScript environment to create a new object.
    • getArrayConstructor

      public String getArrayConstructor​(String javascriptObjectType, Object[] ary)
      Gets an array parameter constructor as a String, which then can be passed to the execute() method.
      Specified by:
      getArrayConstructor in interface IJavascriptRuntime
      Parameters:
      javascriptObjectType - type The type of JavaScript object array to create
      ary - The array elements
      Returns:
      A string which can be passed to the JavaScript environment to create a new array.
    • getFunction

      public String getFunction​(String variable, String function, Object... args)
      Gets a function as a String, which then can be passed to the execute() method.
      Specified by:
      getFunction in interface IJavascriptRuntime
      Parameters:
      variable - The variable to invoke the function on.
      function - The function to invoke
      args - Arguments the function requires
      Returns:
      A string which can be passed to the JavaScript environment to invoke the function
    • getFunction

      public String getFunction​(String function, Object... args)
      Gets a function as a String, which then can be passed to the execute() method.
      Specified by:
      getFunction in interface IJavascriptRuntime
      Parameters:
      function - The function to invoke
      args - Arguments the function requires
      Returns:
      A string which can be passed to the JavaScript environment to invoke the function
    • getArrayFunction

      public String getArrayFunction​(String function, Object[] ary)
      Gets an array function as a String, which then can be passed to the execute() method.
      Specified by:
      getArrayFunction in interface IJavascriptRuntime
      Parameters:
      function - The function to invoke
      ary - The array of arguments to pass to the function.
      Returns:
      A string which can be passed to the JavaScript environment to invoke the function
    • setJavascriptRuntime

      public static void setJavascriptRuntime​(IJavascriptRuntime testRuntime)
      Sets a Javascript runtime to use. Should only be used by unit tests to set a mock runtime
      Parameters:
      testRuntime - The runtime to use
    • getArgString

      protected String getArgString​(Object arg)
      Takes the specified object and converts the argument to a String.
      Parameters:
      arg - The object to convert
      Returns:
      A String representation of the argument.