GWT Tk 0.2.3

asquare.gwt.debug.client
Class Debug

java.lang.Object
  extended by asquare.gwt.debug.client.Debug

public class Debug
extends Object

Facade for debugging methods. Creates methods for printing debug statements from JSNI and native JavaScript. You can enable/disable debug methods by pressing the Esc key twice sequentially.

Uses a DebugEventListener to listen for the enabler key. See DebugEventListener for potential conflicts with PopupPanel and DialogBox.

A stub version of this class is provided which will remove this class definition from the final deliverable if placed ahead of this implementation in the classpath. The stub class will prevent debug statements from being displayed, however, the string will still be created by the browser's interpreter. To entirely remove debugging statements from the deliverable you will need to do something like this:

 if (Debug.ENABLED)
 {
        Debug.println("Foo.bar(" + value1 + ',' + value2 + ')');
 }
 
Debug.ENABLED is false in the stub version.

The compiler may optimize out the class if you only reference this class through JSNI. Consider calling Debug.init() in your entry point or test case if you are getting this message:
com.google.gwt.core.client.JavaScriptException: JavaScript TypeError exception: Object doesn't support this property or method.

See Also:
DebugConsole

Field Summary
static char DEFAULT_ENABLE_KEY
          The default debug enabler key (Esc).
static boolean ENABLED
           
 
Constructor Summary
Debug()
           
 
Method Summary
static void disable()
          Disables debugging, prints a message stating so and hides the in-browser console.
static void dump(JavaScriptObject o)
          Displays members of native JavaScript objects.
static void dump(Object o)
          Displays members of native JavaScript objects.
static void enable()
          Enables debugging and prints a message stating so.
static void enableSilently()
          Enable debugging, but does not show the in-browser console.
static char getEnableKey()
          Get the key which enables & disables debugging.
static void init()
          This is called automatically when the class (script) is loaded.
static void installEventTracer(char enableKey, int eventMask)
          Installs an experimental event tracer.
static boolean isEnabled()
          Is debugging enabled at compile time and runtime.
static void prettyPrint(JavaScriptObject o)
          Prints a description of a JavaScript object.
static void prettyPrint(Object o)
          Prints a description of a JavaScript object.
static void print(String message)
          Prints a debugging message to the DebugConsole widget.
static void println(String message)
          Prints a debugging message to the DebugConsole widget, follwed by "\r\n".
static void printToBrowserConsole(String message)
          Prints a message to the native browser console, if available.
static void setEnableKey(char enableKey)
          Set the key which enables & disables debugging.
static void uninstallEventTracer()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLED

public static final boolean ENABLED
See Also:
Constant Field Values

DEFAULT_ENABLE_KEY

public static final char DEFAULT_ENABLE_KEY
The default debug enabler key (Esc).

See Also:
Constant Field Values
Constructor Detail

Debug

public Debug()
Method Detail

init

public static void init()
This is called automatically when the class (script) is loaded. If you only reference this class via JavaScript you need to call init() (or another method) to ensure this class is not optimized out by the compiler.


getEnableKey

public static char getEnableKey()
Get the key which enables & disables debugging.

Returns:
a keycode representing the enabler key

setEnableKey

public static void setEnableKey(char enableKey)
Set the key which enables & disables debugging.

Parameters:
enableKey - a keycode representing the enabler key

enableSilently

public static void enableSilently()
Enable debugging, but does not show the in-browser console.


enable

public static void enable()
Enables debugging and prints a message stating so.


disable

public static void disable()
Disables debugging, prints a message stating so and hides the in-browser console.


isEnabled

public static boolean isEnabled()
Is debugging enabled at compile time and runtime.

Returns:
true if enabled

print

public static void print(String message)
Prints a debugging message to the DebugConsole widget. The message is mirrored to the browser's native console, if supported. In hosted mode the message is mirrored to System.out and the GWT Shell.

Parameters:
message -
See Also:
DebugConsole

println

public static void println(String message)
Prints a debugging message to the DebugConsole widget, follwed by "\r\n". The message is mirrored to the browser's native console, if supported. In hosted mode the message is mirrored to System.out and the GWT Shell.

Parameters:
message -
See Also:
DebugConsole

printToBrowserConsole

public static void printToBrowserConsole(String message)
Prints a message to the native browser console, if available. Otherwise does nothing.

Parameters:
message -

prettyPrint

public static void prettyPrint(Object o)
Prints a description of a JavaScript object. Not very useful for Java objects.

See Also:
prettyPrint(JavaScriptObject)

prettyPrint

public static void prettyPrint(JavaScriptObject o)
Prints a description of a JavaScript object. Not very useful for Java objects.


dump

public static void dump(Object o)
Displays members of native JavaScript objects. Not very useful for Java objects.

See Also:
dump(JavaScriptObject)

dump

public static void dump(JavaScriptObject o)
Displays members of native JavaScript objects. This is implemented in JavaScript where Java objects are opaque. GWT doesn't support reflection so we can't see objects members in Java.


installEventTracer

public static void installEventTracer(char enableKey,
                                      int eventMask)
Installs an experimental event tracer. Press the specified key twice to start tracing. A message will be printed to the console for each event matching eventMask.

Some events are not tracing in Firefox at this time, even though the events trigger listeners in GWT widgets.

Parameters:
enableKey - a keyCode or (char) 0 for the default ('e')
eventMask - a bitwise event mask, 0 for no events or -1 for the default
See Also:
DebugEventListener, Event

uninstallEventTracer

public static void uninstallEventTracer()
See Also:
installEventTracer(char, int)

GWT Tk 0.2.3

© 2007 Mat Gessel