Class CefUtils

java.lang.Object
provided.owlMaps.cefUtils.impl.CefUtils
All Implemented Interfaces:
ICefUtils

public final class CefUtils
extends java.lang.Object
implements ICefUtils
Implementation of ICefUtils
Author:
swong
  • Field Summary

    Fields
    Modifier and Type Field Description
    private org.cef.browser.CefMessageRouter callbackMsgRouter
    The message router to use for callbacks from the JavaScript side.
    (package private) org.cef.browser.CefBrowser cefBrowser
    The current CefBrowser instance holding the frame that holds the map
    private org.cef.CefClient cefClient
    The CEF client object
    (package private) org.cef.browser.CefFrame cefFrame
    The current CefFrame holding the map in the browser
    (package private) ICefObject cefMap
    The current map object being held in the browser
    private ICefObjectFactory cefObjFac
    The factory to use to create ICefObjects
    private java.util.Map<java.util.UUID,​java.util.function.Consumer<?>> consumerCallbackMap
    The map of Consumer function ID's to the Consumer itself.
    private long devToolsDelay
    The current delay to use before creating and displaying the dev tools window
    private java.lang.String googleMapsApiKey
    The Google Maps API key in use
    private com.google.gson.Gson gson
    GSON JSON converter to use for data transmission to/from the JavaScript side
    (package private) boolean isTransparent
    If true the browser background is transparent
    private static java.lang.String JS_CALL_FN_FORMAT
    Format string for JavaScript call to run a given window function.
    private boolean makeDevTools
    If true, create the dev tools window after the current devToolsDelay
    private org.cef.browser.CefMessageRouter objCreateMsgRouter
    The message router to use when creating objects on the JavaScript side
    private java.util.Map<java.util.UUID,​java.util.function.Consumer<?>> pendingReturnValMap
    The map of Consumer function ID's to the Consumer itself where the Consumer is used for processing returned values from the JavaScript side.
    private org.cef.browser.CefMessageRouter returnValMsgRouter
    The message router to use for return values from JavaScript method calls.
    private java.util.Map<java.util.UUID,​java.lang.Runnable> runnableCallbackMap
    The map of Runnable function ID's to the Runnable itself.
    private ISystemInfo sysInfo
    Accessors for accessing dynamic system values
    private boolean useOSR
    If true, use Off-Screen Rendering
  • Constructor Summary

    Constructors
    Constructor Description
    CefUtils​(java.lang.String googleMapsApiKey, ISystemInfo sysInfo)
    Constructor for the class
  • Method Summary

    Modifier and Type Method Description
    <T> java.util.concurrent.Future<T> call​(java.lang.String fnName, java.lang.reflect.Type returnType, java.lang.Object... params)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Call the specified Javascript functuion with the given parameters and return the result as a Future
    void callVoid​(java.lang.String fnName, java.lang.Object... params)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    A call to the given Javascript function that is a void return
    <T> T convertJsonMap​(T x, java.lang.reflect.Type resultType)
    Converts the given object into the given result type by converting back to JSON and sending back through the GSON parser.
    ICefObject getCefMapObj()
    Get the ICefObject that wraps the Javascript map entity
    double getSysLengthPerMeter()
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Get the conversion factor from the length units currently being used by the system into meters.
    ICefObject makeCefObj​(java.lang.String jsClassname, java.lang.Object... params)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Instantiate the given class on the JavaScript side with the given parameters
    java.util.UUID registerConsumerCallback​(java.util.function.Consumer<?> callback)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Register the given Consumer in the system so that it can be used for callbacks.
    java.util.UUID registerPendingReturnValCallback​(java.util.function.Consumer<?> callback)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Register the given Consumer in the system so that it can be used for return values of function calls.
    java.util.UUID registerRunnableCallback​(java.lang.Runnable callback)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Register the given Runnable in the system so that it can be used for callbacks.
    void setDevToolsDelay​(long delay)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Sets the delay to wait before opening the dev tools window.
    void setDevToolsPort​(int port)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Set the port used by the dev tools window
    void setMakeDevTools​(boolean makeDevTools)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Enables the display of the browser dev console window
    void setUseOSR​(boolean useOSR)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Sets whether or not the system uses the Off-Screen Rendering (OSR).
    javax.swing.JComponent start​(java.lang.String startURL, provided.mixedData.IMixedDataDictionary mapOptionsDict, java.lang.Runnable onMapLoad)
    *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
    Start the Map on the Javascript side

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • JS_CALL_FN_FORMAT

      private static final java.lang.String JS_CALL_FN_FORMAT
      Format string for JavaScript call to run a given window function.
      See Also:
      Constant Field Values
    • sysInfo

      private final ISystemInfo sysInfo
      Accessors for accessing dynamic system values
    • googleMapsApiKey

      private final java.lang.String googleMapsApiKey
      The Google Maps API key in use
    • cefClient

      private final org.cef.CefClient cefClient
      The CEF client object
    • gson

      private com.google.gson.Gson gson
      GSON JSON converter to use for data transmission to/from the JavaScript side
    • isTransparent

      boolean isTransparent
      If true the browser background is transparent
    • makeDevTools

      private boolean makeDevTools
      If true, create the dev tools window after the current devToolsDelay
    • devToolsDelay

      private long devToolsDelay
      The current delay to use before creating and displaying the dev tools window
    • useOSR

      private boolean useOSR
      If true, use Off-Screen Rendering
    • cefObjFac

      private ICefObjectFactory cefObjFac
      The factory to use to create ICefObjects
    • callbackMsgRouter

      private org.cef.browser.CefMessageRouter callbackMsgRouter
      The message router to use for callbacks from the JavaScript side. The callbacks are assumed to be persistent and utilized multiple times.
    • objCreateMsgRouter

      private org.cef.browser.CefMessageRouter objCreateMsgRouter
      The message router to use when creating objects on the JavaScript side
    • returnValMsgRouter

      private org.cef.browser.CefMessageRouter returnValMsgRouter
      The message router to use for return values from JavaScript method calls. The callbacks are assumed to be single use for a particular function call's return value.
    • runnableCallbackMap

      private java.util.Map<java.util.UUID,​java.lang.Runnable> runnableCallbackMap
      The map of Runnable function ID's to the Runnable itself.
    • consumerCallbackMap

      private java.util.Map<java.util.UUID,​java.util.function.Consumer<?>> consumerCallbackMap
      The map of Consumer function ID's to the Consumer itself.
    • pendingReturnValMap

      private java.util.Map<java.util.UUID,​java.util.function.Consumer<?>> pendingReturnValMap
      The map of Consumer function ID's to the Consumer itself where the Consumer is used for processing returned values from the JavaScript side.
    • cefBrowser

      org.cef.browser.CefBrowser cefBrowser
      The current CefBrowser instance holding the frame that holds the map
    • cefFrame

      org.cef.browser.CefFrame cefFrame
      The current CefFrame holding the map in the browser
    • cefMap

      ICefObject cefMap
      The current map object being held in the browser
  • Constructor Details

    • CefUtils

      public CefUtils​(java.lang.String googleMapsApiKey, ISystemInfo sysInfo)
      Constructor for the class
      Parameters:
      googleMapsApiKey - The Google Maps API key to use
      sysInfo - ISytemInfo object to provide dynamically set system-wide info such as the unit of length in use.
  • Method Details

    • start

      public javax.swing.JComponent start​(java.lang.String startURL, provided.mixedData.IMixedDataDictionary mapOptionsDict, java.lang.Runnable onMapLoad)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Start the Map on the Javascript side
      Specified by:
      start in interface ICefUtils
      Parameters:
      startURL - The URL with which to open the map
      mapOptionsDict - A dictionary of IMapOptions options
      onMapLoad - Callback to run after the map is loaded
      Returns:
      A JComponent that can be displayed on the view.
    • setDevToolsDelay

      public void setDevToolsDelay​(long delay)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Sets the delay to wait before opening the dev tools window. The dev tools window needs to be delayed so that it can show what's happening in the map.
      Specified by:
      setDevToolsDelay in interface ICefUtils
      Parameters:
      delay - The number of milliseconds to delay
    • setUseOSR

      public void setUseOSR​(boolean useOSR)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Sets whether or not the system uses the Off-Screen Rendering (OSR).
      Specified by:
      setUseOSR in interface ICefUtils
      Parameters:
      useOSR - If true, use OSR
    • setDevToolsPort

      public void setDevToolsPort​(int port)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Set the port used by the dev tools window
      Specified by:
      setDevToolsPort in interface ICefUtils
      Parameters:
      port - A valid port number not being used by any other app.
    • setMakeDevTools

      public void setMakeDevTools​(boolean makeDevTools)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Enables the display of the browser dev console window
      Specified by:
      setMakeDevTools in interface ICefUtils
      Parameters:
      makeDevTools - If true, show the dev console window
    • getCefMapObj

      public ICefObject getCefMapObj()
      Description copied from interface: ICefUtils
      Get the ICefObject that wraps the Javascript map entity
      Specified by:
      getCefMapObj in interface ICefUtils
      Returns:
      The ICefObject for the map
    • callVoid

      public void callVoid​(java.lang.String fnName, java.lang.Object... params)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      A call to the given Javascript function that is a void return
      Specified by:
      callVoid in interface ICefUtils
      Parameters:
      fnName - The name of the Javascript function to invoke
      params - A vararg of parameters to pass to the function
    • call

      public <T> java.util.concurrent.Future<T> call​(java.lang.String fnName, java.lang.reflect.Type returnType, java.lang.Object... params)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Call the specified Javascript functuion with the given parameters and return the result as a Future
      Specified by:
      call in interface ICefUtils
      Type Parameters:
      T - The type of the return value
      Parameters:
      fnName - The Javascript function to call
      returnType - TODO
      params - Vararg of parameters with which to invoke the function
      Returns:
      The return value of the function, available when ready.
    • registerRunnableCallback

      public java.util.UUID registerRunnableCallback​(java.lang.Runnable callback)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Register the given Runnable in the system so that it can be used for callbacks.
      Specified by:
      registerRunnableCallback in interface ICefUtils
      Parameters:
      callback - The Runnable to register
      Returns:
      A unique ID associated with the given Runnable.
    • registerConsumerCallback

      public java.util.UUID registerConsumerCallback​(java.util.function.Consumer<?> callback)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Register the given Consumer in the system so that it can be used for callbacks. The callback is assumed to be persistent and used multiple times.
      Specified by:
      registerConsumerCallback in interface ICefUtils
      Parameters:
      callback - The Consumer to register
      Returns:
      A unique ID associated with the given Consumer
    • registerPendingReturnValCallback

      public java.util.UUID registerPendingReturnValCallback​(java.util.function.Consumer<?> callback)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Register the given Consumer in the system so that it can be used for return values of function calls. The callback is assumed to be single use and must be removed from the mapping when executed.
      Specified by:
      registerPendingReturnValCallback in interface ICefUtils
      Parameters:
      callback - The Consumer to register
      Returns:
      A unique ID associated with the given Consumer
    • convertJsonMap

      public <T> T convertJsonMap​(T x, java.lang.reflect.Type resultType)
      Converts the given object into the given result type by converting back to JSON and sending back through the GSON parser.
      Specified by:
      convertJsonMap in interface ICefUtils
      Type Parameters:
      T - The type of the original object
      Parameters:
      x - The original object
      resultType - The desired type of the result
      Returns:
      An object of the desired type, not usually the same instance as the given object
    • getSysLengthPerMeter

      public double getSysLengthPerMeter()
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Get the conversion factor from the length units currently being used by the system into meters.
      Specified by:
      getSysLengthPerMeter in interface ICefUtils
      Returns:
      A length conversion factor of system_units/meter
    • makeCefObj

      public ICefObject makeCefObj​(java.lang.String jsClassname, java.lang.Object... params)
      Description copied from interface: ICefUtils
      *** FOR INTERNAL USE ONLY!! DEVELOPER CODE SHOULD NEVER USE THIS METHOD DIRECTLY! ***
      Instantiate the given class on the JavaScript side with the given parameters
      Specified by:
      makeCefObj in interface ICefUtils
      Parameters:
      jsClassname - The name of the class to instantiate
      params - The class's constructor parameters
      Returns:
      An ICefObject representing the instantiated JavaScript object. The object is NOT to be considered viable until it is able to return a valid ID value.