|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel PIRL.Viewers.Stream_Monitor
public class Stream_Monitor
A Stream_Monitor provides a scrolling display of styled text written to it.
Text may be provided directly to the monitor; in this case it acts like the JTextPane it employs. Or text may be written to the stream the monitor offers. Adding text to the monitor is thread safe. Text is added to the bottom of the current content. The capacity of the monitor - the amount of text that will be retained - may be controlled. When the capacity has been reached text is removed from the top of the current content in whole line increments. The text content may be edited by the user, saved to a disk file, or cleared.
The monitor JTextPane is contained within a JScrollPane initialized with the default scroll bar policies. The vertical scroll bar is actively managed such that when the thumb is located at the bottom of the scroll bar it will stay there, and text added to the monitor will scroll up keeping the end of the last text added visible. However, if the thumb is moved to any other location the thumb will remain there and the visible text will not move unless it must scroll up when the capacity is reached and excess text is removed from the top.
Text written to the monitor may be auto-styled with a table of text-to-style associations. The text-to-style associations may be managed as desired.
File and View menus configured for text file saving, capacity control and content clearing are provided for use in an application menu bar. These menus may be modified to suit the needs of the application.
Nested Class Summary | |
---|---|
class |
Stream_Monitor.Monitor_OutputStream
|
class |
Stream_Monitor.Monitor_Writer
|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static SimpleAttributeSet |
HIGHLIGHT_STYLE
A highlighted text style. |
static String |
ID
Class name and identification. |
static SimpleAttributeSet |
MARKER_STYLE
A marker text style. |
static int |
MIN_CAPACITY
The lower limit on the capacity value. |
static SimpleAttributeSet |
NOTICE_STYLE
A text style that will be noticed. |
static SimpleAttributeSet |
stderr_STYLE
Text style attributes suitable for "stderr" auto-styling . |
static SimpleAttributeSet |
stdout_STYLE
Text style attributes suitable for "stdout" auto-styling . |
static int |
Stream_Buffer_Capacity
|
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
Stream_Monitor()
Construct a Stream_Monitor. |
Method Summary | |
---|---|
Hashtable |
Auto_Style_Table()
Get the text-to-style association table. |
boolean |
Auto_Style()
Test if auto-styling mode is enabled |
Stream_Monitor |
Auto_Style(boolean enable)
Enable or disable auto-styling. |
AttributeSet |
Auto_Style(String text)
Get the style associated with a text prefix. |
Stream_Monitor |
Auto_Style(String text,
AttributeSet style)
Add an auto-style text-to-style association. |
int |
Capacity()
Get the maximum number of characters to be retained for scrolling. |
Stream_Monitor |
Capacity(int capacity)
Set the maximum number of characters to be retained for scrolling. |
Stream_Monitor |
Clear()
Clear the monitor of all text. |
static int |
Default_Capacity()
Get the default character capacity. |
static void |
Default_Capacity(int capacity)
Set the default character capacity. |
JMenu |
File_Menu()
Get the monitor's "File" menu. |
void |
Save_Monitor_Text()
Save the current monitor text to a file. |
void |
Save_Monitor_Text(boolean interactive)
Save the current monitor text to a file. |
void |
Save_Monitor_Text(String pathname)
Save the current monitor text to a file. |
JScrollPane |
Scroll_Pane()
Get the JScrollPane that contains the JTextPane where the monitor text is displayed. |
Stream_Monitor.Monitor_OutputStream |
Stream()
Get an OutputStream for writing to the monitor display. |
int |
Used()
Get the number of characters in the monitor. |
JMenu |
View_Menu()
Get the monitor's "View" menu. |
Stream_Monitor |
Write(String text)
Write text to the monitor. |
Stream_Monitor |
Write(String text,
AttributeSet style)
Write styled text to the monitor. |
Stream_Monitor.Monitor_Writer |
Writer()
Get a Writer for writing to the monitor display. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String ID
public static final SimpleAttributeSet stdout_STYLE
auto-styling
.
The style is a bold Monospaced font.
public static final SimpleAttributeSet stderr_STYLE
auto-styling
.
The style is a bold Monospaced font with a yellow background.
public static final SimpleAttributeSet NOTICE_STYLE
The style is bold red text.
public static final SimpleAttributeSet HIGHLIGHT_STYLE
The style is blue text.
public static final SimpleAttributeSet MARKER_STYLE
The style is a bold Monospaced font.
public static final int MIN_CAPACITY
capacity
value.
public static final int Stream_Buffer_Capacity
Constructor Detail |
---|
public Stream_Monitor()
Method Detail |
---|
public Stream_Monitor.Monitor_OutputStream Stream()
The stream is line-oriented: Each byte written is buffered until an
end-of-line sequence, or a maximum of is encountered at which point the buffer is
written
to the monitor display. An end-of-line
line sequence is any one of a line feed ('\n', 0x0A), a carriage
return ('\r', 0x0D), or a carriage return followed immediately by a
linefeed.
N.B.: Because both the OutputStream returned by this method
and the Writer()
are buffered output to the same monitor
display it is recommended that only one be used with any
Stream_Monitor object; otherwise unpredictable interleaved text
may be displayed.
OutputStream
that can be used to write text to
the monitor display.public Stream_Monitor.Monitor_Writer Writer()
The stream is line-oriented: Each character written is buffered until an
end-of-line sequence is encountered at which point the buffer is
written
to the monitor display. An end-of-line
line sequence is any one of a line feed ('\n', 0x0A), a carriage
return ('\r', 0x0D), or a carriage return followed immediately by a
linefeed.
N.B.: Because both the Writer returned by this method
and the Stream()
are buffered output to the same monitor
display it is recommended that only one be used with any
Stream_Monitor object; otherwise unpredictable interleaved text
may be displayed.
Stream_Monitor.Monitor_Writer
that can be used to write text to the
monitor display.public Stream_Monitor Capacity(int capacity)
capacity
- The maximum number of characters to be retained.
This value will be limited to not less than MIN_CAPACITY
.public int Capacity()
Capacity(int)
public static void Default_Capacity(int capacity)
When a new Stream_Monitor is constructed its initial capacity will be set to the default capacity.
capacity
- The initial capacity for a new Stream_Monitor.
This value will be limited to not less than MIN_CAPACITY
.public static int Default_Capacity()
Default_Capacity(int)
public int Used()
N.B.: The amount of capacity used may be larger than the
capacity
set for the monitor.
Write(String, AttributeSet)
public Stream_Monitor Auto_Style(boolean enable)
If auto-styling is enabled, and a style is not specified, all text
written
to the monitor display
is first examined for an initial sequence that matches one of the
text-to-style keys. If a match is found the associated style is
applied to the displayed text.
enable
- If true, auto-styling is enabled; false disables
auto-styling.
public boolean Auto_Style()
Auto_Style(boolean)
public Stream_Monitor Auto_Style(String text, AttributeSet style)
When auto-style is enabled each time text is written
or the output stream
is flushed to the
monitor display the text is checked for the specified prefix text
and, if found, the corresponding style is applied.
text
- The prefix String to be associated with a style.
If null no association is made.style
- The AttributeSet to be associated with the text.
If null no association is made.
Auto_Style(boolean)
,
Write(String, AttributeSet)
public AttributeSet Auto_Style(String text)
text
- The prefix text that is associated with a style.
Auto_Style(boolean)
public Hashtable Auto_Style_Table()
Auto_Style(boolean)
public JMenu File_Menu()
The File menu has "Save" and "Save As ..." menu items, in that order,
that have action listeners that will save the monitor text
. They have no
mnemonics or accelerators.
public JMenu View_Menu()
The View menu has "Capacity ..." and "Clear" menu items, in that
order, that have action listeners that will interactively set the
monitor character capacity
and clear
the monitor contents, respectively. They have no mnemonics or
accelerators.
public JScrollPane Scroll_Pane()
The StyledDocument managing the text can be obtained by:
Stream_Monitor
monitor = new Stream_Monitor();
...
StyledDocument
document = (JTextPane)(monitor.Scroll_Pane().getViewport().getView())
.getStyledDocument();
public void Save_Monitor_Text(boolean interactive)
If interactive is true a JFileChooser will be used to select the file where the text will be saved. Otherwise the text will be saved to the previously selected file. If no file has been previously selected interactive mode will be used.
The current monitor contents are written as plain text.
If there was a problem writing the text to the file an
error dialog
will
display the exception message.
interactive
- If interactive file selection is to be used.public void Save_Monitor_Text(String pathname)
pathname
- The pathname to the file where the text is to
be save. If null, interactive file selection will be used.Save_Monitor_Text(boolean)
public void Save_Monitor_Text()
If a file has previously been selected for saving the monitor text then it is overwritten. Otherwise interactive file selection is used.
Save_Monitor_Text(boolean)
public Stream_Monitor Clear()
public Stream_Monitor Write(String text)
This method write
s the text
with a null style.
Write
in interface Styled_Writer
text
- A text String to be added to the end of the monitor
display.
Write(String, AttributeSet)
public Stream_Monitor Write(String text, AttributeSet style)
If the style is null and auto-styling
is enabled the initial portion of the text will be checked for an
auto-style key. If one is found the associated style will be applied.
N.B.: The style is applied to all of the text specified;
auto-styling is not limited to the single line which begins with
an auto-style prefix.
If the amount of space used
is greater than the
capacity
plus a MIN_CAPACITY
margin,
monitor text is removed from the top (FIFO) up to and including
the end-of-line characters to bring the amount used below the
capacity.
The text is appended to the bottom of the monitor with the style, if any, applied. The scroll pane is moved up so that the end of the text appears at the bottom of the display.
A style is assembled using combinations of the numerous StyleConstants setXXX functions applied to a SimpleAttributeSet. For example:
SimpleAttributeSet bold_red_text = new SimpleAttributeSet ();
StyleConstants.setBold (bold_red_text, true);
StyleConstants.setForeground (bold_red_text, Color.RED);
StyleConstants.setFontFamily (bold_red_text, "Monospaced");
assembles a style that will produce text in a bold, red, monospaced font.
Write
in interface Styled_Writer
text
- The text String to be appended to the monitor.style
- The AttributeSet to be applied to the text. This
may be null if plain text is to be displayed.
StyleConstants
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |