| Overview | Package | Class | Tree | Deprecated | Index | Help | |||
| PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||
java.lang.Object | +--ncsa.horizon.util.MessageCenter
A MessageCenter provides a place for one or more objects to send text messages that are meant for view by the user. Typically when one wants to send a message to the user, one often calls System.out.println; however, in a GUI-type application, the visible destination of such message (e.g. a browser's Java console) may not be very noticable to the user. Instead, one might rather want to display them in a TextArea object. Or, the user might only want them to appear in certain applications or circumstances like during debugging. This class provides an application and its objects a place to send messages, whether or not they should appear or not. Where the messages appear can be set once at the application level or altered throughout the session.
A MessageCenter maintains a stack of MultiPrintWriters, that the user can choose from to send messages to. By default, these Writers do not print their messages anywhere--they just disappear into the bit-bucket; however, one can attach one or more output streams any of the MultiPrintWriters so that any message written to the MultiPrintWriters will be multicasted to all the streams attached to it. Each MultiPrintWriter--or slot--can take different kinds of messages. Four default writers--OUT, ERR, DEBUG, STATUS, and HELP--are provided automatically; however, any number of writer slots can be added as necessary. The different slots are referred to via an integer slot index with the default buffers occupying slots 0 thru 4.
Here's an example of its use:
MessageCenter mc = new MessageCenter();
mc.addToSlot(OUT, System.out); // send OUT messages to stdout
// send some messages
mc.println(mc.OUT, "This is a message."); // appear on stdout.
mc.println(mc.OUT, "This is a another message."); // this, too.
mc.println(mc.DEBUG, "About to give user help.") // these do not
mc.println(mc.HELP, "Click any button to proceed.") // appear.
// create a new buffer
int test = nextIndex();
mc.addToSlot(test, System.err) // send two slot choice to stderr
mc.println(test, "I now have " + (mc.maxIndex() + 1) + " buffer slots");
As the name implies, a MessageCenter is meant to service a number of
client objects wishing to print to different or the same buffers.
Horizon maintains a MessageCenter via a public final static member field
of the Horizon class.
Clients can either use that MessageCenter direcly from that reference
or extract out the streams of interest, load them with real target streams,
and save the streams of interest--or, save the reference away locally for
future use. If an application wants messages saved away in memory for access later, one can attach a MessageBuffer stream to a slot. The MessageBuffer can be accessed later by a GUI component such as a TextArea for display.
| Inner Class Summary | |
| static | MessageCenter.Slots
predefined slots for MessageCenter output streams. |
| Field Summary | |
| java.util.Vector | writers
the collection of MessageBuffer objects |
| Constructor Summary | |
| MessageCenter()
Create a new MessageCenter. |
|
| MessageCenter(boolean useSysStrms,
boolean debug)
Create a new MessageCenter |
|
| Method Summary | |
| void | addSysStreams()
add System.out to the OUT and System.err to the ERR and STATUS slots. |
| void | addToSlot(int slot,
java.io.PrintWriter wr)
add a PrintWriter to a slot |
| void | addToSlot(int slot,
java.io.Writer wr)
add a Writer to a slot |
| void | addToSlot(int slot,
java.io.OutputStream os)
add an OutputStream to a slot |
| MultiPrintWriter | getPrintWriter(int slot)
return the MultiPrintWriter in a given slot. |
| static void | main(java.lang.String[] argv)
|
| int | maxIndex()
return the maximum buffer index currently in use. |
| int | nextIndex()
return the next available index for a message buffer |
| void | println(int slot,
java.lang.String s)
print a String and a newline to the streams at a given slot. |
| void | print(int slot,
java.lang.String s)
print a String to the streams at a given slot. |
| void | removeFromSlot(int slot,
java.io.Writer wr)
remove a PrintWriter from a slot |
| void | removeFromSlot(int slot,
java.io.OutputStream os)
remove a PrintWriter from a slot |
| void | removeSysStreams()
remove System.out and System.err to the OUT and ERR slots, respectively |
| Methods inherited from class java.lang.Object | |
| clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait | |
| Field Detail |
protected java.util.Vector writers
| Constructor Detail |
public MessageCenter()
public MessageCenter(boolean useSysStrms,
boolean debug)
useSysStrms
- if true, attach System.out and System.err to
the OUT and ERR streams, respectively
debug
- if true, attach System.err to the DEBUG| Method Detail |
public MultiPrintWriter getPrintWriter(int slot)
throws java.lang.ArrayIndexOutOfBoundsException
public void addToSlot(int slot,
java.io.PrintWriter wr)
throws java.lang.ArrayIndexOutOfBoundsException
public void addToSlot(int slot,
java.io.Writer wr)
throws java.lang.ArrayIndexOutOfBoundsException
public void addToSlot(int slot,
java.io.OutputStream os)
throws java.lang.ArrayIndexOutOfBoundsException
public void removeFromSlot(int slot,
java.io.Writer wr)
public void removeFromSlot(int slot,
java.io.OutputStream os)
public void addSysStreams()
public void removeSysStreams()
public void print(int slot,
java.lang.String s)
public void println(int slot,
java.lang.String s)
public final int maxIndex()
public int nextIndex()
public static void main(java.lang.String[] argv)
| Overview | Package | Class | Tree | Deprecated | Index | Help | |||
| PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||