Class JsHelper


  • public final class JsHelper
    extends Object
    This is a singleton wrapper for Java native object which is wrapping a CHARBA java script object implementation with some utilities to act on java script objects.
    Author:
    Andrea "Stock" Stocchero
    • Method Detail

      • get

        public static JsHelper get()
        Singleton object to get the helper instance
        Returns:
        helper instance.
      • cast

        public <T> T cast​(Object object)
        Performs unchecked cast to a type.
        Using this method can have an incorrect type of the object to the rest of the system which will result in hard to debug problems.
        Type Parameters:
        T - type of the result
        Parameters:
        object - object which must be cast
        Returns:
        the object cast to another type
      • createMutationObserverInit

        public MutationObserverInit createMutationObserverInit()
        Creates new instance of observer initialization options.
        Returns:
        new instance of observer initialization options
      • has

        public boolean has​(Object object,
                           String key)
        Returns a boolean indicating whether the object has the specified property as its own property.
        Parameters:
        object - the object on which to search the property.
        key - the string name of the property to test.
        Returns:
        boolean indicating whether or not the object has the specified property as own property.
      • typeOf

        public ObjectType typeOf​(Object object)
        Returns the java script object type of object.
        Parameters:
        object - the object to get type.
        Returns:
        the object type
      • typeOf

        public ObjectType typeOf​(Object object,
                                 String key)
        Returns the java script object type of a property.
        Parameters:
        object - the object on which to search the property.
        key - the string name of the property to test.
        Returns:
        the object type
      • newCallbackProxy

        public <T> CallbackProxy<T> newCallbackProxy()
        Creates new proxy for callback which will pass this environment of java script as first argument of callback method.
        Type Parameters:
        T - type of callback wrapped by proxy
        Returns:
        new proxy for callback.
      • isCanvasPattern

        public boolean isCanvasPattern​(Object object)
        Returns true if the object is a CanvasPatternItem.
        Parameters:
        object - the object instance on which to check
        Returns:
        true if the object is a CanvasPatternItem
      • isCanvasGradient

        public boolean isCanvasGradient​(Object object)
        Returns true if the object is a CanvasGradientItem.
        Parameters:
        object - the object instance on which to check
        Returns:
        true if the object is a CanvasGradientItem
      • isCanvas

        public boolean isCanvas​(NativeObjectContainer object,
                                Key key)
        Returns true if the object is a Canvas.
        Parameters:
        object - the object instance on which to check
        key - the string name of the property to test.
        Returns:
        true if the object is a Canvas
      • isImage

        public boolean isImage​(NativeObjectContainer object,
                               Key key)
        Returns true if the object is a Img.
        Parameters:
        object - the object instance on which to check
        key - the string name of the property to test.
        Returns:
        true if the object is a Img
      • getIntegerProperty

        public int getIntegerProperty​(Key key,
                                      NativeObject nativeObject)
        Returns the property value from java script object, when it is stored as integer.
        Parameters:
        key - the key to search inside the object
        nativeObject - java script object
        Returns:
        the property value or Undefined.INTEGER if not exist
      • getBooleanProperty

        public boolean getBooleanProperty​(Key key,
                                          NativeObject nativeObject)
        Returns the property value from java script object, when it is stored as boolean.
        Parameters:
        key - the key to search inside the object
        nativeObject - java script object
        Returns:
        the property value or Undefined.BOOLEAN if not exist
      • getStringProperty

        public String getStringProperty​(Key key,
                                        NativeObject nativeObject)
        Returns the property value from java script object, when the ID is stored as string.
        Parameters:
        key - the key to search inside the object
        nativeObject - java script object
        Returns:
        the property value or Undefined.STRING if not exist