Package 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.JPanelA 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
-
-
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearBufferMessages()Clears all the messages stored in the internal buffer from the beginning of theJConsolePane.voidclearScreenMessages()Clears only the messages that are displayed in the textarea.voiddestroyConsole()Destroys the console.voiddumpConsole(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).booleangetAppendFirstTime()Gets append policy.booleangetAutoSave()Gets auto save status.java.awt.ColorgetBackgroundColor()Gets the background color of the textarea.java.lang.StringgetClearButtonText()Gets the text of the clear button.java.lang.StringgetCloseButtonText()Gets the text of the close button.java.lang.StringgetConfimMessage()Gets the text for the popup window that confirms file overwrite.java.lang.StringgetConfimTitle()Gets the title for the popup window that confirms file overwrite.static JConsolePanegetConsolePane()Singleton constructor.java.lang.StringgetFilechooserApproveButtonText()Gets the filechooser approve button text.java.lang.StringgetFilechooserTitle()Gets the filechooser title.java.awt.ColorgetForegroundColor()Gets the foreground color of the textarea.intgetMaxChars()If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.java.lang.StringgetMessagesFilename()Gets the default filename for the filechooser.java.lang.StringgetSaveButtonText()Gets the text of the save button.java.awt.ColorgetSelectedTextColor()Gets the selected text color of the textarea.java.awt.ColorgetSelectionColor()Gets the selection color of the textarea.java.awt.FontgetTextFont()Gets the font of the textarea.java.lang.StringgetTraceFilename()Gets the file used bydumpConsole()and all auto save methods.voidhideConsole()Hides the console.voidhideControlButtons()Hides the control buttons.voidsetAppendFirstTime(boolean b)Sets append policy.voidsetAutoSave(boolean b)Sets auto save status.voidsetBackgroundColor(java.awt.Color c)Sets the background color of the textarea.voidsetClearButtonText(java.lang.String s)Sets the text of the clear button.voidsetCloseButtonText(java.lang.String s)Sets the text of the close button.voidsetConfimMessage(java.lang.String s)Sets the text for the popup window that confirms file overwrite.voidsetConfimTitle(java.lang.String s)Sets the title for the popup window that confirms file overwrite.voidsetFilechooserApproveButtonText(java.lang.String s)Sets the filechooser approve button text.voidsetFilechooserTitle(java.lang.String s)Sets the filechooser title.voidsetForegroundColor(java.awt.Color c)Sets the foreground color of the textarea.voidsetMaxChars(int i)If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.voidsetMessagesFilename(java.lang.String s)Sets the default filename for the filechooser.voidsetSaveButtonText(java.lang.String s)Sets the text of the save button.voidsetSelectedTextColor(java.awt.Color c)Sets the selected text color of the textarea.voidsetSelectionColor(java.awt.Color c)Sets the selection color of the textarea.voidsetTextFont(java.awt.Font f)Sets the font of the textarea.voidsetTraceFilename(java.lang.String s)Sets the file used bydumpConsole()and all auto save methods.voidshowConsole()Shows the console.voidshowControlButtons()Shows the control buttons.voidstartConsole()Attachs the new streams to stdout and stderr.voidstopConsole()Attachs the original streams to stdout and stderr.voidupdateLNF()Updates the look and feel of theJConsolePaneand 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
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 theJConsolePane. Use this if you have printed too many messages and you want to free up the memory used. Perhaps you should invokedumpConsole()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.IOExceptionDumps 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, useclearBufferMessages()for this.- Parameters:
filename- The filename to store all console's messages.append- Iftruetext 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 invokegetConsole()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 theJConsolePaneand 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 bydumpConsole()and all auto save methods.- Returns:
- The filename.
-
setTraceFilename
public void setTraceFilename(java.lang.String s)
Sets the file used bydumpConsole()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.
-
-