Class JavascriptObject

java.lang.Object
com.dlsc.gmapsfx.javascript.JavascriptObject
Direct Known Subclasses:
DirectionsGeocodedWaypoint, DirectionsLeg, DirectionsPane, DirectionsRenderer, DirectionsRequest, DirectionsResult, DirectionsRoute, DirectionsService, DirectionsSteps, DirectionsWaypoint, Distance, DrivingOptions, Duration, ElevationResult, ElevationService, GeocoderAddressComponent, GeocoderComponentRestrictions, GeocoderGeometry, GeocoderRequest, GeocodingResult, GeocodingService, GMapPoint, GoogleMap, InfoWindow, InfoWindowOptions, JavascriptArray, JavascriptFunction, LatLong, LatLongBounds, LocationElevationRequest, MapOptions, MapShape, MapShapeOptions, Marker, MarkerClusterer, MarkerOptions, MaxZoomResult, MaxZoomService, MVCArray, PathElevationRequest, Projection, Size

public class JavascriptObject
extends Object
Base class for any Google JavaScript object.
Author:
Rob Terpilowski
  • Field Details

  • Constructor Details

    • JavascriptObject

      protected JavascriptObject()
    • JavascriptObject

      protected JavascriptObject​(String type)
      Parameters:
      type - The type of underlying Javascript object to create
    • JavascriptObject

      protected JavascriptObject​(String type, String stringRepresentation)
      Builds a new JavascriptObject based on a string representation of the object. This is useful when constructing functions as objects
      Parameters:
      type - The type of object to build
      stringRepresentation - A string representation of the object, which can be executed by the Javascript runtime.
    • JavascriptObject

      protected JavascriptObject​(String type, Object... args)
      Parameters:
      type - The type of underlying Javascript object to create.
      args - Any arguments required to create the object.
    • JavascriptObject

      protected JavascriptObject​(String type, Object[] ary, boolean isArray)
      Parameters:
      type - The type of underlying Javascript object to create.
      ary - The array to be passed in.
      isArray - boolean to indicate the an array is to be used as the parameter rather than breaking up into individual parameters.
    • JavascriptObject

      protected JavascriptObject​(String type, JSObject jsObject)
      Wraps a Javascript JSObject returned from a function.
      Parameters:
      type - Type of Javascript object to create.
      jsObject - Object returned from Javascript.
  • Method Details

    • getJSObject

      public JSObject getJSObject()
      Get the underlying object used by the Javascript runtime.
      Returns:
      The underlying Javascript object
    • getNextVariableName

      protected final String getNextVariableName()
      Gets the name of the next variable which will be the objectname plus a unique number
      Returns:
      The name of the next variable to create
    • getVariableName

      public String getVariableName()
      Gets the name of this variable within the Javascript runtime
      Returns:
      The name of this variable.
    • setProperty

      protected void setProperty​(String propertyName, Object propertyValue)
      Sets a property on this Javascript object.
      Parameters:
      propertyName - The property name
      propertyValue - The property value.
    • setProperty

      protected void setProperty​(String propertyName, JavascriptObject propertyValue)
      Sets a property on this Javascript object for which the value is a Javascript object itself.
      Parameters:
      propertyName - The name of the property.
      propertyValue - The value of the property.
    • setProperty

      protected void setProperty​(String propertyName, JavascriptEnum propertyValue)
      Sets a property on this Javascript object for which the value is a JavascriptEnum The value is set to what is returned by the getEnumValue() method on the JavascriptEnum
      Parameters:
      propertyName - The name of the property.
      propertyValue - The value of the property.
    • getProperty

      protected Object getProperty​(String key)
      Get the specified property for this object.
      Parameters:
      key - The property name
      Returns:
      The value of the property
    • getProperty

      protected <T> T getProperty​(String key, Class<T> type)
      Gets the property and casts to the appropriate type
      Type Parameters:
      T -
      Parameters:
      key - The property name
      type - The property type
      Returns:
      The value of the property
    • invokeJavascript

      protected Object invokeJavascript​(String function)
      Invokes a JavaScript function that takes no arguments.
      Parameters:
      function - The function to invoke
      Returns:
      The return value of the function call.
    • invokeJavascript

      protected Object invokeJavascript​(String function, Object... args)
      Invoke the specified JavaScript function in the JavaScript runtime.
      Parameters:
      function - The function to invoke
      args - Any arguments to pass to the function
      Returns:
      The result of the function.
    • invokeJavascriptReturnValue

      protected <T> T invokeJavascriptReturnValue​(String function, Class<T> returnType)
      Invokes a JavaScript function that takes no arguments.
      Type Parameters:
      T -
      Parameters:
      function - The function to invoke
      returnType - The type of object to return
      Returns:
      The result of the function.
    • invokeJavascriptReturnValue

      protected <T> T invokeJavascriptReturnValue​(String function, Class<T> returnType, Object... args)
      Invoke the specified JavaScript function in the JavaScript runtime.
      Type Parameters:
      T -
      Parameters:
      function - The function to invoke
      returnType - The type of object to return
      args - Any arguments to pass to the function
      Returns:
      The result of the function.
    • isMemberDefined

      protected boolean isMemberDefined​(String member)
    • checkUndefined

      protected Object checkUndefined​(Object val)
      JSObject will return the String "undefined" at certain times, so we need to make sure we're not getting a value that looks valid, but isn't.
      Parameters:
      val - The value from Javascript to be checked.
      Returns:
      Either null or the value passed in.
    • checkBoolean

      protected Boolean checkBoolean​(Object val, Boolean def)
      Checks a returned Javascript value where we expect a boolean but could get null.
      Parameters:
      val - The value from Javascript to be checked.
      def - The default return value, which can be null.
      Returns:
      The actual value, or if null, returns false.
    • checkInteger

      protected Integer checkInteger​(Object val, Integer def)