Package ca.corbett.extras
Class MessageUtil
java.lang.Object
ca.corbett.extras.MessageUtil
Simple utility class to show messages to the user via JOptionPane while also simultaneously
logging them. This saves the caller from having to make two separate calls each time
an error comes up.
Example usage:
MessageUtil messageUtil = new MessageUtil(this, myLogger);
// ...
messageUtil.error("Something went horribly wrong", someException);
This will show an error dialog to the user, and also log the message string to the
given Logger.- Since:
- 2022-04-11
- Author:
- scorbo2
-
Constructor Summary
ConstructorsConstructorDescriptionMessageUtil(Component parent) Creates a MessageUtil with the given parent Component.MessageUtil(Component parent, Logger logger) Creates a MessageUtil with the given parent Component and the given Logger. -
Method Summary
Modifier and TypeMethodDescriptionvoidShows an error message to the user, and also logs it if a Logger was provided.voidShows an error message to the user, and also logs it if a Logger was provided.voidShows an error message to the user, and also logs it if a Logger was provided.voidShows an error message to the user, and also logs it if a Logger was provided.Returns the Logger currently being used.voidShows an info message to the user, and also logs it if a Logger was provided.voidShows an info message to the user, and also logs it if a Logger was provided.voidsetDefaultErrorTitle(String title) Used to specify a default dialog title in the case where error() is invoked without a given title.voidsetDefaultInfoTitle(String title) Used to specify a default dialog title in the case where info() is invoked without a given title.voidShows a warning message to the user, and also logs it if a Logger was provided.voidShows a warning message to the user, and also logs it if a Logger was provided.
-
Constructor Details
-
MessageUtil
Creates a MessageUtil with the given parent Component.- Parameters:
parent- The parent Component to be used with message dialogs.
-
MessageUtil
Creates a MessageUtil with the given parent Component and the given Logger.- Parameters:
parent- The parent Component to be used with message dialogs.logger- The Logger which will receive INFO and SEVERE messages.
-
-
Method Details
-
getLogger
Returns the Logger currently being used. May be null if none was set.- Returns:
- A Logger instance, or null.
-
setDefaultErrorTitle
Used to specify a default dialog title in the case where error() is invoked without a given title. Does not effect logging. If unset, the default is "Error".- Parameters:
title- The new title to use for error dialogs.
-
setDefaultInfoTitle
Used to specify a default dialog title in the case where info() is invoked without a given title. Does not effect logging. If unset, the default is "Info".- Parameters:
title- The new title to use for info dialogs.
-
error
Shows an error message to the user, and also logs it if a Logger was provided.- Parameters:
message- The error message to show.
-
error
Shows an error message to the user, and also logs it if a Logger was provided.- Parameters:
title- The title for the dialog.message- The error message to show.
-
error
Shows an error message to the user, and also logs it if a Logger was provided.- Parameters:
message- The error message to show.ex- An Exception which will be handed to the Logger.
-
error
Shows an error message to the user, and also logs it if a Logger was provided.- Parameters:
title- The title for the dialog.message- The error message to show.ex- An Exception which will be handed to the Logger.
-
info
Shows an info message to the user, and also logs it if a Logger was provided.- Parameters:
message- The info message to show.
-
info
Shows an info message to the user, and also logs it if a Logger was provided.- Parameters:
title- The title for the dialog.message- The info message to show.
-
warning
Shows a warning message to the user, and also logs it if a Logger was provided.- Parameters:
message- The warning message to show.
-
warning
Shows a warning message to the user, and also logs it if a Logger was provided.- Parameters:
title- The title for the dialog.message- The warning message to show.
-