// Edge for connecting nodes in trees
/** BTree Animation
June.4 Friday 2004
Implemented by Jung-Ho, Yoo & Chang-Hwan, Park
in Seoul, S.Korea
**/
import java.awt.*;
import ciips.animation.*;
import ciips.animation.tree.*;
/** A drawable object connecting two TreeNode
's
**/
public class BTreeEdge extends Drawable {
private TreeNode start, end;
private Color arrow_colour, value_colour;
private Dimension startoffset;
private Dimension endoffset;
/** Create a new edge
* joining start
and end
* @par start - reference to start node
* @par end - reference to end node
* @par startoffset - start offset at parent node
@par endoffset - end offset at child node
**/
public BTreeEdge( TreeNode start, TreeNode end, Dimension startoffset, Dimension endoffset ) {
this.start = start;
this.end = end;
arrow_colour = Color.black;
this.startoffset = startoffset;
this.endoffset = endoffset;
}
/**
Constructor in which offset is set to (0,0)
**/
public BTreeEdge( TreeNode start, TreeNode end ) {
this( start, end, new Dimension(0,0), new Dimension(0,0) );
}
public void setStart( TreeNode s ) { start = s; }
public void setEnd( TreeNode e ) { end = e; }
public TreeNode getStart() { return start; }
public TreeNode getEnd() { return end; }
/** Changes the offset to the arc start and end points ..
used if the node size shrinks or expands, eg because a tree
became larger or the panel changed size
**/
public void setstartOffset( Dimension startoffset ) {
this.startoffset = startoffset;
}
public void setendOffset( Dimension endoffset ) {
this.endoffset = endoffset;
}
public void setColour( Color c ) { arrow_colour = c; }
/** Match an edge
**/
public boolean equals( TreeNode s, TreeNode end ) {
return (start == s) && (this.end == end);
}
/** Draw the edge
*/
public void draw( Graphics g ) {
g.setColor( arrow_colour );
// g.fillPolygon(arrow_x, arrow_y, 3);
g.drawLine( start.getX() + startoffset.width, start.getY() + startoffset.height,
end.getX() + endoffset.width, end.getY() + endoffset.height );
}
public String toString() {
return "BTreeEdge (" + start + "-" + end + ")";
}
}