Class ConsoleCanvasGraphics

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

 class ConsoleCanvasGraphics
extends ConsoleCanvas
implements DrawGraphics


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  int cursorCol
           
protected  int cursorRow
           
protected  boolean inXORMode
           
protected static int NO_SCALING
           
protected  Image offscreenImage
          Variables for controlling the consoleCanvas pane.
protected  Color xorColor
           
 
Fields inherited from class ConsoleCanvas
CONSOLE_CURSOR_THREAD_NAME, cursorBlinking, cursorThread, cursorVisible, DEPTH, font, fontBase, fontHeight, fontWidth, GREY_MARGIN, hasFocus, macOSX, MARGIN, numCols, numRows, numXPixels, numYPixels, parentConsole, savePrint, 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
ConsoleCanvasGraphics(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 device dependent features once the canvas has actually been created.
 void clearRect(int x, int y, int width, int height)
          Clears a rectangle on the console canvas.
 void clearScreen(Color bgColor)
          Clears the entire console canvas to a specified colour
 void clearToEOL(int row, int col, Color bgColor)
          Clears a rectangle on console canvas from the specified row and column to the end of line
 void copyArea(int x, int y, int width, int height, int deltaX, int deltaY)
          Copies an area of the screen from (x, y) to (x + width, y + height) onto the screen with top corner at (x + delta_x, y + delta_y).
 void draw3DRect(int x, int y, int width, int height, boolean raised, Color color)
          Draws a 3D rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle, Color color)
          Draws an arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.
 void drawImage(Image img, int x, int y, ImageObserver obs)
          Draws an image at (x, y).
 void drawLine(int x1, int y1, int x2, int y2, Color color)
          Draws a line from (x1, y1) to (x2, y2) in specified colour.
 void drawOval(int x, int y, int width, int height, Color color)
          Draws an oval on the screen in the sqaure from (x, y) to (x + width, y + height) in specified colour.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints, Color color)
          Draws a polygon.
 void drawRect(int x, int y, int width, int height, Color color)
          Draws a rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight, Color color)
          Draws a rounded rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.
 void drawString(String str, int x, int y, Font font, Color color)
          Draws a line from (x1, y1) to (x2, y2) in specified colour.
 void drawText(int row, int col, String text, Color fgColor, Color bgColor)
          Draws the specified text to the screen at the specified row and column using the specified foreground and background colours.
 void drawWindowToGraphics(Graphics g)
          This routine is used to implement the saving and printing.
 void drawWindowToGraphics(Graphics g, int pageWidth, int pageHeight)
           
 void fill3DRect(int x, int y, int width, int height, boolean raised, Color color)
          Draws a filled 3D rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle, Color color)
          Draws a filled arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.
 void fillOval(int x, int y, int width, int height, Color color)
          Draws a filled oval on the screen in the sqaure from (x, y) to (x + width, y + height) in specified colour.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints, Color color)
          Draws a filled polygon.
 void fillRect(int x, int y, int width, int height, Color color)
          Draws a filled rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight, Color color)
          Draws a filled rounded rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.
 int getCurrentColumn()
          Returns the current column number of the cursor.
 int getCurrentRow()
          Returns the current row number of the cursor.
 int getDrawingAreaHeight()
          Returns the height of the console window in pixels.
 int getDrawingAreaWidth()
          Returns the width of the console window in pixels.
 int getMargin()
           
protected  Graphics getOffscreenGraphics(Color color)
          Returns the Graphics object associated with the offscreen bitmap.
protected  Graphics getOnscreenGraphics(Color color)
          Returns the Graphics object associated with the ConsoleCanvas.
 void paint(Graphics g)
          Overrides the paint method to redraw the screen using doDraw
 void scrollUpALine(Color bgColor)
          Scrolls up the entire ConsoleCanvas a single line.
 void setCursorPos(int row, int col)
          Sets the cursor to the specified row and column.
 void setPaintMode()
          Sets the drawing mode for any graphics to "Paint".
 void setXORMode(Color xorColor)
          Sets the drawing mode for any graphics to "XOR".
 
Methods inherited from class ConsoleCanvas
blinkCursor, focusGained, focusLost, getMinimumSize, getPreferredSize, invertScreen, isFocusTraversable, isMainRunning, killCursorThread, printContents, run, saveContents, setCursorVisible, toggleCursor, update
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
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

cursorCol

protected int cursorCol

cursorRow

protected int cursorRow

inXORMode

protected boolean inXORMode

NO_SCALING

protected static final int NO_SCALING
See Also:
Constant Field Values

offscreenImage

protected Image offscreenImage
Variables for controlling the consoleCanvas pane.


xorColor

protected Color xorColor
Constructor Detail

ConsoleCanvasGraphics

public ConsoleCanvasGraphics(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 device dependent features once the canvas has actually been created.

Overrides:
addNotify in class ConsoleCanvas

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Clears a rectangle on the console canvas.


clearScreen

public void clearScreen(Color bgColor)
Clears the entire console canvas to a specified colour


clearToEOL

public void clearToEOL(int row,
                       int col,
                       Color bgColor)
Clears a rectangle on console canvas from the specified row and column to the end of line


copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int deltaX,
                     int deltaY)
Copies an area of the screen from (x, y) to (x + width, y + height) onto the screen with top corner at (x + delta_x, y + delta_y).


draw3DRect

public void draw3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised,
                       Color color)
Draws a 3D rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.


drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle,
                    Color color)
Draws an arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.


drawImage

public void drawImage(Image img,
                      int x,
                      int y,
                      ImageObserver obs)
Draws an image at (x, y).


drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2,
                     Color color)
Draws a line from (x1, y1) to (x2, y2) in specified colour.


drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height,
                     Color color)
Draws an oval on the screen in the sqaure from (x, y) to (x + width, y + height) in specified colour.


drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints,
                        Color color)
Draws a polygon.


drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height,
                     Color color)
Draws a rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.


drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight,
                          Color color)
Draws a rounded rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.


drawString

public void drawString(String str,
                       int x,
                       int y,
                       Font font,
                       Color color)
Draws a line from (x1, y1) to (x2, y2) in specified colour.


drawText

public void drawText(int row,
                     int col,
                     String text,
                     Color fgColor,
                     Color bgColor)
Draws the specified text to the screen at the specified row and column using the specified foreground and background colours.


drawWindowToGraphics

public void drawWindowToGraphics(Graphics g)
This routine is used to implement the saving and printing. The Graphics object passed in is a printing or saving surface.

Specified by:
drawWindowToGraphics in interface DrawGraphics

drawWindowToGraphics

public void drawWindowToGraphics(Graphics g,
                                 int pageWidth,
                                 int pageHeight)
Specified by:
drawWindowToGraphics in interface DrawGraphics

fill3DRect

public void fill3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised,
                       Color color)
Draws a filled 3D rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.


fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle,
                    Color color)
Draws a filled arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.


fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height,
                     Color color)
Draws a filled oval on the screen in the sqaure from (x, y) to (x + width, y + height) in specified colour.


fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints,
                        Color color)
Draws a filled polygon.


fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height,
                     Color color)
Draws a filled rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.


fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight,
                          Color color)
Draws a filled rounded rectangle on the screen from (x, y) to (x + width, y + height) in specified colour.


getCurrentColumn

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

Specified by:
getCurrentColumn in class ConsoleCanvas
Returns:
The current column number of the cursor.

getCurrentRow

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

Specified by:
getCurrentRow in class ConsoleCanvas
Returns:
The current row number of the cursor.

getDrawingAreaHeight

public int getDrawingAreaHeight()
Returns the height of the console window in pixels.

Returns:
The height of the console window in pixels.

getDrawingAreaWidth

public int getDrawingAreaWidth()
Returns the width of the console window in pixels.

Returns:
The width of the console window in pixels.

getMargin

public int getMargin()
Specified by:
getMargin in interface DrawGraphics

getOffscreenGraphics

protected Graphics getOffscreenGraphics(Color color)
Returns the Graphics object associated with the offscreen bitmap. Sets the drawing mode and foreground colour appropriately.


getOnscreenGraphics

protected Graphics getOnscreenGraphics(Color color)
Returns the Graphics object associated with the ConsoleCanvas. Turns off the cursor (if necessary), sets the drawing mode, translates the coordinates to take into account the margins, sets the foreground colour and clips the drawing to the drawing area.


paint

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

Overrides:
paint in class Canvas

scrollUpALine

public void scrollUpALine(Color bgColor)
Scrolls up the entire ConsoleCanvas a single line. The blank space at the bottom is filled in the specified colour.


setCursorPos

public void setCursorPos(int row,
                         int col)
Sets the cursor to the specified row and column.


setPaintMode

public void setPaintMode()
Sets the drawing mode for any graphics to "Paint".


setXORMode

public void setXORMode(Color xorColor)
Sets the drawing mode for any graphics to "XOR".