|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectciips.animation.Drawable
ciips.animation.IntMatrix
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:
It can then be removed from the drawing panel by:
IntMatrix matrix1 = new IntMatrix(4);
drawingPanel.addDrawingObj(matrix1);
matrix1.setColor(....);
matrix1.move(x, y);
....
drawingPanel.removeObj(matrix1);
This class implements a matrix representation with all integer entries.
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 |
public IntMatrix(int rows, int columns)
rows
- The number of rows of the new matrix.columns
- The number of columns of the new matrix.public IntMatrix(int rows)
rows
- Number of rows/columns of the new matrix.Method Detail |
public int elem(int i, int j)
i
- The column number of the element of interest.j
- The row number of the element to be extracted.
public void setElem(int i, int j, int value)
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.public void incElem(int i, int j, int value)
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.public void setDiag(int[] value)
value
- An array of value to be assigned to each of the element
on the main diagonal of the matrix.public void setLT(int value)
value
- The value to be assigned to the elements.public void printMatrix()
public void setHighlight(int j, int k)
j
- The column of the element to be highlighted.k
- The row of the element to be highlighted.public void setHighlight2(int j, int k)
j
- The column of the element to be highlighted.k
- The row of the element to be highlighted.public void restoreHighlight(int j, int k)
j
- The column of the element to be restored.k
- The row of the element to be restored.public void restoreHighlight2(int j, int k)
j
- The column of the element to be restored.k
- The row of the element to be restored.public void restoreAll()
public void setTitle(java.lang.String title)
title
- The new title of the matrix.public void setRowLabels(java.lang.String[] strs)
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.public void setColLabels(java.lang.String[] strs)
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.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)
draw
method of this class.
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.public void setColor(java.awt.Color fg, java.awt.Color bg)
fg
- The new foreground color.bg
- The new background color.public void draw(java.awt.Graphics g)
drawMatrix
method which
draws the matrix based on the position and color previously set.
draw
in interface DrawingObj
draw
in class Drawable
drawMatrix(java.awt.Graphics, int, int, java.awt.Color, java.awt.Color)
public void drawMatrix(java.awt.Graphics g, int x, int y, java.awt.Color fg, java.awt.Color bg)
draw
method which
in turn is called from the drawing panel to draw the matrix based
on the position and color previously set.
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |