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 implementation of MatrixModel interface and it used to organize 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.
 java.awt.Dimension getSize()
          Gets the matrix dimension.
protected  void perform(MatrixEvent e)
          Fires the specified event to 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
 

Constructor Detail

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.
Method Detail

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.

getSize

public java.awt.Dimension getSize()
Gets the matrix dimension. The result is represented with java.awt.Dimension class where width field correspond to number of rows and height field correspond to number of columns.
Returns:
a matrix dimension.

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)
Removes the specified number of rows starting from the given row.
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)
Removes the specified number of columns starting from the given column.
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(MatrixEvent e)
Fires the specified event to registered matrix listeners.
Parameters:
e - the specified event.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org