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> 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.MutationObserverInit
createMutationObserverInit()
Creates new instance of observer initialization options.static JsHelper
get()
Singleton object to get the helper instanceboolean
getBooleanProperty(Key key, NativeObject nativeObject)
Returns the property value from java script object, when it is stored as boolean.int
getIntegerProperty(Key key, NativeObject nativeObject)
Returns the property value from java script object, when it is stored as integer.String
getStringProperty(Key key, NativeObject nativeObject)
Returns the property value from java script object, when the ID is stored as string.boolean
has(Object object, String key)
Returns a boolean indicating whether the object has the specified property as its own property.boolean
isCanvas(NativeObjectContainer object, Key key)
Returnstrue
if the object is aCanvas
.boolean
isCanvasGradient(Object object)
Returnstrue
if the object is aCanvasGradientItem
.boolean
isCanvasPattern(Object object)
Returnstrue
if the object is aCanvasPatternItem
.boolean
isImage(NativeObjectContainer object, Key key)
Returnstrue
if the object is aImg
.<T> CallbackProxy<T>
newCallbackProxy()
Creates new proxy for callback which will passthis
environment of java script as first argument of callback method.ObjectType
typeOf(Object object)
Returns the java script object type of object.ObjectType
typeOf(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 passthis
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)
Returnstrue
if the object is aCanvasPatternItem
.- Parameters:
object
- the object instance on which to check- Returns:
true
if the object is aCanvasPatternItem
-
isCanvasGradient
public boolean isCanvasGradient(Object object)
Returnstrue
if the object is aCanvasGradientItem
.- Parameters:
object
- the object instance on which to check- Returns:
true
if the object is aCanvasGradientItem
-
isCanvas
public boolean isCanvas(NativeObjectContainer object, Key key)
Returnstrue
if the object is aCanvas
.- Parameters:
object
- the object instance on which to checkkey
- the string name of the property to test.- Returns:
true
if the object is aCanvas
-
isImage
public boolean isImage(NativeObjectContainer object, Key key)
Returnstrue
if the object is aImg
.- Parameters:
object
- the object instance on which to checkkey
- the string name of the property to test.- Returns:
true
if 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.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 objectnativeObject
- 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 objectnativeObject
- java script object- Returns:
- the property value or
Undefined.STRING
if not exist
-
-