T
- the type of objects stored in the 2D arraypublic class GridModel<T>
extends java.lang.Object
Constructor and Description |
---|
GridModel(T[][] grid)
Constructs a grid initialized with the given grid data.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(GridListener<T> l)
Add a listener that should be notified whenever the grid changes.
|
int |
getNumCols()
Returns the number of columns in the grid.
|
int |
getNumRows()
Returns the number of rows in the grid.
|
T |
getValueAt(int row,
int col)
Returns the object at (row, col) in the grid.
|
void |
removeListener(GridListener<T> l)
Removes a listener from the list of listeners.
|
void |
setGrid(T[][] grid)
Replaces the 2D array with a completely new 2D array and calls gridReplaced() on each listener.
|
void |
setValueAt(int row,
int col,
T val)
Sets the value at the given (row, col) and calls cellChanged() on each listener if the value
is not equal according to the equals() method or if it changed from null to a non-null value.
|
java.lang.String |
toString()
Returns a string representation of this grid along with a list of listeners.
|
public GridModel(T[][] grid)
grid
- the 2d array of data to initialize the grid to.java.lang.IllegalArgumentException
- if the gridData is nullpublic void addListener(GridListener<T> l)
l
- the listener to addpublic void removeListener(GridListener<T> l)
l
- the listener to removepublic int getNumRows()
public int getNumCols()
public T getValueAt(int row, int col)
row
- the rowcol
- the columnpublic void setValueAt(int row, int col, T val)
row
- the rowcol
- the columnval
- the new valuepublic void setGrid(T[][] grid)
grid
- the new 2D arrayjava.lang.IllegalArgumentException
- if the gridData is nullpublic java.lang.String toString()
toString
in class java.lang.Object