public class JTextReporter extends Object
Dialogs are created using the various static showDialog
methods. For example, this
code creates and shows a dialog displaying the given text:
String textToDisplay = ...
JTextReporter.showDialog("My very important report", text);
Dialog behaviour can be specified with those showDialog
methods which accept a flags
argument. The dialog in the above example will have the default state (non-modal;
resizable; always on top of other windows) as specified by the DEFAULT_FLAGS
constant. If we wanted to display the text in a modal dialog we can do this:
String textToDisplay = ...
JTextReporter.showDialog("My very important report", text,
JTextReporter.FLAG_MODAL | FLAG_RESIZEABLE);
As well as displaying fixed text, you can also append text to the dialog's display while it is
on-screen. Each of the showDialog
methods returns a JTextReporter.Connection object (a
nested class within JTextReporter
) which provides methods to append text safely from any
thread:
Connection conn = JTextReporter.showDialog("Progressive report");
// Append some text to the dialog's display
conn.append("First line of the report").appendNewline();
// Later add some more text
conn.append("Next line of the report").appendNewline();
A Connection object only keeps a WeakReference to the associated dialog to avoid
memory leaks. If an attempt is made to append text after the user has closed the dialog an error
message is logged indicating that the connection has expired.
The JTextReporter.Connection also lets you add listeners to track when the text reporter is updated or closed:
Connection conn = JTextReporter.showDialog("Progressive report");
conn.addListener(new TextReporterListener() {
@Override
public void onReporterClosed() {
// do something
}
@Override
public void onReporterUpdated() {
// do something
}
});
Modifier and Type | Class and Description |
---|---|
static class |
JTextReporter.Connection
A connection to an active text reporter dialog providing methods to update the text
displayed, add or remove listeners, and close the dialog programatically.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FLAGS
Default flags argument for
showDialog methods. |
static char |
DEFAULT_SEPARATOR_CHAR
Default character to use for the JTextReporter.Connection.appendSeparatorLine(int) method.
|
static int |
DEFAULT_TEXTAREA_COLS
Default number of columns shown in the text display area's preferred size
|
static int |
DEFAULT_TEXTAREA_ROWS
Default number of rows shown in the text display area's preferred size
|
static int |
FLAG_ALWAYS_ON_TOP
Constant indicating that a text reporter should stay on top of other application windows.
|
static int |
FLAG_MODAL
Constant indicating that a text reporter should be displayed as a modal dialog.
|
static int |
FLAG_RESIZABLE
Constant indicating that a text reporter dialog should be resizable.
|
static String |
NEWLINE
System-dependent newline character(s).
|
Constructor and Description |
---|
JTextReporter() |
Modifier and Type | Method and Description |
---|---|
static JTextReporter.Connection |
showDialog(String title)
Creates a displays a new text reporter dialog.
|
static JTextReporter.Connection |
showDialog(String title,
String initialText)
Creates a displays a new text reporter dialog.
|
static JTextReporter.Connection |
showDialog(String title,
String initialText,
int flags)
Creates a displays a new text reporter dialog.
|
static JTextReporter.Connection |
showDialog(String title,
String initialText,
int flags,
int textAreaRows,
int textAreaCols) |
public static final int FLAG_MODAL
showDialog
methods which take a flags
argument.public static final int FLAG_ALWAYS_ON_TOP
showDialog
methods which take a flags
argument.public static final int FLAG_RESIZABLE
showDialog
methods which take a flags
argument.public static final int DEFAULT_FLAGS
showDialog
methods. Equivalent to FLAG_ALWAYS_ON_TOP | FLAG_RESIZABLE
.public static final int DEFAULT_TEXTAREA_ROWS
public static final int DEFAULT_TEXTAREA_COLS
public static String NEWLINE
public static final char DEFAULT_SEPARATOR_CHAR
public static JTextReporter.Connection showDialog(String title)
This method can be called safely from any thread.
title
- dialog title (may be null
or emptypublic static JTextReporter.Connection showDialog(String title, String initialText)
This method can be called safely from any thread.
title
- dialog title (may be null
or emptyinitialText
- text to display initially (may be null
or emptypublic static JTextReporter.Connection showDialog(String title, String initialText, int flags)
This method can be called safely from any thread.
title
- dialog title (may be null
or emptyinitialText
- text to display initially (may be null
or emptypublic static JTextReporter.Connection showDialog(String title, String initialText, int flags, int textAreaRows, int textAreaCols)
Copyright © 1996–2023 Geotools. All rights reserved.