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:
ImageObserver
,MenuContainer
,Serializable
,Accessible
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, 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
Modifier and TypeMethodDescriptionvoid
Clears all the messages stored in the internal buffer from the beginning of theJConsolePane
.void
Clears only the messages that are displayed in the textarea.void
Destroys the console.void
dumpConsole
(String filename, boolean append) Dumps all the console messages (up to now) to a file (not only the messages displayed in the textarea).boolean
Gets append policy.boolean
Gets auto save status.Gets the background color of the textarea.Gets the text of the clear button.Gets the text of the close button.Gets the text for the popup window that confirms file overwrite.Gets the title for the popup window that confirms file overwrite.static JConsolePane
Singleton constructor.Gets the filechooser approve button text.Gets the filechooser title.Gets the foreground color of the textarea.int
If -1 no limit, else the messages will be flushed to 'traceFilename' and cleared when this limit is reached.Gets the default filename for the filechooser.Gets the text of the save button.Gets the selected text color of the textarea.Gets the selection color of the textarea.Gets the font of the textarea.Gets the file used bydumpConsole()
and all auto save methods.void
Hides the console.void
Hides the control buttons.void
setAppendFirstTime
(boolean b) Sets append policy.void
setAutoSave
(boolean b) Sets auto save status.void
Sets the background color of the textarea.void
Sets the text of the clear button.void
Sets the text of the close button.void
Sets the text for the popup window that confirms file overwrite.void
Sets the title for the popup window that confirms file overwrite.void
Sets the filechooser approve button text.void
Sets the filechooser title.void
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
Sets the default filename for the filechooser.void
Sets the text of the save button.void
Sets the selected text color of the textarea.void
Sets the selection color of the textarea.void
setTextFont
(Font f) Sets the font of the textarea.void
Sets the file used bydumpConsole()
and all auto save methods.void
Shows the console.void
Shows the control buttons.void
Attachs the new streams to stdout and stderr.void
Attachs the original streams to stdout and stderr.void
Updates the look and feel of theJConsolePane
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, 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 Details
-
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 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
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, useclearBufferMessages()
for this.- Parameters:
filename
- The filename to store all console's messages.append
- Iftrue
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 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 theJConsolePane
and it's components. MUST be called AFTER invoking:UIManager.setLookAndFeel()
in your application. -
getConfimTitle
Gets the title for the popup window that confirms file overwrite.- Returns:
- The title.
-
setConfimTitle
Sets the title for the popup window that confirms file overwrite.- Parameters:
s
- The title.
-
getConfimMessage
Gets the text for the popup window that confirms file overwrite.- Returns:
- The message.
-
setConfimMessage
Sets the text for the popup window that confirms file overwrite.- Parameters:
s
- The message.
-
getMessagesFilename
Gets the default filename for the filechooser.- Returns:
- The filename.
-
setMessagesFilename
Sets the default filename for the filechooser.- Parameters:
s
- The filename.
-
getTraceFilename
Gets the file used bydumpConsole()
and all auto save methods.- Returns:
- The filename.
-
setTraceFilename
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
Gets the foreground color of the textarea.- Returns:
- The color.
-
setForegroundColor
Sets the foreground color of the textarea.- Parameters:
c
- The color.
-
getBackgroundColor
Gets the background color of the textarea.- Returns:
- The color.
-
setBackgroundColor
Sets the background color of the textarea.- Parameters:
c
- The color.
-
getSelectedTextColor
Gets the selected text color of the textarea.- Returns:
- The color.
-
setSelectedTextColor
Sets the selected text color of the textarea.- Parameters:
c
- The color.
-
getSelectionColor
Gets the selection color of the textarea.- Returns:
- The color.
-
setSelectionColor
Sets the selection color of the textarea.- Parameters:
c
- The color.
-
getClearButtonText
Gets the text of the clear button.- Returns:
- The text.
-
setClearButtonText
Sets the text of the clear button.- Parameters:
s
- The text.
-
getSaveButtonText
Gets the text of the save button.- Returns:
- The text.
-
setSaveButtonText
Sets the text of the save button.- Parameters:
s
- The text.
-
getCloseButtonText
Gets the text of the close button.- Returns:
- The text.
-
setCloseButtonText
Sets the text of the close button.- Parameters:
s
- The text.
-
getFilechooserTitle
Gets the filechooser title.- Returns:
- The title.
-
setFilechooserTitle
Sets the filechooser title.- Parameters:
s
- The title.
-
getFilechooserApproveButtonText
Gets the filechooser approve button text.- Returns:
- The text.
-
setFilechooserApproveButtonText
Sets the filechooser approve button text.- Parameters:
s
- The text.
-
getTextFont
Gets the font of the textarea.- Returns:
- The font.
-
setTextFont
Sets the font of the textarea.- Parameters:
f
- The font.
-