edu.cs.ai.kreator.ui.gui.components
Class ConsolePane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.cs.ai.kreator.ui.gui.components.Tab
                      extended by edu.cs.ai.kreator.ui.gui.components.ConsolePane
All Implemented Interfaces:
KreatorConsole, Stainable, java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CaretListener

public class ConsolePane
extends Tab
implements java.awt.event.KeyListener, javax.swing.event.CaretListener, KreatorConsole, java.awt.event.ActionListener

Author:
KJ
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
static org.apache.log4j.Logger LOG
           
static javax.swing.text.MutableAttributeSet OUTPUT_ATTRS
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
 
Constructor Summary
ConsolePane(java.lang.String name)
          Default constructor.
 
Method Summary
 void abortWorker()
          Aborts current worker of the consolePane
 void actionPerformed(java.awt.event.ActionEvent e)
          Listens for actions from the tool bar.
 void addChangeListener(javax.swing.event.ChangeListener listener)
           
 void addStainedListener(StainedListener listener)
          Adds a StainedListener interested in this Stainable's state.
 void appendAnswerToReport(java.lang.String answer)
          Appends a message to the report view.
 void appendCommandToReport(java.lang.String command)
          Appends a command to the report view.
 void caretUpdate(javax.swing.event.CaretEvent e)
          Checks whether the caret has been moved to some position outside of the input line.
 void chancelWorkerCheckTimer()
          Cancels the worker check timer.
 void clearConsoleTextPane()
          Clears the output in this console pane and prints the console prompt afterwards.
 void clearConsoleTextPane(boolean doPrintPrompt)
          Clears the output in this console pane.
 java.util.List<java.lang.String> getCmdHistory()
          Returns the command history, so that it can be saved in the project.
 javax.swing.Icon getIcon()
          This icon will be displayed in the tab title (e.g. a close button).
 KreatorScriptEngine getScriptEngine()
          Returns the script engine of this concole.
 Token getTokenToComplete()
           
 boolean isRunning()
          Returns true if a worker is currently registered with this console, and thus no other worker should start working in here.
 void keyPressed(java.awt.event.KeyEvent e)
          Catches user input like: - '\n': Execute the command - Backspace: consume this, if it's pressed outside of the input line - Up/Down: Command history - Tab: Word completion
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void performTabButtonAction()
          This method will be called when the user clicks on the tab's title-button.
 void printErrorLine(java.lang.String message)
          Prints a message with the ERROR-AttributeSet
 void printHelpLines(java.lang.String helpText)
           
 void printInfoLine(java.lang.String message)
          Prints a message with the INFO AttributeSet
 void printInputLine(java.lang.String command)
          Sets the input line of this console to line
 void printJavaScriptErrorLine(java.lang.String message)
          Prints a message with the SYSTAXERROR AttributeSet
 void printOutputLine(java.lang.String message)
          Prints a message with the "OUTPUT"-AttibuteSet
 void printOutputLine(java.lang.String message, javax.swing.text.AttributeSet attrs)
          Prints a message with a given AttributeSet
 void printPrompt()
          Prints a prompt.
 void printThreadingLine(java.lang.String message)
          Prints a message with the THREADING_ATTRS AttributeSet
 void printVerboseLine(java.lang.String message)
          If Config allows, prints a verbose message with the "VERBOSE"-AttibuteSet, otherwise the message is logged on debug level.
 void registerWorker(KreatorWorker<?> w)
          Register a worker with this console.
 boolean requestFocusInWindow()
          If the console requests the focus, it sets the focus to its TextPane
 void resetScriptEngine(boolean doPrintPrompt)
          Resets the script engine.
 void setAutoScroll(boolean autoScroll)
          If auto scroll is set to true (default), the caret position will be set to the end of the text pane, when appendTextLine() is called.
 void setCmdHistory(java.util.List<java.lang.String> commandList)
          Sets the console's command history. e.g. when loading a new project.
 void setEditable(boolean b)
          If b is true the console pane is editable.
 void setHover(boolean hover)
          sets if the mouse is hovering over the close button
 void setMinCaretPos(int endPosition)
          Updates the minimal caret position and moves the caret to this position.
 void setScriptEngine(KreatorScriptEngine engine)
          Sets the KreatorScriptEngine used by this console.
 void startWorkerCheckTimer()
          Starts timer to check if the worker is responsive.
 void togglePauseResumeButton()
          Toggles the state of the pause/resume button.
 boolean toggleView()
          Toggles between console and report view.
 void unregisterWorker(KreatorWorker<?> w)
          Unregisters the currently running worker.
 
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, 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, transferFocusBackward, 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, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG

OUTPUT_ATTRS

public static final javax.swing.text.MutableAttributeSet OUTPUT_ATTRS
Constructor Detail

ConsolePane

public ConsolePane(java.lang.String name)
Default constructor. Initializes everything needed to run and display a KReatorConsole: Textpane, listeners, command history and wordcompleter.

Method Detail

toggleView

public boolean toggleView()
Toggles between console and report view.

Specified by:
toggleView in interface KreatorConsole
Returns:
true, if the view shows the console after execution of this method.

setEditable

public void setEditable(boolean b)
If b is true the console pane is editable.

Parameters:
b - if true the console pane is editable.

resetScriptEngine

public void resetScriptEngine(boolean doPrintPrompt)
Resets the script engine.

Specified by:
resetScriptEngine in interface KreatorConsole
Parameters:
doPrintPrompt - if true a prompt is printed after resetting the engine.

clearConsoleTextPane

public void clearConsoleTextPane(boolean doPrintPrompt)
Clears the output in this console pane.

Parameters:
doPrintPrompt - if true, the console prompt is printed after cleaning the pane

clearConsoleTextPane

public void clearConsoleTextPane()
Clears the output in this console pane and prints the console prompt afterwards.

Specified by:
clearConsoleTextPane in interface KreatorConsole
See Also:
#resetScriptEngine()

getTokenToComplete

public Token getTokenToComplete()

setAutoScroll

public void setAutoScroll(boolean autoScroll)
If auto scroll is set to true (default), the caret position will be set to the end of the text pane, when appendTextLine() is called.

Parameters:
autoScroll -

printPrompt

public void printPrompt()
Prints a prompt.


printInputLine

public void printInputLine(java.lang.String command)
Description copied from interface: KreatorConsole
Sets the input line of this console to line

Specified by:
printInputLine in interface KreatorConsole

printOutputLine

public void printOutputLine(java.lang.String message)
Description copied from interface: KreatorConsole
Prints a message with the "OUTPUT"-AttibuteSet

Specified by:
printOutputLine in interface KreatorConsole

printOutputLine

public void printOutputLine(java.lang.String message,
                            javax.swing.text.AttributeSet attrs)
Description copied from interface: KreatorConsole
Prints a message with a given AttributeSet

Specified by:
printOutputLine in interface KreatorConsole

printVerboseLine

public void printVerboseLine(java.lang.String message)
Description copied from interface: KreatorConsole
If Config allows, prints a verbose message with the "VERBOSE"-AttibuteSet, otherwise the message is logged on debug level.

Specified by:
printVerboseLine in interface KreatorConsole

printErrorLine

public void printErrorLine(java.lang.String message)
Description copied from interface: KreatorConsole
Prints a message with the ERROR-AttributeSet

Specified by:
printErrorLine in interface KreatorConsole

printJavaScriptErrorLine

public void printJavaScriptErrorLine(java.lang.String message)
Description copied from interface: KreatorConsole
Prints a message with the SYSTAXERROR AttributeSet

Specified by:
printJavaScriptErrorLine in interface KreatorConsole

printInfoLine

public void printInfoLine(java.lang.String message)
Description copied from interface: KreatorConsole
Prints a message with the INFO AttributeSet

Specified by:
printInfoLine in interface KreatorConsole

printThreadingLine

public void printThreadingLine(java.lang.String message)
Description copied from interface: KreatorConsole
Prints a message with the THREADING_ATTRS AttributeSet

Specified by:
printThreadingLine in interface KreatorConsole

printHelpLines

public void printHelpLines(java.lang.String helpText)

appendCommandToReport

public void appendCommandToReport(java.lang.String command)
Description copied from interface: KreatorConsole
Appends a command to the report view.

Specified by:
appendCommandToReport in interface KreatorConsole

appendAnswerToReport

public void appendAnswerToReport(java.lang.String answer)
Description copied from interface: KreatorConsole
Appends a message to the report view.
This message is automatically commented out.

Specified by:
appendAnswerToReport in interface KreatorConsole

getCmdHistory

public java.util.List<java.lang.String> getCmdHistory()
Returns the command history, so that it can be saved in the project. Respects Configuration.CONSOLE__MAXLENGTH_COMMAND_HISTORY.

Specified by:
getCmdHistory in interface KreatorConsole
Returns:
the command history, so that it can be saved in the project.

setCmdHistory

public void setCmdHistory(java.util.List<java.lang.String> commandList)
Sets the console's command history. e.g. when loading a new project.

Specified by:
setCmdHistory in interface KreatorConsole
Parameters:
commandList - A list of commands.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Catches user input like: - '\n': Execute the command - Backspace: consume this, if it's pressed outside of the input line - Up/Down: Command history - Tab: Word completion

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

caretUpdate

public void caretUpdate(javax.swing.event.CaretEvent e)
Checks whether the caret has been moved to some position outside of the input line.

Specified by:
caretUpdate in interface javax.swing.event.CaretListener

setMinCaretPos

public void setMinCaretPos(int endPosition)
Updates the minimal caret position and moves the caret to this position.

Parameters:
endPosition -

requestFocusInWindow

public boolean requestFocusInWindow()
If the console requests the focus, it sets the focus to its TextPane

Overrides:
requestFocusInWindow in class javax.swing.JComponent

getScriptEngine

public KreatorScriptEngine getScriptEngine()
Returns the script engine of this concole.

Specified by:
getScriptEngine in interface KreatorConsole
Returns:
the script engine of this concole.

abortWorker

public void abortWorker()
Aborts current worker of the consolePane


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Listens for actions from the tool bar.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

registerWorker

public void registerWorker(KreatorWorker<?> w)
Register a worker with this console. A worker does not necessarily be registered with his console, but only a registered worker can be paused or canceled by his console. Normally a worker should automatically register with his console, as soon as he starts running!

Specified by:
registerWorker in interface KreatorConsole

unregisterWorker

public void unregisterWorker(KreatorWorker<?> w)
Unregisters the currently running worker. Normally a worker unregisters himself when his execution is done.

Specified by:
unregisterWorker in interface KreatorConsole

togglePauseResumeButton

public void togglePauseResumeButton()
Toggles the state of the pause/resume button.

Specified by:
togglePauseResumeButton in interface KreatorConsole

startWorkerCheckTimer

public void startWorkerCheckTimer()
Starts timer to check if the worker is responsive.

Specified by:
startWorkerCheckTimer in interface KreatorConsole

chancelWorkerCheckTimer

public void chancelWorkerCheckTimer()
Cancels the worker check timer.

Specified by:
chancelWorkerCheckTimer in interface KreatorConsole

isRunning

public boolean isRunning()
Returns true if a worker is currently registered with this console, and thus no other worker should start working in here.

Specified by:
isRunning in interface KreatorConsole
Returns:
true if there is a worker registered

setHover

public void setHover(boolean hover)
sets if the mouse is hovering over the close button

Parameters:
hover -

getIcon

public javax.swing.Icon getIcon()
Description copied from class: Tab
This icon will be displayed in the tab title (e.g. a close button). It should represent the tabs state (stained/not-stained, running processes, ...)

Specified by:
getIcon in class Tab

performTabButtonAction

public void performTabButtonAction()
Description copied from class: Tab
This method will be called when the user clicks on the tab's title-button. It can be used to close the tab, or pause the running process, etc.

Specified by:
performTabButtonAction in class Tab

setScriptEngine

public void setScriptEngine(KreatorScriptEngine engine)
Description copied from interface: KreatorConsole
Sets the KreatorScriptEngine used by this console.
This can be used to overload KreatorScriptEngine.done(), which will be executed after each script.

Specified by:
setScriptEngine in interface KreatorConsole

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener listener)
Specified by:
addChangeListener in class Tab

addStainedListener

public void addStainedListener(StainedListener listener)
Description copied from interface: Stainable
Adds a StainedListener interested in this Stainable's state.

Specified by:
addStainedListener in interface Stainable
Parameters:
listener - a StainedListener interested in this Stainable's state