Class ConsoleCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by ConsoleCanvas
All Implemented Interfaces:
FocusListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible
Direct Known Subclasses:
ConsoleCanvasGraphics

abstract class ConsoleCanvas
extends Canvas
implements FocusListener, Runnable


Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected static String CONSOLE_CURSOR_THREAD_NAME
          The name of thread for blinking the cursor.
protected  int cursorBlinking
           
protected  Thread cursorThread
          Information about the cursor.
protected  boolean cursorVisible
           
protected static int DEPTH
           
protected  Font font
          Information about the font used for text drawing.
protected  int fontBase
           
protected  int fontHeight
           
protected  int fontWidth
           
protected static int GREY_MARGIN
           
protected  boolean hasFocus
           
protected  boolean macOSX
           
protected static int MARGIN
          Constants for drawing the pane.
protected  int numCols
           
protected  int numRows
           
protected  int numXPixels
           
protected  int numYPixels
           
protected  ConsoleParent parentConsole
          Variables for controlling the consoleCanvas pane.
protected  SavePrint savePrint
           
protected static String SCREEN_UPDATER_THREAD_NAME
           
 
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
ConsoleCanvas(ConsoleParent parent, int rows, int columns, int fontSize)
          Creates the console canvas given the size of the screen in rows and columns and font size.
 
Method Summary
 void addNotify()
          Overrides addNotify in order to set up the cursor thread once the canvas has been created.
protected  void blinkCursor()
          Blinks the cursor off it was on and on if it was off.
 void focusGained(FocusEvent e)
          Changes the cursor from an empty square to a normal cursor.
 void focusLost(FocusEvent e)
          Changes the cursor from a normal cursor to an empty square.
abstract  int getCurrentColumn()
          Returns the current column number of the cursor.
abstract  int getCurrentRow()
          Returns the current row number of the cursor.
 Dimension getMinimumSize()
          Overrides the getMinimumSize method to specify the proper canvas size
 Dimension getPreferredSize()
          Overrides the getPreferredSize method to specify the proper canvas size
 void invertScreen()
          Inverts the console canvas for 50 milliseconds.
 boolean isFocusTraversable()
           
protected  boolean isMainRunning()
          This returns whether the main method is still alive.
 void killCursorThread()
          Kills the cursor thread (used when the Console window is closed).
 void printContents()
          Prints the contents of the window on the printer.
 void run()
          ConsoleCanvas implements the Runnable interface.
 void saveContents()
          Saves the contents of the window to a file.
 void setCursorVisible(boolean visible)
          Makes the blinking cursor visible or invisible.
protected  void toggleCursor()
          Toggles the visible cursor on the screen off or on.
 void update(Graphics g)
          Overrides the update method to redraw the screen using doDraw
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, paint
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONSOLE_CURSOR_THREAD_NAME

protected static final String CONSOLE_CURSOR_THREAD_NAME
The name of thread for blinking the cursor.

See Also:
Constant Field Values

cursorBlinking

protected int cursorBlinking

cursorThread

protected Thread cursorThread
Information about the cursor.


cursorVisible

protected boolean cursorVisible

DEPTH

protected static final int DEPTH
See Also:
Constant Field Values

font

protected Font font
Information about the font used for text drawing.


fontBase

protected int fontBase

fontHeight

protected int fontHeight

fontWidth

protected int fontWidth

GREY_MARGIN

protected static final int GREY_MARGIN
See Also:
Constant Field Values

hasFocus

protected boolean hasFocus

macOSX

protected boolean macOSX

MARGIN

protected static final int MARGIN
Constants for drawing the pane.

See Also:
Constant Field Values

numCols

protected int numCols

numRows

protected int numRows

numXPixels

protected int numXPixels

numYPixels

protected int numYPixels

parentConsole

protected ConsoleParent parentConsole
Variables for controlling the consoleCanvas pane.


savePrint

protected SavePrint savePrint

SCREEN_UPDATER_THREAD_NAME

protected static final String SCREEN_UPDATER_THREAD_NAME
See Also:
Constant Field Values
Constructor Detail

ConsoleCanvas

public ConsoleCanvas(ConsoleParent parent,
                     int rows,
                     int columns,
                     int fontSize)
Creates the console canvas given the size of the screen in rows and columns and font size.

Parameters:
parent - The parent Console class.
rows - The height of the canvas in rows of text.
columns - The width of the canvas in columns of text.
fontSize - The size of the font in the canvas.
Method Detail

addNotify

public void addNotify()
Overrides addNotify in order to set up the cursor thread once the canvas has been created.

Overrides:
addNotify in class Canvas

blinkCursor

protected void blinkCursor()
Blinks the cursor off it was on and on if it was off.


focusGained

public void focusGained(FocusEvent e)
Changes the cursor from an empty square to a normal cursor. Called by the system when the ConsoleCanvas gains focus.

Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Changes the cursor from a normal cursor to an empty square. Called by the system when the ConsoleCanvas loses focus.

Specified by:
focusLost in interface FocusListener

getCurrentColumn

public abstract int getCurrentColumn()
Returns the current column number of the cursor.

Returns:
The current column number of the cursor.

getCurrentRow

public abstract int getCurrentRow()
Returns the current row number of the cursor.

Returns:
The current row number of the cursor.

getMinimumSize

public Dimension getMinimumSize()
Overrides the getMinimumSize method to specify the proper canvas size

Overrides:
getMinimumSize in class Component

getPreferredSize

public Dimension getPreferredSize()
Overrides the getPreferredSize method to specify the proper canvas size

Overrides:
getPreferredSize in class Component

invertScreen

public void invertScreen()
Inverts the console canvas for 50 milliseconds.


isFocusTraversable

public boolean isFocusTraversable()
Overrides:
isFocusTraversable in class Component

isMainRunning

protected boolean isMainRunning()
This returns whether the main method is still alive. If it is not, then it means that the main thread of execution has terminated in the user's program.

Returns:
Whether the main thread of execution is alive.

killCursorThread

public void killCursorThread()
Kills the cursor thread (used when the Console window is closed).


printContents

public void printContents()
Prints the contents of the window on the printer.


run

public void run()
ConsoleCanvas implements the Runnable interface. When run, this thread blinks the cursor every 300 milliseconds and checks to see whether the program has fniished execution.

Specified by:
run in interface Runnable

saveContents

public void saveContents()
Saves the contents of the window to a file.


setCursorVisible

public void setCursorVisible(boolean visible)
Makes the blinking cursor visible or invisible.

Parameters:
visible - Whether the cursor should be visible or not.

toggleCursor

protected void toggleCursor()
Toggles the visible cursor on the screen off or on.


update

public void update(Graphics g)
Overrides the update method to redraw the screen using doDraw

Overrides:
update in class Canvas