hades.gui
Class JConsole

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

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

A Swing-based message console. Note: This class encapsulates calls to println(), message() and consoleMessage() into a wrapper to SwingUtilities.invokeLater() if necessary, in order to comply with the Swing single-thread rule.


Nested Class Summary
 class JConsole.Timer
           
 class JConsole.Updater
           
 
Nested classes inherited from class hades.gui.Console
Console.LogManager, Console.WindowCloser
 
Field Summary
 
Fields inherited from class hades.gui.Console
logManager, messagePopupLevel, MSG_ERROR, MSG_FATAL, MSG_INFO, MSG_UNKNOWN, MSG_WARNING, POPUP_ALWAYS, POPUP_ERROR, POPUP_FATAL, POPUP_INFO, POPUP_NEVER, POPUP_WARNING
 
Constructor Summary
JConsole()
           
JConsole(java.lang.String title)
           
 
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 consoleMessage(java.lang.String msg)
           
 int countLines()
          count the number of lines in the console window.
 void destroy()
          reset the reference to our singleton JConsole object, but keep the GUI and logging still alive for use by objects that have kept their reference.
 java.awt.Frame getFrame()
          return a reference to the Frame window used by this JConsole.
static JConsole getJConsole()
          a singleton method: get a reference to a system-wide JConsole, which is created on the first call.
 void getJIcon()
          load and set the icon image for this console window.
 java.lang.String getLogFileName()
           
 int getMaxLines()
           
 void initialize(java.lang.String s)
          initialize JConsole position and size from a String in xywh format
static void main(java.lang.String[] argv)
           
 void message(java.lang.String s)
           
 void println(java.lang.String s)
          print a line of text to the console, involving black magic.
 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 show()
           
 
Methods inherited from class hades.gui.Console
closeFlushLogStream, createNewConsole, enableFileLoggingGUI, finalize, getConsole, getIcon, openLogStream, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JConsole

public JConsole()

JConsole

public JConsole(java.lang.String title)
Method Detail

getJConsole

public static JConsole getJConsole()
a singleton method: get a reference to a system-wide JConsole, which is created on the first call.


destroy

public void destroy()
reset the reference to our singleton JConsole object, but keep the GUI and logging still alive for use by objects that have kept their reference. The main reason to have this method is to re-create a new JConsole object for applet use in the Java plugin, which seems to create new AWT GUI threads for each applet, while keeping the static reference to _console --- which does not work.

Overrides:
destroy in class Console

getFrame

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

Overrides:
getFrame in class Console

show

public void show()
Overrides:
show in class Console

getJIcon

public void getJIcon()
load and set the icon image for this console window. 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 JConsole position and size from a String in xywh format

Overrides:
initialize in class Console

setMaxLines

public void setMaxLines(int m)
Overrides:
setMaxLines in class Console

getMaxLines

public int getMaxLines()
Overrides:
getMaxLines in class Console

getLogFileName

public java.lang.String getLogFileName()
Overrides:
getLogFileName in class Console

setDefaultLogFileNameAndEnable

public void setDefaultLogFileNameAndEnable()
Overrides:
setDefaultLogFileNameAndEnable in class Console

setLogFileName

public void setLogFileName(java.lang.String name)
Overrides:
setLogFileName in class Console

setLogFileEnable

public void setLogFileEnable(boolean b)
Overrides:
setLogFileEnable in class Console

actionPerformed

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

println

public void println(java.lang.String s)
print a line of text to the console, involving black magic. This method adds the given line of text and an extra newline character to the current console. If we are running in text mode (no GUI), we simply dispatch to System.out.println(). However, if we are using the GUI, things become complicated due to the Swing single-thread rule. Therefore, we first check if we are currently running in the event dispatching thread - in which case we can just proceed. Otherwise, we have to create a Runnable object and call SwingUtilities.invokeLater()...

Overrides:
println in class Console

consoleMessage

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

message

public void message(java.lang.String s)
Overrides:
message in class Console

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().

Overrides:
checkShouldSetVisible in class Console

setMessagePopupLevel

public void setMessagePopupLevel(int i)
Overrides:
setMessagePopupLevel in class Console

setText

public void setText(java.lang.String s)
Overrides:
setText in class Console

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.

Overrides:
cleanup in class Console

countLines

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

Overrides:
countLines in class Console

main

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