org.zaval.data
Class Matrix
java.lang.Object
|
+--org.zaval.data.Matrix
- All Implemented Interfaces:
- MatrixModel
- public class Matrix
- extends java.lang.Object
- implements MatrixModel
This class is an implementation of the MatrixModel interface to work with
matrix-like structures.
|
Constructor Summary |
Matrix(int rows,
int cols)
Constructs the matrix component with the specified number of rows an columns. |
|
Method Summary |
void |
addMatrixListener(MatrixListener m)
Adds the matrix listener to be notified whenever the matrix cell has been updated or
the matrix dimension has been changed. |
java.lang.Object |
get(int index)
Gets the value at the specified cell index. |
java.lang.Object |
get(int row,
int col)
Gets the value of the specified cell. |
int |
getCols()
Gets the number of columns. |
int |
getRows()
Gets the number of rows. |
protected void |
perform(int row,
int col,
java.lang.Object prevValue,
boolean isResized)
Fires the matrix event to the registered matrix listeners. |
void |
put(int row,
int col,
java.lang.Object obj)
Updates the specified cell with the specified value. |
java.awt.Point |
put(int index,
java.lang.Object obj)
Updates a cell with the specified value at the specified index. |
void |
removeCols(int begcol,
int count)
Removes the specified number of columns starting from the given column. |
void |
removeMatrixListener(MatrixListener m)
Removes the matrix listener. |
void |
removeRows(int begrow,
int count)
Removes the specified number of rows starting from the given row. |
void |
setCols(int cols)
Sets the number of columns. |
void |
setRows(int rows)
Sets the number of rows. |
void |
setSize(int rows,
int cols)
Sets the specified matrix dimension. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Matrix
public Matrix(int rows,
int cols)
- Constructs the matrix component with the specified number of rows an columns.
- Parameters:
rows - the specified number of rows.cols - the specified number of columns.
getRows
public int getRows()
- Gets the number of rows.
- Specified by:
getRows in interface MatrixModel
- Returns:
- a number of rows.
getCols
public int getCols()
- Gets the number of columns.
- Specified by:
getCols in interface MatrixModel
- Returns:
- a number of columns.
setRows
public void setRows(int rows)
- Sets the number of rows.
- Parameters:
rows - the specified number of rows.
setCols
public void setCols(int cols)
- Sets the number of columns.
- Parameters:
cols - the specified number of columns.
setSize
public void setSize(int rows,
int cols)
- Sets the specified matrix dimension.
- Parameters:
rows - the specified number of rows.cols - the specified number of columns.
put
public void put(int row,
int col,
java.lang.Object obj)
- Updates the specified cell with the specified value. If the specified row or column
is out of bounds the matrix dimension than the matrix size will be extended
automatically.
- Specified by:
put in interface MatrixModel
- Parameters:
row - the specified row.col - the specified column.obj - the specified value to update the cell value.
put
public java.awt.Point put(int index,
java.lang.Object obj)
- Updates a cell with the specified value at the specified index. Any cell of the
matrix object can be identified by row and column or by index. The index for the
specified cell (row, col) is calculated using following formula:
((row*columns) + col). If the index is out of bounds the matrix dimension
than the matrix size will be extended automatically.
- Parameters:
index - the specified index.obj - the specified value to update the cell value.
get
public java.lang.Object get(int row,
int col)
- Gets the value of the specified cell.
- Specified by:
get in interface MatrixModel
- Parameters:
row - the specified row.col - the specified column.- Returns:
- a value.
get
public java.lang.Object get(int index)
- Gets the value at the specified cell index.
- Parameters:
index - the specified cell index.- Returns:
- a value.
removeRows
public void removeRows(int begrow,
int count)
- Description copied from interface:
MatrixModel
- Removes the specified number of rows starting from the given row.
- Specified by:
removeRows in interface MatrixModel
- Following copied from interface:
org.zaval.data.MatrixModel
- Parameters:
begrow - the first removed row.count - the number of rows to be removed starting from the first row.
removeCols
public void removeCols(int begcol,
int count)
- Description copied from interface:
MatrixModel
- Removes the specified number of columns starting from the given column.
- Specified by:
removeCols in interface MatrixModel
- Following copied from interface:
org.zaval.data.MatrixModel
- Parameters:
begcol - the first removed column.count - the number of columns to be removed starting from the first column.
addMatrixListener
public void addMatrixListener(MatrixListener m)
- Adds the matrix listener to be notified whenever the matrix cell has been updated or
the matrix dimension has been changed.
- Specified by:
addMatrixListener in interface MatrixModel
- Parameters:
m - the matrix listener.
removeMatrixListener
public void removeMatrixListener(MatrixListener m)
- Removes the matrix listener.
- Specified by:
removeMatrixListener in interface MatrixModel
- Parameters:
m - the matrix listener.
perform
protected void perform(int row,
int col,
java.lang.Object prevValue,
boolean isResized)
- Fires the matrix event to the registered matrix listeners.
- Parameters:
row - the specified row of the cell that has been updated or previous rows number.col - the specified column of the cell that has been updated or previous columns number.prevValue - the specified previous cell value.isResized - the specified event type. Use true if the matrix has been resized
and use false if the matrix cell has been modified.
|