objectdraw
Class Line

java.lang.Object
  |
  +--objectdraw.Drawable
        |
        +--objectdraw.Line
All Implemented Interfaces:
DrawableInterface, java.io.Serializable

public class Line
extends Drawable

Line is an implementation of a drawable line segment object.

See Also:
Serialized Form

Field Summary
static double CONTAINMENT_ECCENTRICITY
          Eccentricity of the ellipse surrounding the line, used to test for containment.
protected  Location end
          The line's second endpoint.
protected  Location start
          The line's first endpoint.
 
Fields inherited from class objectdraw.Drawable
canvas, canvasContent, color, DEBUGGING, shown
 
Constructor Summary
Line(double startx, double starty, double endx, double endy, DrawingCanvas c)
          Creates a new Line object.
Line(Location start, Location end, DrawingCanvas c)
          Creates a new Line object.
 
Method Summary
 boolean contains(Location point)
          Determines if the object contains the given point.
 void draw(java.awt.Graphics g)
          Draws the object.
 Location getEnd()
          Gets the line's end point.
 Location getStart()
          Gets the line's start point.
 void move(double dx, double dy)
          Moves the line in the x and y directions the specified amounts.
 void moveTo(double x, double y)
          Moves the line to the specified coordinates.
 void moveTo(Location point)
          Moves the line to the specified Location.
 void setEnd(Location point)
          Sets the line's end point.
 void setEndPoints(double x1, double y1, double x2, double y2)
          Sets the line's end points.
 void setEndPoints(Location start, Location end)
          Sets the line's end points.
 void setStart(Location point)
          Sets the line's start point.
 java.lang.String toString()
          Generates a string representation of the object.
 
Methods inherited from class objectdraw.Drawable
addToCanvas, getColor, hide, isHidden, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setColor, setStateChanged, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTAINMENT_ECCENTRICITY

public static final double CONTAINMENT_ECCENTRICITY
Eccentricity of the ellipse surrounding the line, used to test for containment.

start

protected Location start
The line's first endpoint.

end

protected Location end
The line's second endpoint.
Constructor Detail

Line

public Line(Location start,
            Location end,
            DrawingCanvas c)
Creates a new Line object.
Parameters:
start - the starting point of the line.
end - the destination point of the line.
c - the canvas in which the line is created.

Line

public Line(double startx,
            double starty,
            double endx,
            double endy,
            DrawingCanvas c)
Creates a new Line object.
Parameters:
startx - x-coordinate of the first endpoint
starty - y-coordinate of the second endpoint
endx - x-coordinate of the second endpoint
endy - y-coordinate of the second endpoint
c - the canvas in which the line is created.
Method Detail

draw

public void draw(java.awt.Graphics g)
Draws the object.
Overrides:
draw in class Drawable
Parameters:
g - the graphics context into which the object is drawn.

contains

public boolean contains(Location point)
Determines if the object contains the given point.
Overrides:
contains in class Drawable
Parameters:
point - the point
Returns:
true if point is contained in the object; false otherwise.

getStart

public Location getStart()
Gets the line's start point.
Returns:
the start point

getEnd

public Location getEnd()
Gets the line's end point.
Returns:
the end point

setStart

public void setStart(Location point)
Sets the line's start point.
Parameters:
point - new start point

setEnd

public void setEnd(Location point)
Sets the line's end point.
Parameters:
point - new endpoint

setEndPoints

public void setEndPoints(Location start,
                         Location end)
Sets the line's end points.
Parameters:
start - first endpoint
end - second endpoint

setEndPoints

public void setEndPoints(double x1,
                         double y1,
                         double x2,
                         double y2)
Sets the line's end points.
Parameters:
start - first endpoint
end - second endpoint

toString

public java.lang.String toString()
Generates a string representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
string representation of the object

moveTo

public void moveTo(Location point)
Moves the line to the specified Location.
Overrides:
moveTo in class Drawable
Parameters:
dest - the destination for moving the object.

moveTo

public void moveTo(double x,
                   double y)
Moves the line to the specified coordinates.
Overrides:
moveTo in class Drawable
Parameters:
x - horizontal coordinate of destination.
y - horizontal coordinate of destination.

move

public void move(double dx,
                 double dy)
Moves the line in the x and y directions the specified amounts.
Overrides:
move in class Drawable
Parameters:
dx - the amount to move in the x-direction.
dy - the amount to move in the y-direction.