Class JsHelper
- java.lang.Object
-
- org.pepstock.charba.client.commons.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tcast(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.MutationObserverInitcreateMutationObserverInit()Creates new instance of observer initialization options.static JsHelperget()Singleton object to get the helper instancebooleangetBooleanProperty(Key key, NativeObject nativeObject)Returns the property value from java script object, when it is stored as boolean.intgetIntegerProperty(Key key, NativeObject nativeObject)Returns the property value from java script object, when it is stored as integer.StringgetStringProperty(Key key, NativeObject nativeObject)Returns the property value from java script object, when the ID is stored as string.booleanhas(Object object, String key)Returns a boolean indicating whether the object has the specified property as its own property.booleanisCanvas(NativeObjectContainer object, Key key)Returnstrueif the object is aCanvas.booleanisCanvasGradient(Object object)Returnstrueif the object is aCanvasGradientItem.booleanisCanvasPattern(Object object)Returnstrueif the object is aCanvasPatternItem.booleanisImage(NativeObjectContainer object, Key key)Returnstrueif the object is aImg.<T> CallbackProxy<T>newCallbackProxy()Creates new proxy for callback which will passthisenvironment of java script as first argument of callback method.ObjectTypetypeOf(Object object)Returns the java script object type of object.ObjectTypetypeOf(Object object, String key)Returns the java script object type of a property.
-
-
-
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 passthisenvironment 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)
Returnstrueif the object is aCanvasPatternItem.- Parameters:
object- the object instance on which to check- Returns:
trueif the object is aCanvasPatternItem
-
isCanvasGradient
public boolean isCanvasGradient(Object object)
Returnstrueif the object is aCanvasGradientItem.- Parameters:
object- the object instance on which to check- Returns:
trueif the object is aCanvasGradientItem
-
isCanvas
public boolean isCanvas(NativeObjectContainer object, Key key)
Returnstrueif the object is aCanvas.- Parameters:
object- the object instance on which to checkkey- the string name of the property to test.- Returns:
trueif the object is aCanvas
-
isImage
public boolean isImage(NativeObjectContainer object, Key key)
Returnstrueif the object is aImg.- Parameters:
object- the object instance on which to checkkey- the string name of the property to test.- Returns:
trueif the object is aImg
-
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 objectnativeObject- java script object- Returns:
- the property value or
Undefined.INTEGERif 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 objectnativeObject- java script object- Returns:
- the property value or
Undefined.BOOLEANif 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 objectnativeObject- java script object- Returns:
- the property value or
Undefined.STRINGif not exist
-
-