Package gr.zeus.ui

Class JConsolePane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public final class JConsolePane extends JPanel
A java console to replace the command line window. Redirects the stdout and stderr. Customizable. Can save its messages to text file. In addition, it can auto dump to a log file and clear the textarea. Can be used with JFrame, JInternalFrame or as a JPanel. If used in conjunction with any exe creator for java, e.g: launch4j or JSmooth, it eliminates the dos application windows and your application looks more professional.

Since:
1.0
Author:
Gregory Kotsaftis
See Also:
  • Method Details

    • getConsolePane

      public static JConsolePane getConsolePane()
      Singleton constructor.

      Returns:
      JConsolePane.

      Throws:
      ExceptionInInitializerError
    • startConsole

      public void startConsole()
      Attachs the new streams to stdout and stderr.
    • stopConsole

      public void stopConsole()
      Attachs the original streams to stdout and stderr.
    • showConsole

      public void showConsole()
      Shows the console.
    • hideConsole

      public void hideConsole()
      Hides the console.
    • showControlButtons

      public void showControlButtons()
      Shows the control buttons.
    • hideControlButtons

      public void hideControlButtons()
      Hides the control buttons.
    • clearBufferMessages

      public void clearBufferMessages()
      Clears all the messages stored in the internal buffer from the beginning of the JConsolePane. Use this if you have printed too many messages and you want to free up the memory used. Perhaps you should invoke dumpConsole() to store the messages first, unless of course you already have enabled autosave.
    • clearScreenMessages

      public void clearScreenMessages()
      Clears only the messages that are displayed in the textarea.
    • dumpConsole

      public void dumpConsole(String filename, boolean append) throws IOException
      Dumps all the console messages (up to now) to a file (not only the messages displayed in the textarea). This method does not clear the messages buffer, use clearBufferMessages() for this.

      Parameters:
      filename - The filename to store all console's messages.
      append - If true text is appended in the file, else the file gets overwritten.

      Throws:
      IOException
    • destroyConsole

      public void destroyConsole()
      Destroys the console. Actually what it does is this: Stops, hides and clears the console. If you are to invoke getConsole() after this method you will get a brand new console with no messages at all. This method is not needed for simple applications that are about to invoke System.exit() or normaly close.
    • updateLNF

      public void updateLNF()
      Updates the look and feel of the JConsolePane and it's components. MUST be called AFTER invoking: UIManager.setLookAndFeel() in your application.
    • getConfimTitle

      public String getConfimTitle()
      Gets the title for the popup window that confirms file overwrite.

      Returns:
      The title.
    • setConfimTitle

      public void setConfimTitle(String s)
      Sets the title for the popup window that confirms file overwrite.

      Parameters:
      s - The title.
    • getConfimMessage

      public String getConfimMessage()
      Gets the text for the popup window that confirms file overwrite.

      Returns:
      The message.
    • setConfimMessage

      public void setConfimMessage(String s)
      Sets the text for the popup window that confirms file overwrite.

      Parameters:
      s - The message.
    • getMessagesFilename

      public String getMessagesFilename()
      Gets the default filename for the filechooser.

      Returns:
      The filename.
    • setMessagesFilename

      public void setMessagesFilename(String s)
      Sets the default filename for the filechooser.

      Parameters:
      s - The filename.
    • getTraceFilename

      public String getTraceFilename()
      Gets the file used by dumpConsole() and all auto save methods.

      Returns:
      The filename.
    • setTraceFilename

      public void setTraceFilename(String s)
      Sets the file used by dumpConsole() and all auto save methods.

      Parameters:
      s - The filename.
    • getAppendFirstTime

      public boolean getAppendFirstTime()
      Gets append policy. If the 'traceFilename' exists the first time we try to save the messages, should we append or overwrite?

      Returns:
      true/false
    • setAppendFirstTime

      public void setAppendFirstTime(boolean b)
      Sets append policy. If the 'traceFilename' exists the first time we try to save the messages, should we append or overwrite?

      Parameters:
      b - true/false
    • getAutoSave

      public boolean getAutoSave()
      Gets auto save status. Auto save the console messages to file 'traceFilename' when 'maxChars' are reached and clear the messages (append new messages when required)?

      Returns:
      true/false
    • setAutoSave

      public void setAutoSave(boolean b)
      Sets auto save status. Auto save the console messages to file 'traceFilename' when 'maxChars' are reached and clear the messages (append new messages when required)?

      Parameters:
      b - true/false
    • getMaxChars

      public int getMaxChars()
      If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.

      Returns:
      The limit.
    • setMaxChars

      public void setMaxChars(int i)
      If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.

      Parameters:
      i - The limit.
    • getForegroundColor

      public Color getForegroundColor()
      Gets the foreground color of the textarea.

      Returns:
      The color.
    • setForegroundColor

      public void setForegroundColor(Color c)
      Sets the foreground color of the textarea.

      Parameters:
      c - The color.
    • getBackgroundColor

      public Color getBackgroundColor()
      Gets the background color of the textarea.

      Returns:
      The color.
    • setBackgroundColor

      public void setBackgroundColor(Color c)
      Sets the background color of the textarea.

      Parameters:
      c - The color.
    • getSelectedTextColor

      public Color getSelectedTextColor()
      Gets the selected text color of the textarea.

      Returns:
      The color.
    • setSelectedTextColor

      public void setSelectedTextColor(Color c)
      Sets the selected text color of the textarea.

      Parameters:
      c - The color.
    • getSelectionColor

      public Color getSelectionColor()
      Gets the selection color of the textarea.

      Returns:
      The color.
    • setSelectionColor

      public void setSelectionColor(Color c)
      Sets the selection color of the textarea.

      Parameters:
      c - The color.
    • getClearButtonText

      public String getClearButtonText()
      Gets the text of the clear button.

      Returns:
      The text.
    • setClearButtonText

      public void setClearButtonText(String s)
      Sets the text of the clear button.

      Parameters:
      s - The text.
    • getSaveButtonText

      public String getSaveButtonText()
      Gets the text of the save button.

      Returns:
      The text.
    • setSaveButtonText

      public void setSaveButtonText(String s)
      Sets the text of the save button.

      Parameters:
      s - The text.
    • getCloseButtonText

      public String getCloseButtonText()
      Gets the text of the close button.

      Returns:
      The text.
    • setCloseButtonText

      public void setCloseButtonText(String s)
      Sets the text of the close button.

      Parameters:
      s - The text.
    • getFilechooserTitle

      public String getFilechooserTitle()
      Gets the filechooser title.

      Returns:
      The title.
    • setFilechooserTitle

      public void setFilechooserTitle(String s)
      Sets the filechooser title.

      Parameters:
      s - The title.
    • getFilechooserApproveButtonText

      public String getFilechooserApproveButtonText()
      Gets the filechooser approve button text.

      Returns:
      The text.
    • setFilechooserApproveButtonText

      public void setFilechooserApproveButtonText(String s)
      Sets the filechooser approve button text.

      Parameters:
      s - The text.
    • getTextFont

      public Font getTextFont()
      Gets the font of the textarea.

      Returns:
      The font.
    • setTextFont

      public void setTextFont(Font f)
      Sets the font of the textarea.

      Parameters:
      f - The font.