hades.gui
Class Console

java.lang.Object
  extended byhades.gui.Console
All Implemented Interfaces:
java.awt.event.ActionListener, ConsoleMessage, java.util.EventListener
Direct Known Subclasses:
JConsole

public class Console
extends java.lang.Object
implements java.awt.event.ActionListener, ConsoleMessage

A simple message console.

To save memory and workaround the JDK memory-allocation problems with java.awt.TextField, the maximum number of lines in the console can be limited. See the documentation for getDefaultFonts() for a list of user-configurable GUI settings.

Additionally, class Console supports file logging of messages. Logging is controlled either interactively or via the SetupManager properties "Hades.Console.LogFileName" and "Hades.Console.LogEnable"


Nested Class Summary
(package private)  class Console.LogManager
           
(package private)  class Console.WindowCloser
           
 
Field Summary
protected  boolean logfileEnable
           
protected  java.lang.String logfileName
           
protected  Console.LogManager logManager
           
protected  java.io.PrintWriter logStream
           
protected  int max_lines
           
protected  int messagePopupLevel
           
static int MSG_ERROR
           
static int MSG_FATAL
           
static int MSG_INFO
           
static int MSG_UNKNOWN
           
static int MSG_WARNING
           
protected  int n_lines
           
static int POPUP_ALWAYS
           
static int POPUP_ERROR
           
static int POPUP_FATAL
           
static int POPUP_INFO
           
static int POPUP_NEVER
           
static int POPUP_WARNING
           
protected  boolean useAWT
           
 
Constructor Summary
  Console()
           
  Console(java.lang.String title)
          create a new text or GUI based Console to print messages.
protected Console(java.lang.String DONT, java.lang.String CALL, java.lang.String ME)
          HACK: a dummy constructor used by JConsole.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void checkShouldSetVisible(java.lang.String s)
          parse the first chars of message string 's' to check whether it is an info, warning, error, or fatal message: "-I-", "-W-", "-E-", "-F-" If the message level is greater than the 'popup level', make the console visible and bring in toFront().
 void cleanup()
          an utility method to limit the number of lines.
 void closeFlushLogStream()
           
 void consoleMessage(java.lang.String msg)
           
 int countLines()
          count the number of lines in the console window.
static Console createNewConsole()
           
 void destroy()
           
 void enableFileLoggingGUI(boolean b)
           
 void finalize()
           
static Console getConsole()
          get a reference to a message Console.
 java.awt.Frame getFrame()
          return a reference to the Frame window used by this Console.
 void getIcon()
          load and set the icon image for this frame.
 java.lang.String getLogFileName()
           
 int getMaxLines()
           
 void initialize(java.lang.String s)
          initialize Console position and size from a String in xywh format
static void main(java.lang.String[] argv)
           
 void message(java.lang.String s)
           
 void openLogStream()
           
 void println(java.lang.String s)
           
 void setDefaultLogFileNameAndEnable()
           
 void setLogFileEnable(boolean b)
           
 void setLogFileName(java.lang.String name)
           
 void setMaxLines(int m)
           
 void setMessagePopupLevel(int i)
           
 void setText(java.lang.String s)
           
 void setVisible(boolean b)
           
 void show()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MSG_UNKNOWN

public static final int MSG_UNKNOWN
See Also:
Constant Field Values

MSG_INFO

public static final int MSG_INFO
See Also:
Constant Field Values

MSG_WARNING

public static final int MSG_WARNING
See Also:
Constant Field Values

MSG_ERROR

public static final int MSG_ERROR
See Also:
Constant Field Values

MSG_FATAL

public static final int MSG_FATAL
See Also:
Constant Field Values

POPUP_ALWAYS

public static final int POPUP_ALWAYS
See Also:
Constant Field Values

POPUP_INFO

public static final int POPUP_INFO
See Also:
Constant Field Values

POPUP_WARNING

public static final int POPUP_WARNING
See Also:
Constant Field Values

POPUP_ERROR

public static final int POPUP_ERROR
See Also:
Constant Field Values

POPUP_FATAL

public static final int POPUP_FATAL
See Also:
Constant Field Values

POPUP_NEVER

public static final int POPUP_NEVER
See Also:
Constant Field Values

messagePopupLevel

protected int messagePopupLevel

n_lines

protected int n_lines

max_lines

protected int max_lines

logfileEnable

protected boolean logfileEnable

logfileName

protected java.lang.String logfileName

logStream

protected java.io.PrintWriter logStream

logManager

protected Console.LogManager logManager

useAWT

protected boolean useAWT
Constructor Detail

Console

public Console()

Console

public Console(java.lang.String title)
create a new text or GUI based Console to print messages. We check the "Hades.Console.UseAWT" SetupManager property to decide whether to construct the AWT user interface. Otherwise, messages are just printed to System.out.


Console

protected Console(java.lang.String DONT,
                  java.lang.String CALL,
                  java.lang.String ME)
HACK: a dummy constructor used by JConsole. External classes and problems should never call this.

Method Detail

getConsole

public static Console getConsole()
get a reference to a message Console. For backwards compatibility and to save resources, we use a singleton pattern here: We check if a Console object has already been created. If so, we return a reference to the existing Console. If not, we construct the Console now.

In order to support three different modes (no-GUI, traditional-AWT, and Swing), we use the following algorithm. First, we check the SetupManager "Hades.UseSwingGUI" property. If this evaluates to true, we construct a hades.gui.JConsole and return a reference to it. Otherwise, we directly call the hades.gui.Console constructor, which in turn examines the "Hades.Console.UseAWT" property to decide between AWT or text-only mode.


createNewConsole

public static Console createNewConsole()

destroy

public void destroy()

getFrame

public java.awt.Frame getFrame()
return a reference to the Frame window used by this Console. May be null if (useAWT is false) or the window has not been created yet.


show

public void show()

setVisible

public void setVisible(boolean b)

getIcon

public void getIcon()
load and set the icon image for this frame. The SetupManager resource "Hades.Console.Icon" specifies the filename, with its default value of "/hades/gui/images/hades.gif".


initialize

public void initialize(java.lang.String s)
initialize Console position and size from a String in xywh format


enableFileLoggingGUI

public void enableFileLoggingGUI(boolean b)

setMaxLines

public void setMaxLines(int m)

getMaxLines

public int getMaxLines()

getLogFileName

public java.lang.String getLogFileName()

setDefaultLogFileNameAndEnable

public void setDefaultLogFileNameAndEnable()

setLogFileName

public void setLogFileName(java.lang.String name)

setLogFileEnable

public void setLogFileEnable(boolean b)

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

openLogStream

public void openLogStream()

closeFlushLogStream

public void closeFlushLogStream()

finalize

public void finalize()

println

public void println(java.lang.String s)

checkShouldSetVisible

public void checkShouldSetVisible(java.lang.String s)
parse the first chars of message string 's' to check whether it is an info, warning, error, or fatal message: "-I-", "-W-", "-E-", "-F-" If the message level is greater than the 'popup level', make the console visible and bring in toFront().


setMessagePopupLevel

public void setMessagePopupLevel(int i)

consoleMessage

public void consoleMessage(java.lang.String msg)
Specified by:
consoleMessage in interface ConsoleMessage

message

public void message(java.lang.String s)

setText

public void setText(java.lang.String s)

cleanup

public void cleanup()
an utility method to limit the number of lines. If the number of lines in our TextArea ta is currently above 2*max_lines, we simply delete all lines except the last max_lines lines.


countLines

public int countLines()
count the number of lines in the console window.


main

public static void main(java.lang.String[] argv)