fr.umlv.lawrence
Class DefaultGridModel<E>

java.lang.Object
  extended by fr.umlv.lawrence.GridModel<E>
      extended by fr.umlv.lawrence.DefaultGridModel<E>
Type Parameters:
E - type of cell elements.

public class DefaultGridModel<E>
extends GridModel<E>

Default implementation of a GridModel whose back end are two ArrayList (for double buffering), where update can either be direct, or using back buffer

Author:
Julien Cervelle

Constructor Summary
DefaultGridModel(Collection<? extends E>[][] init)
          Construct of GridModel, given its dimension and the initial content of each cells
DefaultGridModel(int width, int height)
           
DefaultGridModel(int width, int height, Collection<? extends E> defaultValue)
          Construct of GridModel, given its dimension and the initial content of each cells
 
Method Summary
 void addDeffered(int x, int y, E element)
          Add an element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().
 void addGridListener(GridListener listener)
          Register a GridListener to be notified of changes in the model
 boolean contains(Location location)
          Returns if a location lies within the model
 int getHeight()
           
 int getWidth()
           
 void insertDeffered(int x, int y, E element, int position)
          Insert an element in cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().
 void removeAtDeffered(int x, int y, int position)
          remove element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().
 void removeDeffered(int x, int y, E element)
          remove element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().
 void removeGridListener(GridListener listener)
          Remove a GridListener notified of changes in the model
 void setAtDeffered(int x, int y, E element, int position)
          set element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().
 void setDeffered(int x, int y, Collection<? extends E> elements)
          Change all elements of cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().
 void setHighligthElement(int x, int y, E element)
          Set or remove the highlight element at a location.
 void setHighligthElement(Location location, E element)
          Set or remove the highlight element at a location.
 void swap()
          Ask deferred changes to become effective.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultGridModel

public DefaultGridModel(int width,
                        int height,
                        Collection<? extends E> defaultValue)
Construct of GridModel, given its dimension and the initial content of each cells

Parameters:
height - height of the grid
width - width of the grid
defaultValue - elements of all cells

DefaultGridModel

public DefaultGridModel(int width,
                        int height)

DefaultGridModel

public DefaultGridModel(Collection<? extends E>[][] init)
Construct of GridModel, given its dimension and the initial content of each cells

Parameters:
init - initial values of the model, first coordinate is abscisse and second is ordinate
Method Detail

getHeight

public int getHeight()
Specified by:
getHeight in class GridModel<E>
Returns:
the height of the grid (number of cells)

getWidth

public int getWidth()
Specified by:
getWidth in class GridModel<E>
Returns:
the width of the grid (number of cells)

setHighligthElement

public void setHighligthElement(int x,
                                int y,
                                E element)
Set or remove the highlight element at a location. If the element is null, the current highlight element at the location is removed.

Parameters:
x - the abscissa of the highlight element.
y - the ordinate of the highlight element.
element - the highlight element or null to remove it.

setHighligthElement

public void setHighligthElement(Location location,
                                E element)
Set or remove the highlight element at a location. If the element is null, the current highlight element at the location is removed.

Parameters:
location - the location of the highlight element.
element - the highlight element or null.

addDeffered

public void addDeffered(int x,
                        int y,
                        E element)
Add an element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().

Parameters:
x - x coordinate of the cell
y - y coordinate of the cell
element - new cell content
See Also:
swap()

insertDeffered

public void insertDeffered(int x,
                           int y,
                           E element,
                           int position)
Insert an element in cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().

Parameters:
x - x coordinate of the cell
y - y coordinate of the cell
element - new cell content
position - position to insert the element
See Also:
swap()

setAtDeffered

public void setAtDeffered(int x,
                          int y,
                          E element,
                          int position)
set element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().

Parameters:
x - x coordinate of the cell
y - y coordinate of the cell
element - new cell content
position - position to insert the element
See Also:
swap()

removeDeffered

public void removeDeffered(int x,
                           int y,
                           E element)
remove element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().

Parameters:
x - x coordinate of the cell
y - y coordinate of the cell
element - to remove
See Also:
swap()

removeAtDeffered

public void removeAtDeffered(int x,
                             int y,
                             int position)
remove element to cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().

Parameters:
x - x coordinate of the cell
y - y coordinate of the cell
position - the position of the element in the cell to remove
See Also:
swap()

setDeffered

public void setDeffered(int x,
                        int y,
                        Collection<? extends E> elements)
Change all elements of cell (x,y), asking the change to be done in the back buffer, and only displayed by a call to swap().

Parameters:
x - x coordinate of the cell
y - y coordinate of the cell
elements - new cell content
See Also:
swap()

swap

public void swap()
Ask deferred changes to become effective. Listeners are notified of the change.

See Also:
setDeffered(int, int, Collection)

addGridListener

public void addGridListener(GridListener listener)
Description copied from class: GridModel
Register a GridListener to be notified of changes in the model

Specified by:
addGridListener in class GridModel<E>
Parameters:
listener - the GridListener to register

removeGridListener

public void removeGridListener(GridListener listener)
Description copied from class: GridModel
Remove a GridListener notified of changes in the model

Specified by:
removeGridListener in class GridModel<E>
Parameters:
listener - the GridListener to remove

contains

public boolean contains(Location location)
Returns if a location lies within the model

Parameters:
location - the location
Returns:
if a location lies within the model