GWT Tk 0.2.3

asquare.gwt.tk.client.util
Class JsUtil

java.lang.Object
  extended by asquare.gwt.tk.client.util.JsUtil

public class JsUtil
extends Object

JSNI methods for working with native JavaScript objects.


Constructor Summary
JsUtil()
           
 
Method Summary
static JavaScriptObject arrayConvert(float[] array)
          Converts an array of float to a native JavaScript array.
static JavaScriptObject arrayConvert(int[] array)
          Converts an array of int to a native JavaScript array.
static JavaScriptObject arrayConvert(Object[] array)
          Converts an array of objects to a native JavaScript array.
static float arrayGetFloat(JavaScriptObject array, int index)
          Get a float value from a native JavaScript array.
static int arrayGetInt(JavaScriptObject array, int index)
          Get an int value from a native JavaScript array.
static Object arrayGetObject(JavaScriptObject array, int index)
          Get an object from a native JavaScript array.
static int arrayLength(JavaScriptObject array)
          Get the length of a native JavaScript array.
static JavaScriptObject arrayNewArray(int length)
          Constructs an empty native JavaScript array.
static void arraySet(JavaScriptObject array, int index, float value)
          Set a float value at the specified index in a native JavaScript array.
static void arraySet(JavaScriptObject array, int index, int value)
          Set an int value at the specified index in a native JavaScript array.
static void arraySet(JavaScriptObject array, int index, Object value)
          Set an object at the specified index in a native JavaScript array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsUtil

public JsUtil()
Method Detail

arrayConvert

public static JavaScriptObject arrayConvert(int[] array)
Converts an array of int to a native JavaScript array.

Parameters:
array - a regular Java array
Returns:
a new array as an opaque JavaScriptObject

arrayConvert

public static JavaScriptObject arrayConvert(float[] array)
Converts an array of float to a native JavaScript array.

Parameters:
array - a regular Java array
Returns:
a new array as an opaque JavaScriptObject

arrayConvert

public static JavaScriptObject arrayConvert(Object[] array)
Converts an array of objects to a native JavaScript array.

Parameters:
array - a regular Java array
Returns:
a new array as an opaque JavaScriptObject

arrayNewArray

public static JavaScriptObject arrayNewArray(int length)
Constructs an empty native JavaScript array. JavaScript arrays are not typed.

Parameters:
length - the array length
Returns:
the array as an opaque JavaScriptObject
Throws:
JavaScriptException - if length is less than 0

arrayLength

public static int arrayLength(JavaScriptObject array)
Get the length of a native JavaScript array.

Parameters:
array - an opaque handle to a JavaScript array
Returns:
the length
Throws:
JavaScriptException - if the array is null

arrayGetInt

public static int arrayGetInt(JavaScriptObject array,
                              int index)
Get an int value from a native JavaScript array.

Parameters:
array - an opaque handle to a JavaScript array
index - the index, starting at 0
Returns:
the value
Throws:
JavaScriptException - if the array is null
JavaScriptException - if the index is out of bounds
JavaScriptException - if value at the index is not coercable to an int (hosted mode only)

arrayGetFloat

public static float arrayGetFloat(JavaScriptObject array,
                                  int index)
Get a float value from a native JavaScript array.

Parameters:
array - an opaque handle to a JavaScript array
index - the index, starting at 0
Returns:
the value
Throws:
JavaScriptException - if the array is null
JavaScriptException - if the index is out of bounds
JavaScriptException - if value at the index is not coercable to a float (hosted mode only)

arrayGetObject

public static Object arrayGetObject(JavaScriptObject array,
                                    int index)
Get an object from a native JavaScript array.

Parameters:
array - an opaque handle to a JavaScript array
index - the index, starting at 0
Returns:
the value
Throws:
JavaScriptException - if the array is null
JavaScriptException - if the index is out of bounds
JavaScriptException - if value at the index is not an object (hosted mode only)

arraySet

public static void arraySet(JavaScriptObject array,
                            int index,
                            int value)
Set an int value at the specified index in a native JavaScript array. The array will automatically allocate space to accommodate new values.

Parameters:
array - an opaque handle to a JavaScript array
index - the index, starting at 0
value - an integer primative value
Throws:
JavaScriptException - if the array is null
JavaScriptException - if the index is negative

arraySet

public static void arraySet(JavaScriptObject array,
                            int index,
                            float value)
Set a float value at the specified index in a native JavaScript array. The array will automatically allocate space to accommodate new values.

Parameters:
array - an opaque handle to a JavaScript array
index - the index, starting at 0
value - an float primative value
Throws:
JavaScriptException - if the array is null
JavaScriptException - if the index is negative

arraySet

public static void arraySet(JavaScriptObject array,
                            int index,
                            Object value)
Set an object at the specified index in a native JavaScript array. The array will automatically allocate space to accommodate new values.

Parameters:
array - an opaque handle to a JavaScript array
index - the index, starting at 0
value - an object
Throws:
JavaScriptException - if the array is null
JavaScriptException - if the index is negative

GWT Tk 0.2.3

© 2007 Mat Gessel