hmi.util
Class Console

java.lang.Object
  extended by hmi.util.Console

public final class Console
extends Object

Console is an class defining a "System console" window. This console is used by default for showing trace messages. Closing the Console window will cause the system to terminate. The Console class has a large number of static methods, with the intention that the single Console instance can be controlled via these static methods. For instance, to append a text line, use something like: parlevink.util.Console.println("hello, console world"); A Console window will not be shown until it is actually used. If a console should be visible immediately, one can use, for instance, Console.setVisible(true); or Console.clear(); Console windows have three buttons: "Clear" : clears the contents of the text area. "Close" : closes the Console window and terminates the console agent, but does not terminate the system. "Quit" : terminates the complete system. Closing the Console window by clicking the "X" button has the same effect as "Quit", that is, the system will terminate and exit. The Console has a number of methods intended for "remote control": close() : Closes the Console frame; NO termination or exit action implied terminate() : does not really terminate the Console itself, but rather forwards the terminate signal to the Terminator object, provided that a Terminator object has been registered by calling setTerminator(Terminator t). During this "system termination phase", the Console remains in operation. exit() : First executes terminate(), therafter exits the Java Virtual Machine. setBounds(x, y, w, h) : sets the location (x, y) and size (w, h) of the Console Frame setLocation(x, y) : sets the location (x, y) of the Console Frame setSize(w, h) : sets the size (w, h) of the Console Frame setTitle(String title) : sets the JFrame title of the Console frame. setVisible(boolean isVisible) : makes the Console JFrame visible or invisible setEnabled(boolean mode) : enables or disbales the parlevink.util.Console. When disabled, output by means of e.g. println() are ignored. toBack() : moves the Console JFrame to the "back", i.e. behind other windows. toFront() : moves the Console JFrame to the "front", i.e. in front of other windows. setBackground(Color c) : sets the background Color for the Console window. setTextColor(Color c) : sets the text color for the text area. Also there are a number of methods for manipulating the actual text contents of the Console's JFrame: clear() : clears the text area. setText(String newText) : clears the textarea and prints "newText" print(String text) : appends text to the text area. println(String text) : appends text plus a "newline" to the textarea.

Author:
Job Zwiers

Nested Class Summary
static interface Console.ConsoleListener
          Listener interface for Console actions, like print.
(package private) static class Console.ConsoleOutputStream
          OutputStream that writes to the Console
static class Console.Counter
          Counters keep the values for a print counter
 
Field Summary
static int BUTTONHEIGHT
           
private static int BUTTONHEIGHTFACTOR1
           
private static float BUTTONHEIGHTFACTOR2
           
static int BUTTONWIDTH
           
private static int BUTTONWIDTHFACTOR1
           
private static int BUTTONWIDTHFACTOR2
           
static int CHECKBOXWIDTH
           
private static boolean classTerminated
           
private static Button clearButton
           
private static Button closeButton
           
private static Console.ConsoleListener consoleListener
           
private static Map<String,Console.Counter> counters
           
static int DEFAULT_HEIGHT
           
static int DEFAULT_PRINT_LIMIT
           
static String DEFAULT_TITLE
           
static int DEFAULT_WIDTH
           
static int DEFAULT_XOFF
           
static int DEFAULT_YOFF
           
private static boolean enabled
           
private static Checkbox enabledBox
           
static int EXITDELAY
           
private static Frame frame
           
private static boolean frameEnabled
           
private static boolean frameFocusable
           
private static int height
           
static int NONE
           
private static PrintStream out
           
private static int printCounter
           
private static int printLimit
           
private static Button quitButton
           
static int SHOWMESSAGEDELAY
           
static int SYSTEMERR
           
static int SYSTEMOUT
           
private static ArrayList<Terminator> terminatorList
           
private static TextArea text
           
private static String timeFormat
           
private static boolean timestampsEnabled
           
private static String title
           
private static int width
           
static int WINDOW
           
static int XLEFTMARGIN
           
private static int xoff
           
static int XRIGHTMARGIN
           
static int YBOTTOMMARGIN
           
private static int yoff
           
static int YTOPMARGIN
           
 
Constructor Summary
private Console()
           
 
Method Summary
static void addTerminator(Terminator t)
          sets the Terminator.
static void captureError()
           
static void captureOut()
           
private static boolean checkFrame()
           
static void clear()
          clears the Console window.
static void close()
          static method for closing the Console window.
static void close(boolean reset)
          static method for closing the Console window.
private static void closeFrame()
           
private static void createFrame()
           
static boolean cycleCounter(String counterName)
           
static void delay(long d)
          "Utility" method for executing a delay of "d" milliseconds.
static void exit()
          First calls "terminateClass(), and thereafter exits the Java Virtual Machine.
static void exit(int exitCode)
          First calls "terminateClass(), and thereafter exits the Java Virtual Machine.
static Console.Counter getCounter(String counterName)
          returns the counter with name as specified, possibly null
static Console.Counter getCounter(String counterName, int limit, int cycle)
          returns the counter with name as specified.
static Frame getFrame()
           
static int getPrintLimit()
          returns the number of lines that can still be printed, without reaching the print limit
static void main(String[] arg)
           
static void print(String s)
          appends s to the text in the Console window.
private static boolean printLimitReached()
           
static void println()
          appends a newline to the text in the Console window.
static void println(boolean test, String s)
          like println, but only prints when test is true.
static void println(boolean test, String strue, String sfalse)
          like println, but prints strue when test is true, else prints sfalse.
static void println(String s)
          appends s to the text in the Console window.
static void println(String counterName, int limit, int cycle, String s)
          Executes println(s), but prints only when the cyclic counter resets to zero.
static void println(String counterName, String s)
          Executes println(s), but prints only when the cyclic counter resets to zero.
static void reset()
          resets title, size, and location to default values.
static void setBackground(Color c)
          sets the background color of the console frame.
static void setBounds(int x, int y, int w, int h)
          sets the size and location of the console window.
static void setConsoleListener(Console.ConsoleListener cl)
           
static void setCounterLimit(String counterName, int limit)
          sets the print limit for a named print counter
static void setEnabled(boolean mode)
          determines whether the Console is enabled or disabled.
static void setFocusable(boolean focusable)
           
static void setFrameEnabled(boolean mode)
          determines whether the Console Window is enabled or disabled.
static void setLocation(int x, int y)
          sets the location of the console window.
static void setPrintLimit(int limit)
          sets the max number of lines that will be printed on the Console; if limit is negative, the printLimit is set to Integer.MAX_VALUE (2^31-1), so effectively no limit.
static void setPrintStream(PrintStream s)
          Sets the PrintStream that is used when the Console Frame is not enabled.
static void setSize(int w, int h)
          sets the size of the console window.
static void setText(String s)
          replaces the current text in the Console window by a new text.
static void setTextColor(Color c)
          sets the text color of the console frame.
static void setTimeFormat(String format)
          specifies the format to be used for timestamps.
static void setTimestampsEnabled(boolean enabled)
          enables or disables printing of timestamps
static void setTitle(String s)
          sets the title of the console window.
static void setVisible(boolean visible)
          determines whether the Console window is visible or not.
static boolean terminateClass()
          The first "terminateClass" call executes the Terminator, if it is set.
static void toBack()
          moves the Console window "to the back".
static void toChannels(int channel)
           
static void toConsoleWindow()
          disables the printstream output, and enables the Console
static void toFront()
          moves the Console window "to the front".
static void toSystemErr()
          disables (and if necessary disposes) the Console window, thereafter, Console output is redirected to System.err
static void toSystemOut()
          disables (and if necessary disposes) the Console window, thereafter, Console output is redirected to System.out
protected static void windowClose()
           
protected static void windowResize()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WIDTH

public static final int DEFAULT_WIDTH
See Also:
Constant Field Values

DEFAULT_HEIGHT

public static final int DEFAULT_HEIGHT
See Also:
Constant Field Values

DEFAULT_XOFF

public static final int DEFAULT_XOFF
See Also:
Constant Field Values

DEFAULT_YOFF

public static final int DEFAULT_YOFF
See Also:
Constant Field Values

XLEFTMARGIN

public static final int XLEFTMARGIN
See Also:
Constant Field Values

XRIGHTMARGIN

public static final int XRIGHTMARGIN
See Also:
Constant Field Values

YTOPMARGIN

public static final int YTOPMARGIN
See Also:
Constant Field Values

YBOTTOMMARGIN

public static final int YBOTTOMMARGIN
See Also:
Constant Field Values

BUTTONWIDTH

public static final int BUTTONWIDTH
See Also:
Constant Field Values

BUTTONHEIGHT

public static final int BUTTONHEIGHT
See Also:
Constant Field Values

CHECKBOXWIDTH

public static final int CHECKBOXWIDTH
See Also:
Constant Field Values

DEFAULT_TITLE

public static final String DEFAULT_TITLE
See Also:
Constant Field Values

DEFAULT_PRINT_LIMIT

public static final int DEFAULT_PRINT_LIMIT
See Also:
Constant Field Values

width

private static int width

height

private static int height

xoff

private static int xoff

yoff

private static int yoff

title

private static String title

terminatorList

private static ArrayList<Terminator> terminatorList

classTerminated

private static boolean classTerminated

text

private static TextArea text

clearButton

private static Button clearButton

closeButton

private static Button closeButton

quitButton

private static Button quitButton

enabledBox

private static Checkbox enabledBox

frame

private static Frame frame

enabled

private static boolean enabled

frameEnabled

private static boolean frameEnabled

consoleListener

private static Console.ConsoleListener consoleListener

out

private static PrintStream out

printLimit

private static int printLimit

printCounter

private static int printCounter

timeFormat

private static String timeFormat

timestampsEnabled

private static boolean timestampsEnabled

counters

private static Map<String,Console.Counter> counters

SHOWMESSAGEDELAY

public static final int SHOWMESSAGEDELAY
See Also:
Constant Field Values

EXITDELAY

public static final int EXITDELAY
See Also:
Constant Field Values

frameFocusable

private static boolean frameFocusable

BUTTONHEIGHTFACTOR1

private static final int BUTTONHEIGHTFACTOR1
See Also:
Constant Field Values

BUTTONHEIGHTFACTOR2

private static final float BUTTONHEIGHTFACTOR2
See Also:
Constant Field Values

BUTTONWIDTHFACTOR1

private static final int BUTTONWIDTHFACTOR1
See Also:
Constant Field Values

BUTTONWIDTHFACTOR2

private static final int BUTTONWIDTHFACTOR2
See Also:
Constant Field Values

SYSTEMOUT

public static final int SYSTEMOUT
See Also:
Constant Field Values

SYSTEMERR

public static final int SYSTEMERR
See Also:
Constant Field Values

WINDOW

public static final int WINDOW
See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values
Constructor Detail

Console

private Console()
Method Detail

setCounterLimit

public static void setCounterLimit(String counterName,
                                   int limit)
sets the print limit for a named print counter


cycleCounter

public static boolean cycleCounter(String counterName)

getCounter

public static Console.Counter getCounter(String counterName)
returns the counter with name as specified, possibly null


getCounter

public static Console.Counter getCounter(String counterName,
                                         int limit,
                                         int cycle)
returns the counter with name as specified. If no counter with that name exists, a new Counter is allocated, with limit and cycle time as specified. (Otherwise, thse values are ignored)


setTimeFormat

public static void setTimeFormat(String format)
specifies the format to be used for timestamps. The default is "h:m:s", which print hours, minutes, and seconds separated by colon characters. See parlevink.util.TimeValue for other formats


setTimestampsEnabled

public static void setTimestampsEnabled(boolean enabled)
enables or disables printing of timestamps


setPrintLimit

public static void setPrintLimit(int limit)
sets the max number of lines that will be printed on the Console; if limit is negative, the printLimit is set to Integer.MAX_VALUE (2^31-1), so effectively no limit.


getPrintLimit

public static int getPrintLimit()
returns the number of lines that can still be printed, without reaching the print limit


printLimitReached

private static boolean printLimitReached()

close

public static void close(boolean reset)
static method for closing the Console window. (No terminate or exit though) No effect if frame == null; It does not terminate a possible running console agent. if reset== true, the title, size and location are reset to default values.


close

public static void close()
static method for closing the Console window. No effect if frame == null; It does not terminate a possible running console agent. title, size, and location are reset to default values.


reset

public static void reset()
resets title, size, and location to default values.


terminateClass

public static boolean terminateClass()
The first "terminateClass" call executes the Terminator, if it is set. (Further "terminateClass" calls are ignored.) The Java Virtual Machine is not exited, and also the Console itself is not "stopped". This implies that processes that are handled by the Terminator can still use the Console for output. (See also the exit() methods for exiting the Java Virtual Machine)


exit

public static void exit(int exitCode)
First calls "terminateClass(), and thereafter exits the Java Virtual Machine. "exitCode" is the value returned to the OS.


exit

public static void exit()
First calls "terminateClass(), and thereafter exits the Java Virtual Machine. The value 0 is returned to the OS as "exit code".


getFrame

public static Frame getFrame()

setFocusable

public static void setFocusable(boolean focusable)

createFrame

private static void createFrame()

checkFrame

private static boolean checkFrame()

windowClose

protected static void windowClose()

closeFrame

private static void closeFrame()

windowResize

protected static void windowResize()

setBounds

public static void setBounds(int x,
                             int y,
                             int w,
                             int h)
sets the size and location of the console window.


setLocation

public static void setLocation(int x,
                               int y)
sets the location of the console window.


setSize

public static void setSize(int w,
                           int h)
sets the size of the console window.


setTitle

public static void setTitle(String s)
sets the title of the console window.


setVisible

public static void setVisible(boolean visible)
determines whether the Console window is visible or not. When visible is true, a new console window is opened if necessary. When visible is false, the console window is made invisible, if such a console window is present; no new console will be opened.


clear

public static void clear()
clears the Console window. Also resets the printCounter to 0 Ignored when the Console is disabled.


setText

public static void setText(String s)
replaces the current text in the Console window by a new text. Ignored when the Console is disabled.


print

public static void print(String s)
appends s to the text in the Console window. A newline character is not automatically added. This method is identical to append(); it has been added so that "System.out.print()" calls can be replaced easily by "parlevink.util.Console.print()" calls. Ignored when the Console is disabled.


println

public static void println()
appends a newline to the text in the Console window. Ignored when the Console is disabled.


println

public static void println(String s)
appends s to the text in the Console window. A newline character is automatically added. This method is identical to appendln(); it has been added so that "System.out.println()" calls can be replaced easily by "parlevink.util.Console.println()" calls. Ignored when the Console is disabled.


println

public static void println(boolean test,
                           String strue,
                           String sfalse)
like println, but prints strue when test is true, else prints sfalse.


println

public static void println(boolean test,
                           String s)
like println, but only prints when test is true.


println

public static void println(String counterName,
                           String s)
Executes println(s), but prints only when the cyclic counter resets to zero.


println

public static void println(String counterName,
                           int limit,
                           int cycle,
                           String s)
Executes println(s), but prints only when the cyclic counter resets to zero.


toBack

public static void toBack()
moves the Console window "to the back". Will not open a new console window.


toFront

public static void toFront()
moves the Console window "to the front". If necessary, a new Console window is opened.


delay

public static void delay(long d)
"Utility" method for executing a delay of "d" milliseconds. Effectively the same as executing Thread.sleep(), but catches and ignores Exceptions.


setBackground

public static void setBackground(Color c)
sets the background color of the console frame.


setTextColor

public static void setTextColor(Color c)
sets the text color of the console frame.


addTerminator

public static void addTerminator(Terminator t)
sets the Terminator. The Terminator, i.e. an implementation of the Terminator interface, is called when the Console executes its "terminate" method. (terminate is called either directly, or implicitly when exit() is called, or the quit button is pressed) The general idea is that the Terminator should stop all running processes and takes care of "clean termination". However, it should not stop the Java Virtual Machine for instance by calling System.exit.


setEnabled

public static void setEnabled(boolean mode)
determines whether the Console is enabled or disabled. When disabled, the text area will not change, for instance, no text will be appended, printed etc. The Console window, if visible, will not disappear.


setFrameEnabled

public static void setFrameEnabled(boolean mode)
determines whether the Console Window is enabled or disabled. When disabled, Console output is printed on System.out, else it appears in the Console window.


setPrintStream

public static void setPrintStream(PrintStream s)
Sets the PrintStream that is used when the Console Frame is not enabled. The default is System.out.


toChannels

public static void toChannels(int channel)

toSystemOut

public static void toSystemOut()
disables (and if necessary disposes) the Console window, thereafter, Console output is redirected to System.out


toSystemErr

public static void toSystemErr()
disables (and if necessary disposes) the Console window, thereafter, Console output is redirected to System.err


toConsoleWindow

public static void toConsoleWindow()
disables the printstream output, and enables the Console


setConsoleListener

public static void setConsoleListener(Console.ConsoleListener cl)

main

public static void main(String[] arg)

captureError

public static void captureError()

captureOut

public static void captureOut()