pt.ua.gboard
Class Gelem

java.lang.Object
  extended by pt.ua.gboard.Gelem
Direct Known Subclasses:
ImageGelem, LabyrinthGelem, MutableGelem, OneColorGelem

public abstract class Gelem
extends java.lang.Object

Abstract graphical element occupying a rectangular group of cells in a GBoard.

invariant: numberOfLines() >= 1 && numberOfColumns() >= 1

This class follows DbC(tm) methodology. Where possible, contracts are implement with JML and native's Java assert.

Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
Gelem()
          Constructs a new Gelem (1x1 cells).
Gelem(int numberOfLines, int numberOfColumns)
          Constructs a new Gelem (numberOfLines x numberOfColumns cells).
 
Method Summary
abstract  void draw(java.awt.Graphics g, int line, int column, int cellWidth, int cellHeight, java.awt.Color background)
          Draw Gelem in GBoard (it should be exported only to GBoard).
abstract  void erase(java.awt.Graphics g, int line, int column, int cellWidth, int cellHeight, java.awt.Color background)
          Erase Gelem from GBoard (it should be exported only to GBoard).
 int height(int cellHeight)
          Height (in pixels) of current gelem.
 boolean intersects(int line, int column, Gelem other, int otherLine, int otherColumn)
          Does current gelem at position (line, column) intersects gelem other at position (otherLine, otherColumn)?
 boolean isMutable()
          Is gelem mutable? A mutable gelem automatically updates GBoard when updated.
 MutableGelem mutable()
          If mutable, returns a mutable version of current gelem, otherwise it returns null.
 int numberOfColumns()
          Column dimensions of Gelem measured in number of cells.
 int numberOfLines()
          Line dimensions of Gelem measured in number of cells.
 int width(int cellWidth)
          Width (in pixels) of current gelem.
 int x(int column, int cellWidth)
          Pixel x position of gelem.
 int y(int line, int cellHeight)
          Pixel y position of gelem.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Gelem

public Gelem()
Constructs a new Gelem (1x1 cells).


Gelem

public Gelem(int numberOfLines,
             int numberOfColumns)
Constructs a new Gelem (numberOfLines x numberOfColumns cells).

requires: numberOfLines >= 1 && numberOfColumns >= 1

Parameters:
numberOfLines - number of lines
numberOfColumns - number of columns
Method Detail

numberOfLines

public int numberOfLines()
Line dimensions of Gelem measured in number of cells.

Returns:
int number of lines

numberOfColumns

public int numberOfColumns()
Column dimensions of Gelem measured in number of cells.

Returns:
int number of columns

draw

public abstract void draw(java.awt.Graphics g,
                          int line,
                          int column,
                          int cellWidth,
                          int cellHeight,
                          java.awt.Color background)
Draw Gelem in GBoard (it should be exported only to GBoard).

requires: g != null && background != null (incomplete!)

Parameters:
g - Java's Graphics object to use in drawing
line - line in GBoard to draw Gelem.
column - column in GBoard to draw Gelem.
cellWidth - number of horizontal pixels per cell
cellHeight - number of vertical pixels per cell
background - background color

erase

public abstract void erase(java.awt.Graphics g,
                           int line,
                           int column,
                           int cellWidth,
                           int cellHeight,
                           java.awt.Color background)
Erase Gelem from GBoard (it should be exported only to GBoard).

requires: g != null && background != null (incomplete!)

Parameters:
g - Java's Graphics object to use in drawing
line - line in GBoard to draw Gelem.
column - column in GBoard to draw Gelem.
cellWidth - number of horizontal pixels per cell
cellHeight - number of vertical pixels per cell

intersects

public boolean intersects(int line,
                          int column,
                          Gelem other,
                          int otherLine,
                          int otherColumn)
Does current gelem at position (line, column) intersects gelem other at position (otherLine, otherColumn)?

requires: other != null

Parameters:
line - line of current Gelem.
column - column of current Gelem.
other - the other gelem
otherLine - line of other Gelem.
otherColumn - column of other Gelem.
Returns:
boolean true if they intersect

x

public int x(int column,
             int cellWidth)
Pixel x position of gelem.

Parameters:
column - column of gelem.
cellWidth - number of horizontal pixels per cell
Returns:
int position

y

public int y(int line,
             int cellHeight)
Pixel y position of gelem.

Parameters:
line - line of gelem.
cellHeight - number of vertical pixels per cell
Returns:
int position

width

public int width(int cellWidth)
Width (in pixels) of current gelem.

Parameters:
cellWidth - number of horizontal pixels per cell
Returns:
int number of pixels

height

public int height(int cellHeight)
Height (in pixels) of current gelem.

Parameters:
cellHeight - number of vertical pixels per cell
Returns:
int number of pixels

isMutable

public boolean isMutable()
Is gelem mutable? A mutable gelem automatically updates GBoard when updated.

Returns:
boolean true if mutable, otherwise retuns false

mutable

public MutableGelem mutable()
If mutable, returns a mutable version of current gelem, otherwise it returns null.

Returns:
boolean a reference to an object if mutable, otherwise retuns null