public final class OptionPaneExceptionHandler extends Handler
Handler
which displays a short message to the user using a JOptionPane, and
is intended only for Level.SEVERE messages.
The issue arises of how to inform the user in the case of a Level.SEVERE message : if all Handlers are purely textual, then in a graphical application it is not uncommon for the user to be unaware of the problem, since the textual output is not necessarily visible. This Handler addresses the issue by defining a graphical logging Handler, which will always get the user's attention by using a visual pop-up message.
This Handler is unusual for two reasons :
The content of the message is taken from
LogRecord.getMessage()
, which is usually a short piece
of text. The intent is that this Handler present only the barest
facts, and that the user refer to other text-based Handler tools
for further information.
This Handler can be used both from the event dispatch thread, and from any other thread. Thus, it may be used by any worker thread which is experiencing difficulties.
Typically, this Handler is attached to the root Logger, and is thus inherited by all all other Loggers.
Constructor and Description |
---|
OptionPaneExceptionHandler()
Construct this Handler with default settings.
|
Modifier and Type | Method and Description |
---|---|
static void |
attachToRootLogger()
Add a OptionPaneExceptionHandler to the root Logger.
|
void |
close()
No-operation.
|
void |
flush()
No-operation.
|
void |
publish(LogRecord aLogRecord)
If aLogRecord satisfies
Handler.isLoggable(java.util.logging.LogRecord) ,
then a short message is displayed to the user using a JOptionPane. |
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
public OptionPaneExceptionHandler()
Formatter
is set to a SimpleFormatter
public void publish(LogRecord aLogRecord)
Handler.isLoggable(java.util.logging.LogRecord)
,
then a short message is displayed to the user using a JOptionPane.
The message is presented in a modal dialog, and will grab the focus.
Warning : if a SEVERE message is generated during startup, before the main window is displayed, then any pop-up message generated by this class will eventually be hidden behind the main window.
public static void attachToRootLogger()
Typically, the Handler attached to the root Logger is inherited by all other Loggers.
Called both upon startup and when refreshing the logging.properties file. In the case of startup, it is best to call this method only after the main window is shown ; otherwise, it is likely that any startup error messages generated by this class will be hidden by the main window.
Copyright Hirondelle Systems - License - Generated 2013Sep20.10.58