public class MessageHandler
extends java.lang.Object
implements java.lang.Thread.UncaughtExceptionHandler
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.
See ptolemy.gui.GraphicalMessageHandler
Constructor and Description |
---|
MessageHandler()
Create a MessageHandler.
|
Modifier and Type | Method and Description |
---|---|
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)
Display the warning message.
|
protected void |
_warning(java.lang.String info)
Show the specified message.
|
protected void |
_warning(java.lang.String info,
java.lang.Throwable throwable)
Display the warning message and throwable information.
|
protected boolean |
_yesNoCancelQuestion(java.lang.String question,
java.lang.String trueOption,
java.lang.String falseOption,
java.lang.String exceptionOption)
Ask the user a question with three possible answers;
return true if the answer is the first one and false if
the answer is the second one; throw an exception if the
user selects the third one.
|
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 boolean |
isNonInteractive()
Return true if the current process is a non-interactive session.
|
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 void |
setStatusHandler(StatusHandler handler)
Set the specified status handler, replacing any previously
set handler.
|
static java.lang.String |
shortDescription(java.lang.Throwable throwable)
Return a short description of the throwable.
|
static void |
status(java.lang.String message)
Display a status message to the user.
|
void |
uncaughtException(java.lang.Thread thread,
java.lang.Throwable exception)
Handle uncaught exceptions in a standard way.
|
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 |
yesNoCancelQuestion(java.lang.String question)
Ask the user a yes/no/cancel question, and return true if the
answer is yes.
|
static boolean |
yesNoCancelQuestion(java.lang.String question,
java.lang.String trueOption,
java.lang.String falseOption,
java.lang.String exceptionOption)
Ask the user a question with three possible answers;
return true if the answer is the first one and false if
the answer is the second one; throw an exception if the
user selects the third one.
|
static boolean |
yesNoQuestion(java.lang.String question)
Ask the user a yes/no question, and return true if the answer
is yes.
|
public static void error(java.lang.String info)
Note that within Ptolemy, most user code should not call this method directly. Instead, throw an exception, which will be caught by the system elsewhere and include information about what object caused the error.
info
- The message.public static void error(java.lang.String info, java.lang.Throwable throwable)
Note that within Ptolemy, most user code should not call this method directly. Instead, throw an exception, which will be caught by the system elsewhere and include information about what object caused the error.
info
- The message.throwable
- The throwable.CancelException
public static MessageHandler getMessageHandler()
setMessageHandler(MessageHandler)
public static boolean isNonInteractive()
This method merely checks to see if the "ptolemy.ptII.isRunningNightlyBuild" property exists and is not empty or if the "ptolemy.ptII.batchMode" property exists and is not empty and the property "ptolemyII.ptII.testingMessageHandler" is not set.
To run the test suite in the Nightly Build mode, use
make nightly
public static void message(java.lang.String info)
info
- The message.status(String)
public static void setMessageHandler(MessageHandler handler)
handler
- The message handler.getMessageHandler()
public static void setStatusHandler(StatusHandler handler)
handler
- The handler, or null to set no handler.status(String)
public static java.lang.String shortDescription(java.lang.Throwable throwable)
throwable
- The throwablepublic static void status(java.lang.String message)
message
- The message to display.message(String)
public void uncaughtException(java.lang.Thread thread, java.lang.Throwable exception)
uncaughtException
in interface java.lang.Thread.UncaughtExceptionHandler
thread
- The thread throwing the exception.exception
- The exception.public static void warning(java.lang.String info) throws CancelException
Note that within Ptolemy, most user code should not call this method directly. Instead, throw an exception, which will be caught by the system elsewhere and include information about what object caused the warning.
info
- The message.CancelException
- If the user clicks on the "Cancel" button.public static void warning(java.lang.String info, java.lang.Throwable throwable) throws CancelException
Note that within Ptolemy, most user code should not call this method directly. Instead, throw an exception, which will be caught by the system elsewhere and include information about what object caused the warning.
info
- The message.throwable
- The throwable associated with this warning.CancelException
- If the user clicks on the "Cancel" button.public static boolean yesNoQuestion(java.lang.String question)
question
- The yes/no question.public static boolean yesNoCancelQuestion(java.lang.String question) throws CancelException
question
- The yes/no/cancel question.CancelException
- If the user clicks on
the "Cancel" button.public static boolean yesNoCancelQuestion(java.lang.String question, java.lang.String trueOption, java.lang.String falseOption, java.lang.String exceptionOption) throws CancelException
question
- The question.trueOption
- The option for which to return true.falseOption
- The option for which to return false.exceptionOption
- The option for which to throw an exception.CancelException
- If the user selects the third option.protected void _error(java.lang.String info)
info
- The message.protected void _error(java.lang.String info, java.lang.Throwable throwable)
info
- The message.throwable
- The throwable.CancelException
protected void _message(java.lang.String info)
info
- The message.protected void _warning(java.lang.String info) throws CancelException
Derived classes might 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.
info
- The message.CancelException
- If the user clicks on the "Cancel" button.protected void _warning(java.lang.String info, java.lang.Throwable throwable) throws CancelException
info
- The message.throwable
- The Throwable.CancelException
- If the user clicks on the "Cancel" button.protected boolean _yesNoQuestion(java.lang.String question)
question
- The yes/no question to be asked.protected boolean _yesNoCancelQuestion(java.lang.String question, java.lang.String trueOption, java.lang.String falseOption, java.lang.String exceptionOption) throws CancelException
question
- The question.trueOption
- The option for which to return true.falseOption
- The option for which to return false.exceptionOption
- The option for which to throw an exception.CancelException
- If the user selects the third option.