ptolemy.gui
Class MessageHandler

java.lang.Object
  |
  +--ptolemy.gui.MessageHandler
Direct Known Subclasses:
GraphicalMessageHandler

public class MessageHandler
extends java.lang.Object

This is a class that is used to report errors. It provides a set of static methods that are called to report errors. However, the actual reporting of the errors is deferred to an instance of this class that is set using the setMessageHandler() method. Normally there is only one instance, set up by the application, so the class is a singleton. But this is not enforced.

This base class simply writes the errors to System.err. When an applet or application starts up, it may wish to set a subclass of this class as the message handler, to allow a nicer way of reporting errors. For example, a swing application will probably want to report errors in a dialog box, using for example the derived class GraphicalMessageHandler.

Since:
Ptolemy II 1.0
Version:
$Id: MessageHandler.html,v 1.1 2004/02/17 15:36:59 mnwaltz Exp $
Author:
Edward A. Lee, Steve Neuendorffer
See Also:
GraphicalMessageHandler

Constructor Summary
MessageHandler()
           
 
Method Summary
protected  void _error(java.lang.String info)
          Show the specified error message.
protected  void _error(java.lang.String info, java.lang.Throwable throwable)
          Show the specified message and throwable information.
protected  void _message(java.lang.String info)
          Show the specified message.
protected  void _warning(java.lang.String info)
          Show the specified message in a modal dialog.
protected  void _warning(java.lang.String info, java.lang.Throwable throwable)
          Show the specified message and throwable information in a modal dialog.
protected  boolean _yesNoQuestion(java.lang.String question)
          Ask the user a yes/no question, and return true if the answer is yes.
static void error(java.lang.String info)
          Defer to the set message handler to show the specified error message.
static void error(java.lang.String info, java.lang.Throwable throwable)
          Defer to the set message handler to show the specified message and throwable information.
static MessageHandler getMessageHandler()
          Return the message handler instance that is used by the static methods in this class.
static void message(java.lang.String info)
          Defer to the set message handler to show the specified message.
static void setMessageHandler(MessageHandler handler)
          Set the message handler instance that is used by the static methods in this class.
static java.lang.String shortDescription(java.lang.Throwable throwable)
          Return a short description of the throwable.
static void warning(java.lang.String info)
          Defer to the set message handler to show the specified message in a modal dialog.
static void warning(java.lang.String info, java.lang.Throwable throwable)
          Show the specified message and throwable information in a modal dialog.
static boolean yesNoQuestion(java.lang.String question)
          Ask the user a yes/no question, and return true if the answer is yes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageHandler

public MessageHandler()
Method Detail

error

public static void error(java.lang.String info)
Defer to the set message handler to show the specified error message.

Parameters:
info - The message.

error

public static void error(java.lang.String info,
                         java.lang.Throwable throwable)
Defer to the set message handler to show the specified message and throwable information. If the throwable is an instance of CancelException, then it is not shown. By default, only the message of the throwable is thrown. The stack trace information is only shown if the user clicks on the "Display Stack Trace" button.

Parameters:
info - The message.
throwable - The throwable.
See Also:
CancelException

shortDescription

public static java.lang.String shortDescription(java.lang.Throwable throwable)
Return a short description of the throwable.

Parameters:
throwable - The throwable
Returns:
If the throwable is an Exception, return "Exception", if it is an Error, return "Error", if it is a Throwable, return "Throwable".

getMessageHandler

public static MessageHandler getMessageHandler()
Return the message handler instance that is used by the static methods in this class.


message

public static void message(java.lang.String info)
Defer to the set message handler to show the specified message.

Parameters:
info - The message.

setMessageHandler

public static void setMessageHandler(MessageHandler handler)
Set the message handler instance that is used by the static methods in this class. If the given handler is null, then do nothing.

Parameters:
handler - The message handler.

warning

public static void warning(java.lang.String info)
                    throws CancelException
Defer to the set message handler to show the specified message in a modal dialog. If the user clicks on the "Cancel" button, then throw an exception. This gives the user the option of not continuing the execution, something that is particularly useful if continuing execution will result in repeated warnings.

Parameters:
info - The message.
Throws:
CancelException - If the user clicks on the "Cancel" button.

warning

public static void warning(java.lang.String info,
                           java.lang.Throwable throwable)
                    throws CancelException
Show the specified message and throwable information in a modal dialog. If the user clicks on the "Cancel" button, then throw an exception. This gives the user the option of not continuing the execution, something that is particularly useful if continuing execution will result in repeated warnings. By default, only the message of the throwable is thrown. The stack trace information is only shown if the user clicks on the "Display Stack Trace" button.

Parameters:
info - The message.
Throws:
CancelException - If the user clicks on the "Cancel" button.

yesNoQuestion

public static boolean yesNoQuestion(java.lang.String question)
Ask the user a yes/no question, and return true if the answer is yes.

Returns:
True if the answer is yes.

_error

protected void _error(java.lang.String info)
Show the specified error message.

Parameters:
info - The message.

_error

protected void _error(java.lang.String info,
                      java.lang.Throwable throwable)
Show the specified message and throwable information. If the throwable is an instance of CancelException, then it is not shown. By default, only the message of the exception is thrown. The stack trace information is only shown if the user clicks on the "Display Stack Trace" button.

Parameters:
info - The message.
throwable - The throwable.
See Also:
CancelException

_message

protected void _message(java.lang.String info)
Show the specified message.

Parameters:
info - The message.

_warning

protected void _warning(java.lang.String info)
                 throws CancelException
Show the specified message in a modal dialog. If the user clicks on the "Cancel" button, then throw an exception. This gives the user the option of not continuing the execution, something that is particularly useful if continuing execution will result in repeated warnings.

Parameters:
info - The message.
Throws:
CancelException - If the user clicks on the "Cancel" button.

_warning

protected void _warning(java.lang.String info,
                        java.lang.Throwable throwable)
                 throws CancelException
Show the specified message and throwable information in a modal dialog. If the user clicks on the "Cancel" button, then throw an exception. This gives the user the option of not continuing the execution, something that is particularly useful if continuing execution will result in repeated warnings. By default, only the message of the throwable is thrown. The stack trace information is only shown if the user clicks on the "Display Stack Trace" button.

Parameters:
info - The message.
Throws:
CancelException - If the user clicks on the "Cancel" button.

_yesNoQuestion

protected boolean _yesNoQuestion(java.lang.String question)
Ask the user a yes/no question, and return true if the answer is yes. In this base class, this prints the question on standard output and looks for the reply on standard input.

Returns:
True if the answer is yes.