multex
Class Awt

java.lang.Object
  extended bymultex.Awt

public class Awt
extends java.lang.Object

Services for reporting onto AWT Dialogs the messages for any exception with dynamic or static or no internationalization. The exception can be

For setting static internationalization see MsgText.

Author:
Christoph Knabe, Berlin, Copyright 1999-2001

Method Summary
static int countLines(java.lang.String i_text)
          Result: Number of lines in String i_text.
static void report(java.awt.Component io_ownerHook, java.lang.Throwable i_throwable)
          Reports i_throwable into an error message dialog with static internationalization.
static void report(java.awt.Component io_ownerHook, java.lang.Throwable i_throwable, java.util.ResourceBundle i_resourceBundle)
          Reports i_throwable into an AWT Dialog, detail description here.
static void setAwtExceptionHandlerClass(AwtExceptionHandler i_exceptionHandler)
          Registers the class of the passed object as the default exception handler for AWT and Swing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

report

public static void report(java.awt.Component io_ownerHook,
                          java.lang.Throwable i_throwable)
Reports i_throwable into an error message dialog with static internationalization. For details see @link #report(java.awt.Component, Throwable, ResourceBundle)}.


report

public static void report(java.awt.Component io_ownerHook,
                          java.lang.Throwable i_throwable,
                          java.util.ResourceBundle i_resourceBundle)
Reports i_throwable into an AWT Dialog, detail description here.
Firstly reports the same as Msg.printMessages(StringBuffer, Throwable, ResourceBundle) into a pop-up window of appropriate size. Accepting the message is done by Each of these will close the dialog box.

The Button "Show Stack Trace" will add the compactified stack trace including the chain of all causing exceptions to the message dialog box. The contents of the compact stack trace are described at method Msg.printStackTrace(StringBuffer,Throwable).

In an application this method should not be called directly from a GUI class, but the author of each GUI class should set up a method e.g.

  private void _report(Throwable ex){Awt.report(this,ex,null);}
  
, which will be called from each catch-clause in the event listeners and adds the actual GUI class as the owner of the message dialog.

Parameters:
io_ownerHook - The owner Window of the dialog box will be determined from io_ownerHook by searching the nearest parent Window. The owner window is blocked for further input until this dialog box will be closed. If the owner hook is null, the dialog is created as a nonmodal dialog with a shared, anonymous owner frame.
i_throwable - The exception to be reported along with its causal chain
i_resourceBundle - Where to take from the message texts for the exceptions to be reported. If null, falls back to static or no internationalization, depending on the actual state of @{link MsgText}.
See Also:
Msg.printReport(StringBuffer,Throwable, ResourceBundle)

countLines

public static int countLines(java.lang.String i_text)
Result: Number of lines in String i_text. Useful for sizing the text area in a message window.

See Also:
BufferedReader.readLine()

setAwtExceptionHandlerClass

public static void setAwtExceptionHandlerClass(AwtExceptionHandler i_exceptionHandler)
                                        throws Failure
Registers the class of the passed object as the default exception handler for AWT and Swing. The object itself is used only for type safety of the method handle(Throwable), but is ignored in other aspects.

Quoted below is the documentation of the private method handleException of java.awt.EventDispatchThread. It's not a long-term solution but it does work.

Handles an exception thrown in the event-dispatch thread.

If the system property "sun.awt.exception.handler" is defined, then when this method is invoked it will attempt to do the following:

  1. Load the class named by the value of that property, using the current thread's context class loader,
  2. Instantiate that class using its zero-argument constructor,
  3. Find the resulting handler object's public void handle method, which should take a single argument of type Throwable, and
  4. Invoke the handler's handle method, passing it the thrown argument that was passed to this method.
If any of the first three steps fail then this method will return false and all following invocations of this method will return false immediately. An exception thrown by the handler object's handle will be caught, and will cause this method to return false. If the handler's handle method is successfully invoked, then this method will return true. This method will never throw any sort of exception.

Note: This method is a temporary hack to work around the absence of a real API that provides the ability to replace the event-dispatch thread. The magic "sun.awt.exception.handler" property will be removed in a future release.

Parameters:
i_exceptionHandler - Any instance of the class, which shall be used as global AWT/Swing AwtExceptionHandler
Throws:
Failure - i_exceptionHandler is null, or its class has no default constructor, or it is not instantiable via its default constructor or the necessary System property is not settable. It seems, too, that the class must be public, and must be a static class (if inner). The diagnostics of Class.newInstance() are not very clear.
See Also:
JGuru discussion