When a GUI is available, methods support cases where one would use a dialog box, which requires user-interaction after each messages, or a console window to display messages, in which case messages just accumulate in the window. Dialog boxes need a component on which to center themselves, and a default can be specified.
If nothing is configured, the messages by default are printed on
System.err. Where the messages are sent can be modified by calling
ErrorMessage.setAppendable(Appendable). For methods that have
a title as an argument and that do have an argument representing a
Swing component, the behavior depends on whether setComponent was
called. If setComponent(Component) was not
called, the message appears on the designated Appendable (which by
default is System.err). If setComponent(Component)
has been called, including with a null argument, the message will
be shown in a dialog box.
For methods that cause a message to be displayed the order of arguments are:
- a
Componentproviding a component indicating where a dialog box should be centered. If null, the dialog box will appear in the center of the screen. - a
Stringgiving a title for a dialog box. A dialog box will be provided only ifsetComponent(Component)has been called, including with a null argument. - a
Localegiving the locale to use (null implies the default locale. - a
Stringcontaining format directives or the message itself - a variable number of
Objects providing arguments specified by a format string.
JOptionPane. The rationale for a
different order is to make any format string used appear directly before
its arguments and to keep the order of arguments consistent among methods
defined by this class.
While the method ErrorMessage.setStackTrace(boolean) can be used
to programatically turn the display of stack traces on and off for
Those "display" methods that take a Throwable as an argument, one may
wish to control this behavior from a GUI. The class
1 * StackTraceMenuItem will an appropriate menu item.
Error messages will often be directed to a console. The documentation
for SimpleConsole explains how do do this
- See Also:
-
Field Summary
Fields inherited from class org.bzdev.util.ErrorMessage
err -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddChangeListener(ChangeListener listener) Add a state-change listener.static voidAdd a separator.static voidAdd separator if needed.static voidDisplay a message with a title, centering any dialog box on a component.static voidDisplay a message with a title.static voidDisplay a console if there is one, if it is an instance ofSimpleConsole, and if there is new text to display.static voiddisplayFormat(Component comp, String title, String format, Object... args) Display formatted text with a title using the default locale and a specified component.static voidDisplay formatted text with a title for a specific locale.static voiddisplayFormat(String title, Locale locale, String format, Object... args) Display formatted text with a title for a specific locale.static ErrorMsgOpsGet an instance of ErrorMsgOps.static SwingErrorMessageGet the instance of ErrorMessage used as a tag.static voidremoveChangeListener(ChangeListener listener) Remove a state-change listenerstatic voidsetComponent(Component comp) Set the component on which to center dialog boxes; null for a system default.static voidsetStackTrace(boolean value) Set stack-trace recording.static booleanCheck if stack traces are enabled.Methods inherited from class org.bzdev.util.ErrorMessage
addSeparatorAux, addSeparatorIfNeededAux, addToMessageMap, display, display, display, display, display, displayAux, displayAux, displayAux, displayAux, displayAux, displayAux, displayFormat, displayFormatAux, displayFormatAux, format, format, formatAux, formatAux, getLineAndColumn, getMessageForThrowable, getMultilineString, getMultilineString, setAppendable, setAppendableAux, setOps, setStackTraceAux, stackTraceEnabledAux
-
Method Details
-
getErrorMsgOps
Get an instance of ErrorMsgOps.- Returns:
- an instance of ErrorMsgOps that can be used for reporting error messages or warnings.
-
getTaggingInstance
Get the instance of ErrorMessage used as a tag. This object is merely a tag - it has no ErrorMessage-specific methods. It is useful for the case where the source of an event is an object responsible for error messages.- Returns:
- the instance; null if the graphics environment is headless.
-
addSeparatorIfNeeded
public static void addSeparatorIfNeeded()Add separator if needed. -
addChangeListener
Add a state-change listener. State-change listeners will be notified if stack-trace mode has been changed.- Parameters:
listener- the listener to add.
-
removeChangeListener
Remove a state-change listener- Parameters:
listener- the listener to remove
-
addSeparator
public static void addSeparator()Add a separator. -
setStackTrace
public static void setStackTrace(boolean value) Set stack-trace recording. Determines if a stack trace is shown when a Throwable is displayed.- Parameters:
value- true if stack traces should be recorded; false otherwise- See Also:
-
stackTraceEnabled
public static boolean stackTraceEnabled()Check if stack traces are enabled.- Returns:
- true if stack traces are enabled; false otherwise
- See Also:
-
setComponent
Set the component on which to center dialog boxes; null for a system default. If this method is not called this class will assume that no GUI is available so all messages will be passed to an Appendable (by default, System.err).- Parameters:
comp- the component; null if no particular component is specified.
-
displayConsoleIfNeeded
public static void displayConsoleIfNeeded()Display a console if there is one, if it is an instance ofSimpleConsole, and if there is new text to display. For aSimpleConsoleto be available, it must have been passed toErrorMessage.setAppendable(Appendable). -
displayFormat
Display formatted text with a title using the default locale and a specified component. The title is used as the title of a dialog box. SeeFormatterfor a description of the format string.- Parameters:
comp- the component; null for the default.title- the title; null for the default titleformat- a format stringargs- the arguments to format
-
displayFormat
Display formatted text with a title for a specific locale. The title is used as the title of a dialog box when a dialog box is used to display the message, If no component was specified for centering a dialog box, the title is ignored and the message is printed on anAppendable. SeeFormatterfor a description of the format string.- Parameters:
title- the title; null for the default titlelocale- the Locale, null for no localizationformat- a format stringargs- the arguments to format
-
displayFormat
public static void displayFormat(Component comp, String title, Locale locale, String format, Object... args) Display formatted text with a title for a specific locale. The title is used as the title of a dialog box when a dialog box is used to display the message, If the Component argument is null, a default location for the dialog box will be used. SeeFormatterfor a description of the format string.- Parameters:
comp- the Component on which to center the dialog box.title- the title; null for the default titlelocale- the Locale, null for no localizationformat- a format stringargs- the arguments to format
-
display
Display a message with a title. The title is used as the title of a dialog box when a dialog box is used to display the message. IfsetComponentwas not called, the title will be ignored and the message will appear on theAppendableused to log messages.- Parameters:
msg- the message to displaytitle- the title; null for the default title- See Also:
-
display
Display a message with a title, centering any dialog box on a component. The title is used as the title of a dialog box.- Parameters:
comp- the component; null for a default.title- the title; null for the default titlemsg- the message to display- See Also:
-