JConsolePane
Date: 2014-06-07

gr.zeus.ui

## Class JConsolePane

- java.lang.Object
- - java.awt.Component
  - - java.awt.Container
    - - javax.swing.JComponent
      - - javax.swing.JPanel
        - - gr.zeus.ui.JConsolePane

- All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

      public final class JConsolePane
      extends javax.swing.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:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class javax.swing.JPanel

      `javax.swing.JPanel.AccessibleJPanel`

    - ### Nested classes/interfaces inherited from class javax.swing.JComponent

      `javax.swing.JComponent.AccessibleJComponent`

    - ### Nested classes/interfaces inherited from class java.awt.Container

      `java.awt.Container.AccessibleAWTContainer`

    - ### Nested classes/interfaces inherited from class java.awt.Component

      `java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy`

  - ### Field Summary

    - ### Fields inherited from class javax.swing.JComponent

      `listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW`

    - ### Fields inherited from class java.awt.Component

      `accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

    - ### Fields inherited from interface java.awt.image.ImageObserver

      `ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearBufferMessages()` Clears all the messages stored in the internal buffer from the beginning of the `JConsolePane`.
    `void` | `clearScreenMessages()` Clears only the messages that are displayed in the textarea.
    `void` | `destroyConsole()` Destroys the console.
    `void` | `dumpConsole(java.lang.String filename, boolean append)` Dumps all the console messages (up to now) to a file (not only the messages displayed in the textarea).
    `boolean` | `getAppendFirstTime()` Gets append policy.
    `boolean` | `getAutoSave()` Gets auto save status.
    `java.awt.Color` | `getBackgroundColor()` Gets the background color of the textarea.
    `java.lang.String` | `getClearButtonText()` Gets the text of the clear button.
    `java.lang.String` | `getCloseButtonText()` Gets the text of the close button.
    `java.lang.String` | `getConfimMessage()` Gets the text for the popup window that confirms file overwrite.
    `java.lang.String` | `getConfimTitle()` Gets the title for the popup window that confirms file overwrite.
    `static JConsolePane` | `getConsolePane()` Singleton constructor.
    `java.lang.String` | `getFilechooserApproveButtonText()` Gets the filechooser approve button text.
    `java.lang.String` | `getFilechooserTitle()` Gets the filechooser title.
    `java.awt.Color` | `getForegroundColor()` Gets the foreground color of the textarea.
    `int` | `getMaxChars()` If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.
    `java.lang.String` | `getMessagesFilename()` Gets the default filename for the filechooser.
    `java.lang.String` | `getSaveButtonText()` Gets the text of the save button.
    `java.awt.Color` | `getSelectedTextColor()` Gets the selected text color of the textarea.
    `java.awt.Color` | `getSelectionColor()` Gets the selection color of the textarea.
    `java.awt.Font` | `getTextFont()` Gets the font of the textarea.
    `java.lang.String` | `getTraceFilename()` Gets the file used by `dumpConsole()` and all auto save methods.
    `void` | `hideConsole()` Hides the console.
    `void` | `hideControlButtons()` Hides the control buttons.
    `void` | `setAppendFirstTime(boolean b)` Sets append policy.
    `void` | `setAutoSave(boolean b)` Sets auto save status.
    `void` | `setBackgroundColor(java.awt.Color c)` Sets the background color of the textarea.
    `void` | `setClearButtonText(java.lang.String s)` Sets the text of the clear button.
    `void` | `setCloseButtonText(java.lang.String s)` Sets the text of the close button.
    `void` | `setConfimMessage(java.lang.String s)` Sets the text for the popup window that confirms file overwrite.
    `void` | `setConfimTitle(java.lang.String s)` Sets the title for the popup window that confirms file overwrite.
    `void` | `setFilechooserApproveButtonText(java.lang.String s)` Sets the filechooser approve button text.
    `void` | `setFilechooserTitle(java.lang.String s)` Sets the filechooser title.
    `void` | `setForegroundColor(java.awt.Color c)` Sets the foreground color of the textarea.
    `void` | `setMaxChars(int i)` If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.
    `void` | `setMessagesFilename(java.lang.String s)` Sets the default filename for the filechooser.
    `void` | `setSaveButtonText(java.lang.String s)` Sets the text of the save button.
    `void` | `setSelectedTextColor(java.awt.Color c)` Sets the selected text color of the textarea.
    `void` | `setSelectionColor(java.awt.Color c)` Sets the selection color of the textarea.
    `void` | `setTextFont(java.awt.Font f)` Sets the font of the textarea.
    `void` | `setTraceFilename(java.lang.String s)` Sets the file used by `dumpConsole()` and all auto save methods.
    `void` | `showConsole()` Shows the console.
    `void` | `showControlButtons()` Shows the control buttons.
    `void` | `startConsole()` Attachs the new streams to stdout and stderr.
    `void` | `stopConsole()` Attachs the original streams to stdout and stderr.
    `void` | `updateLNF()` Updates the look and feel of the `JConsolePane` and it's components.

    - ### Methods inherited from class javax.swing.JPanel

      `getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI`

    - ### Methods inherited from class javax.swing.JComponent

      `addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update`

    - ### Methods inherited from class java.awt.Container

      `add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree`

    - ### Methods inherited from class java.awt.Component

      `action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### getConsolePane

          public static JConsolePane getConsolePane()

      Singleton constructor.

      Returns:
        `JConsolePane`.

      Throws:
        `java.lang.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(java.lang.String filename,
                                  boolean append)
                           throws java.io.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:
        `java.io.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 java.lang.String getConfimTitle()

      Gets the title for the popup window that confirms file overwrite.

      Returns:
        The title.

    - #### setConfimTitle

          public void setConfimTitle(java.lang.String s)

      Sets the title for the popup window that confirms file overwrite.

      Parameters:
        `s` - The title.

    - #### getConfimMessage

          public java.lang.String getConfimMessage()

      Gets the text for the popup window that confirms file overwrite.

      Returns:
        The message.

    - #### setConfimMessage

          public void setConfimMessage(java.lang.String s)

      Sets the text for the popup window that confirms file overwrite.

      Parameters:
        `s` - The message.

    - #### getMessagesFilename

          public java.lang.String getMessagesFilename()

      Gets the default filename for the filechooser.

      Returns:
        The filename.

    - #### setMessagesFilename

          public void setMessagesFilename(java.lang.String s)

      Sets the default filename for the filechooser.

      Parameters:
        `s` - The filename.

    - #### getTraceFilename

          public java.lang.String getTraceFilename()

      Gets the file used by `dumpConsole()` and all auto save methods.

      Returns:
        The filename.

    - #### setTraceFilename

          public void setTraceFilename(java.lang.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 java.awt.Color getForegroundColor()

      Gets the foreground color of the textarea.

      Returns:
        The color.

    - #### setForegroundColor

          public void setForegroundColor(java.awt.Color c)

      Sets the foreground color of the textarea.

      Parameters:
        `c` - The color.

    - #### getBackgroundColor

          public java.awt.Color getBackgroundColor()

      Gets the background color of the textarea.

      Returns:
        The color.

    - #### setBackgroundColor

          public void setBackgroundColor(java.awt.Color c)

      Sets the background color of the textarea.

      Parameters:
        `c` - The color.

    - #### getSelectedTextColor

          public java.awt.Color getSelectedTextColor()

      Gets the selected text color of the textarea.

      Returns:
        The color.

    - #### setSelectedTextColor

          public void setSelectedTextColor(java.awt.Color c)

      Sets the selected text color of the textarea.

      Parameters:
        `c` - The color.

    - #### getSelectionColor

          public java.awt.Color getSelectionColor()

      Gets the selection color of the textarea.

      Returns:
        The color.

    - #### setSelectionColor

          public void setSelectionColor(java.awt.Color c)

      Sets the selection color of the textarea.

      Parameters:
        `c` - The color.

    - #### getClearButtonText

          public java.lang.String getClearButtonText()

      Gets the text of the clear button.

      Returns:
        The text.

    - #### setClearButtonText

          public void setClearButtonText(java.lang.String s)

      Sets the text of the clear button.

      Parameters:
        `s` - The text.

    - #### getSaveButtonText

          public java.lang.String getSaveButtonText()

      Gets the text of the save button.

      Returns:
        The text.

    - #### setSaveButtonText

          public void setSaveButtonText(java.lang.String s)

      Sets the text of the save button.

      Parameters:
        `s` - The text.

    - #### getCloseButtonText

          public java.lang.String getCloseButtonText()

      Gets the text of the close button.

      Returns:
        The text.

    - #### setCloseButtonText

          public void setCloseButtonText(java.lang.String s)

      Sets the text of the close button.

      Parameters:
        `s` - The text.

    - #### getFilechooserTitle

          public java.lang.String getFilechooserTitle()

      Gets the filechooser title.

      Returns:
        The title.

    - #### setFilechooserTitle

          public void setFilechooserTitle(java.lang.String s)

      Sets the filechooser title.

      Parameters:
        `s` - The title.

    - #### getFilechooserApproveButtonText

          public java.lang.String getFilechooserApproveButtonText()

      Gets the filechooser approve button text.

      Returns:
        The text.

    - #### setFilechooserApproveButtonText

          public void setFilechooserApproveButtonText(java.lang.String s)

      Sets the filechooser approve button text.

      Parameters:
        `s` - The text.

    - #### getTextFont

          public java.awt.Font getTextFont()

      Gets the font of the textarea.

      Returns:
        The font.

    - #### setTextFont

          public void setTextFont(java.awt.Font f)

      Sets the font of the textarea.

      Parameters:
        `f` - The font.