Class IntMatrix

java.lang.Object
   |
   +----IntMatrix

public class IntMatrix
extends Object
implements DrawingObj
An example implementation of the DrawingObj interface that can be added to the drawingPanel (an instance of DrawingPanel). Similar to ComBox, an instance of this object class is added to the drawing panel by using the addDrawingObj method from DrawingPanel. This drawing obj can be removed from the drawing panel by invoking the removeObj method.

As an example, an instance of IntMatrix class can be added to an instance of DrawingPanel, namely drawingPanel by using the following:

	IntMatrix matrix1 = new IntMatrix(4);
	drawingPanel.addDrawingObj(matrix1);
	matrix1.setColor(....);
	matrix1.move(x, y);
	....
 
It can then be removed from the drawing panel by:
	drawingPanel.removeObj(matrix1);
 

This class implements a matrix representation with all integer entries.

See Also:
ComBox, addDrawingObj, removeObj

Constructor Index

 o IntMatrix(int)
Construct a square matrix with number of rows = number of columns as specified by the single parameter of the constructor.
 o IntMatrix(int, int)
Construct a matrix with the number of rows and columns specified by the parameters of the constructor.

Method Index

 o draw(Graphics)
This method has to be defined to fully implement the DrawingObj interface.
 o drawBox(Graphics, int, int, String, Color, Color, Font)
This method is used to draw each element of the matrix.
 o drawMatrix(Graphics, int, int, Color, Color)
This method is only called from the draw method which in turn is called from the drawing panel to draw the matrix based on the position and color previously set.
 o elem(int, int)
Get a particular element of the matrix specified by the position given in the parameters of the method.
 o getX()
Get the left most position of the matrix.
 o getY()
Get the top most position of the matrix.
 o incElem(int, int, int)
Increment the element specified by the first two parameters by the value specified by the third parameter.
 o move(int, int)
Move the matrix to the position specified with reference to the top left corner.
 o printMatrix()
Print out the contents of the matrix to the stdout.
 o restoreAll()
Restore all previously highlighted element of the matrix (black and gray).
 o restoreHighlight(int, int)
Restore the element which was highlighted using Color.black.
 o restoreHighlight2(int, int)
Restore the element which was highlighted using Color.gray.
 o setColLabels(String[])
Set a label to each column of the matrix based on the array of String passed in as the parameter.
 o setColor(Color, Color)
Set the foreground and background color for each element of the matrix.
 o setDiag(int[])
Set the value for each element on the main diagonal based on the array passed in as the parameter.
 o setElem(int, int, int)
Assign a new value to the entry specified by the parameters.
 o setHighlight(int, int)
Highlight an element of the matrix, colouring it to black.
 o setHighlight2(int, int)
Highlight an element of the matrix, colouring it to gray.
 o setLT(int)
Assign a value to all elements to the left hand side of the main diagonal (exclusive).
 o setRowLabels(String[])
Set a label to each row of the matrix based on the array of String passed in as the parameter.
 o setTitle(String)
Set a title to the matrix.

Constructors

 o IntMatrix
 public IntMatrix(int rows,
                  int columns)
Construct a matrix with the number of rows and columns specified by the parameters of the constructor.

Parameters:
rows - The number of rows of the new matrix.
columns - The number of columns of the new matrix.
 o IntMatrix
 public IntMatrix(int rows)
Construct a square matrix with number of rows = number of columns as specified by the single parameter of the constructor.

Parameters:
rows - Number of rows/columns of the new matrix.

Methods

 o elem
 public int elem(int i,
                 int j)
Get a particular element of the matrix specified by the position given in the parameters of the method.

Parameters:
i - The column number of the element of interest.
j - The row number of the element to be extracted.
Returns:
The integer element at row and column specified by the two parameter.
 o setElem
 public void setElem(int i,
                     int j,
                     int value)
Assign a new value to the entry specified by the parameters.

Parameters:
i - The column number of the element that is being assigned a new value.
j - The row number of the element that is being assigned a new value.
value - The new value of the element.
 o incElem
 public void incElem(int i,
                     int j,
                     int value)
Increment the element specified by the first two parameters by the value specified by the third parameter.

Parameters:
i - The column number of the element to be incremented.
j - The row number of the element to be incremented.
value - The amount of the element incrementation.
 o setDiag
 public void setDiag(int value[])
Set the value for each element on the main diagonal based on the array passed in as the parameter. The length of the array must be at least equal to the longest dimension of the matrix and the matrix must be a square matrix. Otherwise, an exception might be raised during execution.

Parameters:
value - An array of value to be assigned to each of the element on the main diagonal of the matrix.
 o setLT
 public void setLT(int value)
Assign a value to all elements to the left hand side of the main diagonal (exclusive).

Parameters:
value - The value to be assigned to the elements.
 o printMatrix
 public void printMatrix()
Print out the contents of the matrix to the stdout. MAX_VALUE is represented by #. This method is only used during the diagnostic of the class.

 o setHighlight
 public void setHighlight(int j,
                          int k)
Highlight an element of the matrix, colouring it to black.

Parameters:
j - The column of the element to be highlighted.
k - The row of the element to be highlighted.
 o setHighlight2
 public void setHighlight2(int j,
                           int k)
Highlight an element of the matrix, colouring it to gray.

Parameters:
j - The column of the element to be highlighted.
k - The row of the element to be highlighted.
 o restoreHighlight
 public void restoreHighlight(int j,
                              int k)
Restore the element which was highlighted using Color.black.

Parameters:
j - The column of the element to be restored.
k - The row of the element to be restored.
 o restoreHighlight2
 public void restoreHighlight2(int j,
                               int k)
Restore the element which was highlighted using Color.gray.

Parameters:
j - The column of the element to be restored.
k - The row of the element to be restored.
 o restoreAll
 public void restoreAll()
Restore all previously highlighted element of the matrix (black and gray).

 o setTitle
 public void setTitle(String title)
Set a title to the matrix.

Parameters:
title - The new title of the matrix.
 o setRowLabels
 public void setRowLabels(String strs[])
Set a label to each row of the matrix based on the array of String passed in as the parameter.

Parameters:
strs - The array of String which holds the new label for each row of the matrix. The length of the array must be equal to the number of rows of the matrix.
 o setColLabels
 public void setColLabels(String strs[])
Set a label to each column of the matrix based on the array of String passed in as the parameter.

Parameters:
strs - The array of String which holds the new label for each column of the matrix. The length of the array must be equal to the number of columns of the matrix.
 o drawBox
 public void drawBox(Graphics g,
                     int x,
                     int y,
                     String str,
                     Color fg,
                     Color bg,
                     Font font)
This method is used to draw each element of the matrix. It is only called from the draw method of this class.

Parameters:
g - Graphical context.
x - The left most position of the box.
y - The top most position of the box.
str - The text to be displayed in the box.
fg - Foreground color (text color) of the box.
bg - Background color of the box.
font - A fixed font, in particular size 12 plain courier. This font instance is passed in to avoid font initialization every repaint.
 o move
 public void move(int x,
                  int y)
Move the matrix to the position specified with reference to the top left corner.

Parameters:
x - The left most position of the matrix.
y - The top most position of the matrix.
 o getX
 public int getX()
Get the left most position of the matrix.

Returns:
The x-coordinate of the topleft corner of the matrix.
 o getY
 public int getY()
Get the top most position of the matrix.

Returns:
The y-coordinate of the topleft corner of the matrix.
 o setColor
 public void setColor(Color fg,
                      Color bg)
Set the foreground and background color for each element of the matrix. The row and column labels are displayed in the inverse color mode.

Parameters:
fg - The new foreground color.
bg - The new background color.
 o draw
 public void draw(Graphics g)
This method has to be defined to fully implement the DrawingObj interface. It calls the drawMatrix method which draws the matrix based on the position and color previously set.

See Also:
drawMatrix
 o drawMatrix
 public void drawMatrix(Graphics g,
                        int x,
                        int y,
                        Color fg,
                        Color bg)
This method is only called from the draw method which in turn is called from the drawing panel to draw the matrix based on the position and color previously set.

Parameters:
g - graphical context.
x - The left most position of the matrix.
y - The top most position of the matrix.
fg - Foreground (text) color for each element.
bg - Background color for each element.