Package org.geotools.swing.dialog
Class JTextReporter
- Object
-
- JTextReporter
-
public class JTextReporter extends Object
Displays a text report dialog with options to copy text to the system clipboard or save to file. It is used within the gt-swing module (for example, by the InfoTool class) and is also suitable for general use. This class is not a Swing component itself, rather it is a dialog manager which allows an application to create and update text reporter dialogs from any thread (not just the AWT Event Dispatch Thread).Dialogs are created using the various static
showDialogmethods. For example, this code creates and shows a dialog displaying the given text:
Dialog behaviour can be specified with thoseString textToDisplay = ... JTextReporter.showDialog("My very important report", text);showDialogmethods which accept aflagsargument. 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:
As well as displaying fixed text, you can also append text to the dialog's display while it is on-screen. Each of theString textToDisplay = ... JTextReporter.showDialog("My very important report", text, JTextReporter.FLAG_MODAL | FLAG_RESIZEABLE);showDialogmethods returns a JTextReporter.Connection object (a nested class withinJTextReporter) which provides methods to append text safely from any thread:
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.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();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 } });- Since:
- 2.6
- Author:
- Michael Bedward
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJTextReporter.ConnectionA connection to an active text reporter dialog providing methods to update the text displayed, add or remove listeners, and close the dialog programatically.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_FLAGSDefault flags argument forshowDialogmethods.static charDEFAULT_SEPARATOR_CHARDefault character to use for the JTextReporter.Connection.appendSeparatorLine(int) method.static intDEFAULT_TEXTAREA_COLSDefault number of columns shown in the text display area's preferred sizestatic intDEFAULT_TEXTAREA_ROWSDefault number of rows shown in the text display area's preferred sizestatic intFLAG_ALWAYS_ON_TOPConstant indicating that a text reporter should stay on top of other application windows.static intFLAG_MODALConstant indicating that a text reporter should be displayed as a modal dialog.static intFLAG_RESIZABLEConstant indicating that a text reporter dialog should be resizable.static StringNEWLINESystem-dependent newline character(s).
-
Constructor Summary
Constructors Constructor Description JTextReporter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JTextReporter.ConnectionshowDialog(String title)Creates a displays a new text reporter dialog.static JTextReporter.ConnectionshowDialog(String title, String initialText)Creates a displays a new text reporter dialog.static JTextReporter.ConnectionshowDialog(String title, String initialText, int flags)Creates a displays a new text reporter dialog.static JTextReporter.ConnectionshowDialog(String title, String initialText, int flags, int textAreaRows, int textAreaCols)
-
-
-
Field Detail
-
FLAG_MODAL
public static final int FLAG_MODAL
Constant indicating that a text reporter should be displayed as a modal dialog. Use withshowDialogmethods which take aflagsargument.- See Also:
- Constant Field Values
-
FLAG_ALWAYS_ON_TOP
public static final int FLAG_ALWAYS_ON_TOP
Constant indicating that a text reporter should stay on top of other application windows. Use withshowDialogmethods which take aflagsargument.- See Also:
- Constant Field Values
-
FLAG_RESIZABLE
public static final int FLAG_RESIZABLE
Constant indicating that a text reporter dialog should be resizable. Use withshowDialogmethods which take aflagsargument.- See Also:
- Constant Field Values
-
DEFAULT_FLAGS
public static final int DEFAULT_FLAGS
Default flags argument forshowDialogmethods. Equivalent toFLAG_ALWAYS_ON_TOP | FLAG_RESIZABLE.- See Also:
- Constant Field Values
-
DEFAULT_TEXTAREA_ROWS
public static final int DEFAULT_TEXTAREA_ROWS
Default number of rows shown in the text display area's preferred size- See Also:
- Constant Field Values
-
DEFAULT_TEXTAREA_COLS
public static final int DEFAULT_TEXTAREA_COLS
Default number of columns shown in the text display area's preferred size- See Also:
- Constant Field Values
-
NEWLINE
public static String NEWLINE
System-dependent newline character(s).
-
DEFAULT_SEPARATOR_CHAR
public static final char DEFAULT_SEPARATOR_CHAR
Default character to use for the JTextReporter.Connection.appendSeparatorLine(int) method.- See Also:
- Constant Field Values
-
-
Method Detail
-
showDialog
public static JTextReporter.Connection showDialog(String title)
Creates a displays a new text reporter dialog.This method can be called safely from any thread.
- Parameters:
title- dialog title (may benullor empty- Returns:
- a JTextReporter.Connection via which the text displayed by the dialog can be updated
-
showDialog
public static JTextReporter.Connection showDialog(String title, String initialText)
Creates a displays a new text reporter dialog.This method can be called safely from any thread.
- Parameters:
title- dialog title (may benullor emptyinitialText- text to display initially (may benullor empty- Returns:
- a JTextReporter.Connection via which the text displayed by the dialog can be updated
-
showDialog
public static JTextReporter.Connection showDialog(String title, String initialText, int flags)
Creates a displays a new text reporter dialog.This method can be called safely from any thread.
- Parameters:
title- dialog title (may benullor emptyinitialText- text to display initially (may benullor empty- Returns:
- a JTextReporter.Connection via which the text displayed by the dialog can be updated
-
showDialog
public static JTextReporter.Connection showDialog(String title, String initialText, int flags, int textAreaRows, int textAreaCols)
-
-