public final class Alert extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CONFIRM_LABEL
The title of a confirmation dialog box.
|
static String |
ERROR_LABEL
The title of an error dialog box.
|
static String |
INFO_LABEL
The title of an information dialog box.
|
static String |
WARNING_LABEL
The title of a warning dialog box.
|
Constructor and Description |
---|
Alert() |
Modifier and Type | Method and Description |
---|---|
static boolean |
approve(Component component,
String question)
Identical to
confirm(java.awt.Component, java.lang.String) except the buttons are labeled Yes/No
instead of OK/Cancel. |
static String |
checkMessage(String message,
int lineMaxLength,
int maxLines)
Returns specified message wrapping long lines at word boundary
if needed to.
|
static String |
concatLines(String[] lines)
Returns specified lines separated by open lines.
|
static boolean |
confirm(Component component,
String question)
Displays specified question using an OK/Cancel confirm dialog box.
|
static int |
confirm(Component component,
String question,
int options)
Identical to
confirm(java.awt.Component, java.lang.String) except you can pass
the options you want (typically
JOptionPane.YES_NO_CANCEL_OPTION ). |
static Object[] |
createHTMLContent(String message,
String html,
Dimension size)
Creates an HTML ``message area'' using specified parameters
for use by
JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object) . |
static Object[] |
createTextContent(String message,
String lines,
boolean wrap,
int rows,
int columns)
Creates a plain text ``message area'' using specified parameters
for use by
JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object) . |
static boolean |
isConsoleApp()
Returns
true if the application invoking Alert functions
is a console application. |
static void |
setConsoleApp(boolean consoleApp)
Specifies whether the application invoking Alert functions
is a console application or a graphical application.
|
static int |
showConfirm(Component component,
Object message,
int options)
Identical to
confirm(java.awt.Component, java.lang.String) except you can pass
complex content (see createTextContent(java.lang.String, java.lang.String, boolean, int, int) ), not just a question,
and also the options you want (typically
JOptionPane.YES_NO_CANCEL_OPTION ). |
static void |
showError(Component component,
String message)
Displays specified message using an error dialog box.
|
static void |
showError(Component component,
String message,
String[] lines)
Convenience function equivalent to
showError(component, message, concatLines(lines), true, 25, 80) . |
static void |
showError(Component component,
String message,
String lines,
boolean wrap,
int rows,
int columns)
Displays specified message using an error dialog box.
|
static void |
showErrorHTML(Component component,
String message,
String html,
Dimension size)
Displays specified message using an error dialog box.
|
static void |
showInfo(Component component,
String message)
Displays specified message using an information dialog box.
|
static void |
showInfo(Component component,
String message,
String[] lines)
Convenience function equivalent to
showInfo(component, message, concatLines(lines), true, 25, 80) . |
static void |
showInfo(Component component,
String message,
String lines,
boolean wrap,
int rows,
int columns)
Displays specified message using an information dialog box.
|
static void |
showInfoHTML(Component component,
String message,
String html,
Dimension size)
Displays specified message using an information dialog box.
|
static void |
showWarning(Component component,
String message)
Displays specified message using a warning dialog box.
|
static void |
showWarning(Component component,
String message,
String[] lines)
Convenience function equivalent to
showWarning(component, message, concatLines(lines), true, 25, 80) . |
static void |
showWarning(Component component,
String message,
String lines,
boolean wrap,
int rows,
int columns)
Displays specified message using a warning dialog box.
|
static void |
showWarningHTML(Component component,
String message,
String html,
Dimension size)
Displays specified message using a warning dialog box.
|
public static final String ERROR_LABEL
public static final String WARNING_LABEL
public static final String INFO_LABEL
public static final String CONFIRM_LABEL
public static void showError(Component component, String message)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
public static void showWarning(Component component, String message)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
public static void showInfo(Component component, String message)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
public static String checkMessage(String message, int lineMaxLength, int maxLines)
message
- message that needs to be checkedlineMaxLength
- maximum number of characters in a linemaxLines
- maximum number of lines (to avoid huge messages)public static void setConsoleApp(boolean consoleApp)
Initially the client application is assumed to be a graphical one.
If the client application is a console one, then the Alert functions
prints their messages on System.out
or
System.err
instead of displaying a dialog box.
isConsoleApp
public static boolean isConsoleApp()
true
if the application invoking Alert functions
is a console application. Returns false
if the
client application is a graphical one.setConsoleApp(boolean)
public static boolean confirm(Component component, String question)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.question
- displayed question.
if question contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
true
if user confirms by clicking OK;
false
otherwisepublic static boolean approve(Component component, String question)
confirm(java.awt.Component, java.lang.String)
except the buttons are labeled Yes/No
instead of OK/Cancel.public static int confirm(Component component, String question, int options)
confirm(java.awt.Component, java.lang.String)
except you can pass
the options you want (typically
JOptionPane.YES_NO_CANCEL_OPTION
).public static int showConfirm(Component component, Object message, int options)
confirm(java.awt.Component, java.lang.String)
except you can pass
complex content (see createTextContent(java.lang.String, java.lang.String, boolean, int, int)
), not just a question,
and also the options you want (typically
JOptionPane.YES_NO_CANCEL_OPTION
).public static void showError(Component component, String message, String[] lines)
showError(component, message, concatLines(lines), true, 25, 80)
.public static void showWarning(Component component, String message, String[] lines)
showWarning(component, message, concatLines(lines), true, 25, 80)
.public static void showInfo(Component component, String message, String[] lines)
showInfo(component, message, concatLines(lines), true, 25, 80)
.public static final String concatLines(String[] lines)
public static void showError(Component component, String message, String lines, boolean wrap, int rows, int columns)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
lines
- text displayed in a JTextAreawrap
- if true, lines are wrapped at word boundaries; if false,
lines are not wrapped.rows
- number of rows for the JTextAreacolumns
- number of columns for the JTextAreapublic static void showWarning(Component component, String message, String lines, boolean wrap, int rows, int columns)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
lines
- text displayed in a JTextAreawrap
- if true, lines are wrapped at word boundaries; if false,
lines are not wrapped.rows
- number of rows for the JTextAreacolumns
- number of columns for the JTextAreapublic static void showInfo(Component component, String message, String lines, boolean wrap, int rows, int columns)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
lines
- text displayed in a JTextAreawrap
- if true, lines are wrapped at word boundaries; if false,
lines are not wrapped.rows
- number of rows for the JTextAreacolumns
- number of columns for the JTextAreapublic static Object[] createTextContent(String message, String lines, boolean wrap, int rows, int columns)
JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object)
.
Used by
showError(Component, String, String, boolean, int, int)
, etc.public static void showErrorHTML(Component component, String message, String html, Dimension size)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
html
- HTML source displayed in a JEditorPanesize
- size of the JEditorPanepublic static void showWarningHTML(Component component, String message, String html, Dimension size)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
html
- HTML source displayed in a JEditorPanesize
- size of the JEditorPanepublic static void showInfoHTML(Component component, String message, String html, Dimension size)
component
- used to specify which Frame or Dialog to
use as parent of dialog box.message
- displayed message.
if message contains lines longer than 128 characters, such lines are ``word wrapped'' at 128 characters.
html
- HTML source displayed in a JEditorPanesize
- size of the JEditorPanepublic static Object[] createHTMLContent(String message, String html, Dimension size)
JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object)
.
Used by
showErrorHTML(Component, String, String, Dimension)
, etc.