edu.colorado.cs.ns2.graphics
Class LineDrawable

java.lang.Object
  extended by edu.colorado.cs.ns2.graphics.LineDrawable
All Implemented Interfaces:
Drawable, java.io.Serializable

public class LineDrawable
extends java.lang.Object
implements Drawable, java.io.Serializable

This class represents a Link (a line) as drawn on the screen.

Author:
Kevin Bauer, Pushkar Sambhoos.
See Also:
Serialized Form

Field Summary
private  double c
          The y-intercept of the line.
static int HEIGHT
          The HEIGHT of the line.
private  Link link
          A reference to the NS2 link that the current graphical link represents.
private  double m
          The slope of the line.
private static long serialVersionUID
          Default serial version UID.
static int WIDTH
          The WIDTH of the line.
private  int X1
          The X-coordinate of the first endpoint.
private  int X2
          The X-coordinate of the second endpoint.
private  int Y1
          The Y-coodinate of the first endpoint.
private  int Y2
          The Y-coordinate of the second endpoint.
 
Constructor Summary
LineDrawable(int x1, int y1, int x2, int y2)
          Four-argument constructor: Sets the line's endpoint coordinates.
 
Method Summary
private  void calcLineSlope(int x1, int y1, int x2, int y2)
          Calculates Slope and c to represent equation of line as y = mx + c
 void drawSelf(java.awt.Graphics g, boolean clear)
          Draws a Line with the current co-ordinates.
 Link getLink()
          Get the Link associated with the Line
 java.awt.Point getPoint1()
          Get first endpoint of Line
 java.awt.Point getPoint2()
          Get second endpoint of Line
 void move(int dX, int dY)
          Inherited from interface; not used for this subclass.
 void moveLine(int dX, int dY, int which)
          Change the co-ordinates of the Line
 void setLink(Link link)
          Associate a Link with the Line.
 boolean within(int X, int Y)
          Check to see if (X,Y) corresponds to this Line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Default serial version UID.

See Also:
Constant Field Values

X1

private int X1
The X-coordinate of the first endpoint.


Y1

private int Y1
The Y-coodinate of the first endpoint.


X2

private int X2
The X-coordinate of the second endpoint.


Y2

private int Y2
The Y-coordinate of the second endpoint.


m

private double m
The slope of the line.


c

private double c
The y-intercept of the line.


link

private Link link
A reference to the NS2 link that the current graphical link represents.


HEIGHT

public static final int HEIGHT
The HEIGHT of the line.

See Also:
Constant Field Values

WIDTH

public static final int WIDTH
The WIDTH of the line.

See Also:
Constant Field Values
Constructor Detail

LineDrawable

public LineDrawable(int x1,
                    int y1,
                    int x2,
                    int y2)
Four-argument constructor: Sets the line's endpoint coordinates.

Parameters:
x1 - X-coordinate of the first endpoint.
y1 - Y-coordinate of the first endpoint.
x2 - X-coordinate of the second endpoint.
y2 - Y-coordinate of the second endpoint.
Method Detail

calcLineSlope

private void calcLineSlope(int x1,
                           int y1,
                           int x2,
                           int y2)
Calculates Slope and c to represent equation of line as y = mx + c

Parameters:
x1 - x1
y1 - y1
x2 - x2
y2 - y2

setLink

public void setLink(Link link)
Associate a Link with the Line.

Parameters:
link - - Link

getLink

public Link getLink()
Get the Link associated with the Line

Returns:
Link

drawSelf

public void drawSelf(java.awt.Graphics g,
                     boolean clear)
Draws a Line with the current co-ordinates.

Specified by:
drawSelf in interface Drawable
Parameters:
g - Reference to the Graphics object.
clear - Set it to false to erase the Node.
See Also:
Drawable.drawSelf(java.awt.Graphics, boolean)

move

public void move(int dX,
                 int dY)
Inherited from interface; not used for this subclass.

Specified by:
move in interface Drawable
Parameters:
dX - - change in x co-ordinate.
dY - - change in y co-ordinate.
See Also:
Drawable.move(int, int)

moveLine

public void moveLine(int dX,
                     int dY,
                     int which)
Change the co-ordinates of the Line

Parameters:
dX - change in x position
dY - change in y position
which - select co-ordinate to update (0 or 1)

within

public boolean within(int X,
                      int Y)
Check to see if (X,Y) corresponds to this Line.

Specified by:
within in interface Drawable
Parameters:
X - X-coordinate.
Y - Y-coordinate.
Returns:
True or False
See Also:
Drawable.within(int, int)

getPoint1

public java.awt.Point getPoint1()
Get first endpoint of Line

Returns:
First Point

getPoint2

public java.awt.Point getPoint2()
Get second endpoint of Line

Returns:
Second Point