// Edge for connecting nodes in trees
package ciips.animation.tree;
import java.awt.*;
import ciips.animation.*;
/** A drawable object connecting two TreeNode
's
**/
public class TreeEdge extends Drawable {
private TreeNode start, end;
private Color arrow_colour, value_colour;
private Dimension offset;
/** Create a new edge
* joining start
and end
* @par start - reference to start node
* @par end - reference to end node
* @par offset - offset from node reference point to
centre - used to determine start and end
points of arcs
**/
public TreeEdge( TreeNode start, TreeNode end, Dimension offset ) {
this.start = start;
this.end = end;
arrow_colour = Color.black;
this.offset = offset;
}
/**
Constructor in which offset is set to (0,0)
**/
public TreeEdge( TreeNode start, TreeNode end ) {
this( start, end, 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 setOffset( Dimension offset ) {
this.offset = offset;
}
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() + offset.width, start.getY() + offset.height,
end.getX() + offset.width, end.getY() + offset.width );
}
public String toString() {
return "TreeEdge (" + start + "-" + end + ")";
}
}