* drawingPanel.addDrawingObj(new Legend(x, y));
*
* @see ComBox
* @see IntMatrix
*/
public class Legend extends Drawable {
private int padd = 10;
private Font font = new Font("Helvetica", Font.BOLD, 18);
private Font font2 = new Font("Helvetica", Font.BOLD, 14);
private Font smallfont = new Font("Helvetica", Font.PLAIN, 12);
private Dimension pref_size;
/**
* Construct a legend object on the same drawing panel with the topleft
* corner specified by the parameters.
* @param x Left most position of the legend object.
* @param y Right most position of the legend object.
*/
public Legend(int x, int y, Dimension d ) {
this.x = x;
this.y = y;
this.pref_size = d;
}
/**
* This method draws the details of the legend object on the appropriate
* graphical context, normally the drawing panel.
* This method has to be modified for various application.
*/
public void draw(Graphics g) {
int dx, dy, pos_x, fontSize;
dx = 10;
dy = pref_size.height / 12 ;
pos_x = 30;
fontSize = 15;
// Draw the Frame and the title for the panel
g.setColor(Color.gray);
g.setFont(font);
g.drawString("LEGEND", x + 4*dx+1, y + dy+1);
g.setColor(Color.red);
g.drawString("LEGEND", x + 4*dx, y + dy);
g.setColor(Color.black);
g.drawRect(x , y, pref_size.width - padd, pref_size.height - padd );
g.drawLine(x, y + 2*dy, x + pref_size.width - padd, y + 2*dy);
// Draw the information on Active Node
g.setColor(Color.black);
g.fillRect(x + dx, y + 3*dy - fontSize, 10, 10);
g.drawRect(x + dx, y + 3*dy - fontSize, 10, 10);
g.setFont(font2);
g.setColor(Color.black);
g.drawString("Active Node", x + pos_x, y + 3*dy);
g.setFont(smallfont);
g.drawString(" Node with a value ", x + pos_x, (y + 3*dy + fontSize) );
g.drawString(" ( Leaf node )", x + pos_x, (y + 3*dy + 2*fontSize));
//Draw the information on Inactive node
g.setColor(Color.white);
g.fillRect(x + dx, y + 5*dy - fontSize, 10, 10);
g.setColor(Color.black);
g.drawRect(x + dx, y + 5*dy - fontSize, 10, 10);
g.setFont(font2);
g.setColor(Color.black);
g.drawString("Inactive Node", x + pos_x, y + 5*dy);
g.setFont(smallfont);
g.drawString(" Node with null value ", x + pos_x, (y + 5*dy + fontSize));
g.drawString(" (intermediate node) ", x + pos_x, (y + 5*dy + 2*fontSize));
// Draw the information on Highlighted node
g.setColor(Color.yellow);
g.fillRect(x+dx, y+ 7*dy - fontSize, 10, 10);
g.setColor(Color.black);
g.drawRect(x+dx, y+ 7*dy - fontSize, 10, 10);
g.setFont(font2);
g.setColor(Color.black);
g.drawString("Current Node", x + pos_x, y + 7*dy);
g.setFont(smallfont);
g.drawString("The position of current Node", x + pos_x, (y + 7*dy + fontSize));
// Draw the end-of-word symbol
g.setFont(font2);
g.setColor(Color.black);
g.drawString("@", x + dx, y + 9*dy);
g.drawString("End-of-String Symbol", x + pos_x, y + 9*dy);
g.setFont(smallfont);
g.drawString(" A symbol that marks", x + pos_x, (y + 9*dy + fontSize));
g.drawString(" the end of a String", x + pos_x, (y + 9*dy + 2*fontSize));
}
}