waba.sys
Class Vm

java.lang.Object
  |
  +--waba.sys.Vm

public final class Vm
extends Object

Vm contains various system level methods.

This class contains methods to copy arrays, obtain a timestamp, sleep and get platform and version information.


Field Summary
static boolean actionEqualsMenu
          Internal use only
static int interceptSystemKey
          Only available at desktop. used internally.
static int SK_ACTION
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_ALL
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_CALC
          used as constant that can be 'or'ed in the interceptSystemKeys method
static int SK_FIND
          used as constant that can be 'or'ed in the interceptSystemKeys method
static int SK_HARD1
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_HARD2
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_HARD3
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_HARD4
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_LAUNCH
          used as constant that can be 'or'ed in the interceptSystemKeys method
static int SK_NONE
          used as constant that can be 'or'ed in the interceptSystemKeys method
static int SK_PAGE_DOWN
          This one also can be used in the getSystemKeysPressed method.
static int SK_PAGE_LEFT
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_PAGE_RIGHT
          used as constant that can be 'or'ed in the interceptSystemKeys method.
static int SK_PAGE_UP
          This one also can be used in the getSystemKeysPressed method.
 
Method Summary
static boolean attachLibrary(String name)
          Attaches a library to this application instance.
static boolean attachNativeLibrary(String name)
          Attaches a native library to this application instance (only works at device).
static void clipboardCopy(String s)
          copies the specific string to the clipboard
static String clipboardPaste()
          gets the last string from the clipboard. if none, returns "".
static boolean copyArray(Object srcArray, int srcStart, Object dstArray, int dstStart, int length)
          Copies the elements of one array to another array.
static void debug(String s)
          sends a text to the "SuperWaba Debug Console" memo, preceeded with the current time stamp and followed by a line feed.
static int exec(String command, String args, int launchCode, boolean wait)
          Executes a command.
static void gc()
          Calls the Garbage Collector.
static int getDeviceFreeMemory()
          returns the free memory in the device.
static int getSystemKeysPressed()
          Gets the current keys being pressed.
static int getTimeElapsed(int now, int before)
          Deprecated. The wrapping will only occur after more than 12 days of continuous program run. Since this is something unlike to occur in a PDA, you can safely subtract one timeStamp by the other. This method will be removed in further releases, so if your program can run without exiting for more than 12 days, copy this method to your program and use it.
static int getTimeStamp()
          Returns a time stamp in milliseconds.
static void interceptSystemKeys(int keys)
          Specify which system keys to intercept. use the SK_xxx constants ored together. eg: interceptSystemKeys(HARD1 | HARD2 | FIND).
static int setDeviceAutoOff(int seconds)
          Sets the device's "auto-off" time.
static void sleep(int millis)
          Causes the VM to pause execution for the given number of milliseconds.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

SK_PAGE_UP

public static final int SK_PAGE_UP
This one also can be used in the getSystemKeysPressed method.

SK_PAGE_DOWN

public static final int SK_PAGE_DOWN
This one also can be used in the getSystemKeysPressed method.

SK_HARD1

public static final int SK_HARD1
used as constant that can be 'or'ed in the interceptSystemKeys method. This one also can be used in the getSystemKeysPressed method.

SK_HARD2

public static final int SK_HARD2
used as constant that can be 'or'ed in the interceptSystemKeys method. This one also can be used in the getSystemKeysPressed method.

SK_HARD3

public static final int SK_HARD3
used as constant that can be 'or'ed in the interceptSystemKeys method. This one also can be used in the getSystemKeysPressed method.

SK_HARD4

public static final int SK_HARD4
used as constant that can be 'or'ed in the interceptSystemKeys method. This one also can be used in the getSystemKeysPressed method.

SK_LAUNCH

public static final int SK_LAUNCH
used as constant that can be 'or'ed in the interceptSystemKeys method

SK_FIND

public static final int SK_FIND
used as constant that can be 'or'ed in the interceptSystemKeys method

SK_CALC

public static final int SK_CALC
used as constant that can be 'or'ed in the interceptSystemKeys method

SK_ACTION

public static final int SK_ACTION
used as constant that can be 'or'ed in the interceptSystemKeys method.

SK_ALL

public static final int SK_ALL
used as constant that can be 'or'ed in the interceptSystemKeys method. Note: SK_ALL does not intercept the SK_LAUNCH key (to maintain compatibility with older applications. You must use SK_ALL | SK_LAUNCH to intercept the home key.

SK_NONE

public static final int SK_NONE
used as constant that can be 'or'ed in the interceptSystemKeys method

SK_PAGE_LEFT

public static final int SK_PAGE_LEFT
used as constant that can be 'or'ed in the interceptSystemKeys method. This one also can be used in the getSystemKeysPressed method. This key works only in Windows CE and Palm OS 5 or greater.
Since:
SuperWaba 3.0

SK_PAGE_RIGHT

public static final int SK_PAGE_RIGHT
used as constant that can be 'or'ed in the interceptSystemKeys method. This one also can be used in the getSystemKeysPressed method. This key works only in Windows CE and Palm OS 5 or greater.
Since:
SuperWaba 3.0

interceptSystemKey

public static int interceptSystemKey
Only available at desktop. used internally. Dont set it directly, it will have no effect.

actionEqualsMenu

public static boolean actionEqualsMenu
Internal use only
Method Detail

copyArray

public static boolean copyArray(Object srcArray,
                                int srcStart,
                                Object dstArray,
                                int dstStart,
                                int length)
Copies the elements of one array to another array. This method returns true if the copy is successful. It will return false if the array types are not compatible or if either array is null. If the length parameter would cause the copy to read or write past the end of one of the arrays, an index out of range error will occur. If false is returned then no copying has been performed.
Parameters:
srcArray - the array to copy elements from
srcStart - the starting position in the source array
dstArray - the array to copy elements to
dstStart - the starting position in the destination array
length - the number of elements to copy

getTimeElapsed

public static int getTimeElapsed(int now,
                                 int before)
Deprecated. The wrapping will only occur after more than 12 days of continuous program run. Since this is something unlike to occur in a PDA, you can safely subtract one timeStamp by the other. This method will be removed in further releases, so if your program can run without exiting for more than 12 days, copy this method to your program and use it.

Returns the elapsed time between the given parameters. Due to the 32 bits precision, the getTimeStamp parameter, in the way it is calculated, can wrap around 0. So, use this method to always get the right result.

getTimeStamp

public static int getTimeStamp()
Returns a time stamp in milliseconds. The time stamp is the time in milliseconds since some arbitrary starting time fixed when the VM starts executing. The maximum time stamp value is (1 << 30) and when it is reached, the timer will reset to 0 and will continue counting from there.

exec

public static int exec(String command,
                       String args,
                       int launchCode,
                       boolean wait)
Executes a command.

As an example, the following call could be used to run the command "scandir /p mydir" under Java, Win32 or WinCE:

 int result = Vm.exec("scandir", "/p mydir", 0, true);
 
This example executes the Scribble program under PalmOS:
 Vm.exec("Scribble", null, 0, false);
 
This example executes the web clipper program under PalmOS, telling it to display a web page by using launchCode 54 (CmdGoToURL).
 Vm.exec("Clipper", "http://www.yahoo.com", 54, true);
 
The args parameter passed to this method is the arguments string to pass to the program being executed.

The launchCode parameter is only used under PalmOS. Under PalmOS, it is the launch code value to use when the Vm calls SysUIAppSwitch(). If 0 is passed, the default launch code (CmdNormalLaunch) is used to execute the program.

The wait parameter passed to this method determines whether to execute the command asynchronously. If false, then the method will return without waiting for the command to complete execution. If true, the method will wait for the program to finish executing and the return value of the method will be the value returned from the application under Java, Win32 and WinCE.

Under PalmOS, the wait parameter is ignored since executing another program terminates the running program.

Note: this method kills all running threads.

Parameters:
command - the command to execute
args - command arguments
launchCode - launch code for PalmOS applications
wait - whether to wait for the command to complete execution before returning

setDeviceAutoOff

public static int setDeviceAutoOff(int seconds)
Sets the device's "auto-off" time. This is the time in seconds where, if no user interaction occurs with the device, it turns off. To keep the device always on, pass 0. This method only works under PalmOS. The integer returned is the previous auto-off time in seconds. Remember to restore it when the program exit.

sleep

public static void sleep(int millis)
Causes the VM to pause execution for the given number of milliseconds.
Parameters:
millis - time to sleep in milliseconds

getDeviceFreeMemory

public static int getDeviceFreeMemory()
returns the free memory in the device. This memory is where the database info is stored.
Since:
SuperWaba2.0beta4

gc

public static void gc()
Calls the Garbage Collector. Usualy, this isnt necessary; the gc is called everytime theres no more memory to allocate

interceptSystemKeys

public static void interceptSystemKeys(int keys)
Specify which system keys to intercept. use the SK_xxx constants ored together. eg: interceptSystemKeys(HARD1 | HARD2 | FIND). You can also use SK_ALL or SK_NONE as parameter. Note that the constants differ from the ones in IKeys. in the event handler, you must check for the IKeys values (eg: IKeys.HARD1).
Since:
SuperWaba2.0beta3

debug

public static void debug(String s)
sends a text to the "SuperWaba Debug Console" memo, preceeded with the current time stamp and followed by a line feed. Note: if you're debugging a String that contains 0 in it, all chars after the first 0 will be ignored.

clipboardCopy

public static void clipboardCopy(String s)
copies the specific string to the clipboard

clipboardPaste

public static String clipboardPaste()
gets the last string from the clipboard. if none, returns "".

attachLibrary

public static boolean attachLibrary(String name)
Attaches a library to this application instance. This is useful if you have a local or global library and want to make its classes available to your app. At the initialization, SuperWaba scans all libraries in the device and automatically attach them. But, if the library you're using have a different creator ID or if you saved a bitmap into a file, you may need to attach the file where it is located so you can instantiate its classes or load it using new Image(filename).

Note: this method only attaches SuperWaba Local Extension Libraries, ie, files that have the app's creator id and type 'SWAX'. You may also specify another creator id to the name by adding it like "name.crtr". This make possible the use of a local library in another programs (eg: libA used by progB and progC). In the dekstop you must use "name.crtr", otherwise the library will not be loaded.

After a library is added, its file cannot be modified.

To see what libraries are in the device, you can use Catalog.listCatalogs() and check the files that has type 'SWAX'.

At the desktop, you may attach a library to load an image stored in a Catalog.

Returns:
true if the library was found and attached, false otherwise.

attachNativeLibrary

public static boolean attachNativeLibrary(String name)
Attaches a native library to this application instance (only works at device). You must attach the native library before use any native methods from your library. To learn how to create a native library, you can purchase the tutorial. See at www.superwaba.org.

getSystemKeysPressed

public static int getSystemKeysPressed()
Gets the current keys being pressed. You must set which keys you want to receive notification with the interceptSystemKeys method. Note that those keys will not send notifications in the normal way; you must keep pooling with this method to see when a state has changed.
See Also:
SK_PAGE_UP, SK_PAGE_DOWN, SK_PAGE_LEFT, SK_PAGE_RIGHT, SK_ACTION, SK_HARD1, SK_HARD2, SK_HARD3, SK_HARD4, interceptSystemKeys(int)