Game of Life 1.5

org.bitstorm.gameoflife
Class CellGridCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended byorg.bitstorm.gameoflife.CellGridCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class CellGridCanvas
extends java.awt.Canvas

Subclass of Canvas, which makes the cellgrid visible. Communicates via CellGrid interface.

Author:
Edwin Martin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  CellGrid cellGrid
           
private  int cellSize
           
private  boolean cellUnderMouse
           
private  java.util.Vector listeners
           
private  int newCellSize
           
private  Shape newShape
           
private  java.awt.Graphics offScreenGraphics
           
private  java.awt.Graphics offScreenGraphicsDrawed
          Image, containing the drawed grid.
private  java.awt.Image offScreenImage
          Image for double buffering, to prevent flickering.
private  java.awt.Image offScreenImageDrawed
           
 
Fields inherited from class java.awt.Canvas
 
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
CellGridCanvas(CellGrid cellGrid, int cellSize)
          Constructs a CellGridCanvas.
 
Method Summary
 void draw(int x, int y)
          Draw in this cell.
 java.awt.Dimension getMinimumSize()
          This is the minimum size (size of one cell).
 java.awt.Dimension getPreferredSize()
          This is the preferred size.
 void paint(java.awt.Graphics g)
          Draw this generation.
 void resized()
          The grid is resized (by window resize or zooming).
 void saveCellUnderMouse(int x, int y)
          Remember state of cell for drawing.
 void setAfterWindowResize(Shape newShape, int newCellSize)
          Settings to appy after a window-resize.
 void setCellSize(int cellSize)
          Set cell size (zoom factor)
 void setShape(Shape shape)
          Draws shape in grid.
 void update(java.awt.Graphics g)
          Use double buffering.
 
Methods inherited from class java.awt.Canvas
addNotify, 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, 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, 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, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, 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, setName, 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

cellUnderMouse

private boolean cellUnderMouse

offScreenImage

private java.awt.Image offScreenImage
Image for double buffering, to prevent flickering.


offScreenGraphics

private java.awt.Graphics offScreenGraphics

offScreenImageDrawed

private java.awt.Image offScreenImageDrawed

offScreenGraphicsDrawed

private java.awt.Graphics offScreenGraphicsDrawed
Image, containing the drawed grid.


cellSize

private int cellSize

cellGrid

private CellGrid cellGrid

listeners

private java.util.Vector listeners

newCellSize

private int newCellSize

newShape

private Shape newShape
Constructor Detail

CellGridCanvas

public CellGridCanvas(CellGrid cellGrid,
                      int cellSize)
Constructs a CellGridCanvas.

Parameters:
cellGrid - the GoL cellgrid
cellSize - size of cell in pixels
Method Detail

setCellSize

public void setCellSize(int cellSize)
Set cell size (zoom factor)

Parameters:
cellSize - Size of cell in pixels

resized

public void resized()
The grid is resized (by window resize or zooming). Also apply post-resize properties when necessary


saveCellUnderMouse

public void saveCellUnderMouse(int x,
                               int y)
Remember state of cell for drawing.

Parameters:
x - x-coordinate
y - y-coordinate

draw

public void draw(int x,
                 int y)
Draw in this cell.

Parameters:
x - x-coordinate
y - y-coordinate

update

public void update(java.awt.Graphics g)
Use double buffering.

See Also:
Component.update(java.awt.Graphics)

paint

public void paint(java.awt.Graphics g)
Draw this generation.

See Also:
Component.paint(java.awt.Graphics)

getPreferredSize

public java.awt.Dimension getPreferredSize()
This is the preferred size.

See Also:
Component.getPreferredSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()
This is the minimum size (size of one cell).

See Also:
Component.getMinimumSize()

setAfterWindowResize

public void setAfterWindowResize(Shape newShape,
                                 int newCellSize)
Settings to appy after a window-resize.

Parameters:
newShape - new shape
newCellSize - new cellSize

setShape

public void setShape(Shape shape)
              throws ShapeException
Draws shape in grid.

Parameters:
shape - name of shape
Returns:
true when shape fits, false otherwise
Throws:
ShapeException - if the shape does not fit on the canvas

Game of Life 1.5

This API descibes the Game of Life program, written by Edwin Martin. The source code is available online too.

Copyright 1996-2004 Edwin Martin <edwin@bitstorm.org>.