ciips.animation
Class IntMatrix

java.lang.Object
  extended byciips.animation.Drawable
      extended byciips.animation.IntMatrix
All Implemented Interfaces:
DrawingObj

public class IntMatrix
extends Drawable

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, DrawingPanel.addDrawingObj(ciips.animation.DrawingObj), DrawingPanel.removeObj(ciips.animation.DrawingObj)

Field Summary
 
Fields inherited from class ciips.animation.Drawable
colour, DEFAULT_START, grey, label, x, y
 
Constructor Summary
IntMatrix(int rows)
          Construct a square matrix with number of rows = number of columns as specified by the single parameter of the constructor.
IntMatrix(int rows, int columns)
          Construct a matrix with the number of rows and columns specified by the parameters of the constructor.
 
Method Summary
 void draw(java.awt.Graphics g)
          This method has to be defined to fully implement the DrawingObj interface.
 void drawBox(java.awt.Graphics g, int x, int y, java.lang.String str, java.awt.Color fg, java.awt.Color bg, java.awt.Font font)
          This method is used to draw each element of the matrix.
 void drawMatrix(java.awt.Graphics g, int x, int y, java.awt.Color fg, java.awt.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.
 int elem(int i, int j)
          Get a particular element of the matrix specified by the position given in the parameters of the method.
 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.
 void printMatrix()
          Print out the contents of the matrix to the stdout.
 void restoreAll()
          Restore all previously highlighted element of the matrix (black and gray).
 void restoreHighlight(int j, int k)
          Restore the element which was highlighted using Color.black.
 void restoreHighlight2(int j, int k)
          Restore the element which was highlighted using Color.gray.
 void setColLabels(java.lang.String[] strs)
          Set a label to each column of the matrix based on the array of String passed in as the parameter.
 void setColor(java.awt.Color fg, java.awt.Color bg)
          Set the foreground and background color for each element of the matrix.
 void setDiag(int[] value)
          Set the value for each element on the main diagonal based on the array passed in as the parameter.
 void setElem(int i, int j, int value)
          Assign a new value to the entry specified by the parameters.
 void setHighlight(int j, int k)
          Highlight an element of the matrix, colouring it to black.
 void setHighlight2(int j, int k)
          Highlight an element of the matrix, colouring it to gray.
 void setLT(int value)
          Assign a value to all elements to the left hand side of the main diagonal (exclusive).
 void setRowLabels(java.lang.String[] strs)
          Set a label to each row of the matrix based on the array of String passed in as the parameter.
 void setTitle(java.lang.String title)
          Set a title to the matrix.
 
Methods inherited from class ciips.animation.Drawable
getCurrentColour, getX, getY, move, setGrey, setHighlight, setText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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.

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

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.

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.

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.

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.

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.

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.


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.

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.

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.

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.

restoreAll

public void restoreAll()
Restore all previously highlighted element of the matrix (black and gray).


setTitle

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

Parameters:
title - The new title of the matrix.

setRowLabels

public void setRowLabels(java.lang.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.

setColLabels

public void setColLabels(java.lang.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.

drawBox

public void drawBox(java.awt.Graphics g,
                    int x,
                    int y,
                    java.lang.String str,
                    java.awt.Color fg,
                    java.awt.Color bg,
                    java.awt.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.

setColor

public void setColor(java.awt.Color fg,
                     java.awt.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.

draw

public void draw(java.awt.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.

Specified by:
draw in interface DrawingObj
Specified by:
draw in class Drawable
See Also:
drawMatrix(java.awt.Graphics, int, int, java.awt.Color, java.awt.Color)

drawMatrix

public void drawMatrix(java.awt.Graphics g,
                       int x,
                       int y,
                       java.awt.Color fg,
                       java.awt.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.