objectdraw
Class Line

java.lang.Object
  extended by objectdraw.Drawable
      extended by objectdraw.Line
All Implemented Interfaces:
Serializable, Drawable1DInterface, DrawableInterface
Direct Known Subclasses:
AngLine

public class Line
extends Drawable
implements Drawable1DInterface

Line is an implementation of a drawable line segment object.

Version:
1.1.1 released February 2005
See Also:
Serialized Form

Field Summary
protected  Location end
          The line's second endpoint.
protected  Location start
          The line's first endpoint.
 
Fields inherited from class objectdraw.Drawable
canvasContent, color, shown
 
Constructor Summary
Line(double startx, double starty, double endx, double endy, DrawingCanvas c)
          Creates a new Line object going from (startx,starty) to (endx,endy).
Line(Location start, Location end, DrawingCanvas canvas)
          Creates a new Line object going from start to end.
 
Method Summary
 boolean contains(Location point)
          Determines if a particular position on the DrawingCanvas is contained within the object.
(package private)  void draw(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 object within the canvas in the x and y direction by the amounts specified as parameters.
 void moveTo(double x, double y)
          Moves the object within the canvas to the x and y coordinates provided.
 void setEnd(double x, double y)
          Sets the line's end point.
 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(double x, double y)
          Sets the line's start point.
 void setStart(Location point)
          Sets the line's start point.
 String toString()
          Generates a string representation of the object.
 
Methods inherited from class objectdraw.Drawable
addToCanvas, clearCanvasContent, getCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setCanvasContent, setColor, setStateChanged, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface objectdraw.DrawableInterface
addToCanvas, getCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setColor, show
 

Field Detail

end

protected Location end
The line's second endpoint.


start

protected Location start
The line's first endpoint.

Constructor Detail

Line

public Line(double startx,
            double starty,
            double endx,
            double endy,
            DrawingCanvas c)
Creates a new Line object going from (startx,starty) to (endx,endy).

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.

Line

public Line(Location start,
            Location end,
            DrawingCanvas canvas)
Creates a new Line object going from start to end.

Parameters:
start - the starting point of the line.
end - the destination point of the line.
canvas - the canvas in which the line is created.
Method Detail

contains

public boolean contains(Location point)
Description copied from interface: DrawableInterface
Determines if a particular position on the DrawingCanvas is contained within the object.

Specified by:
contains in interface DrawableInterface
Specified by:
contains in class Drawable
Parameters:
point - the position on the canvas.
Returns:
true if point is contained in the object, false otherwise.

draw

void draw(Graphics g)
Draws the object.

Overrides:
draw in class Drawable
Parameters:
g - the graphics context into which the object is drawn.

getEnd

public Location getEnd()
Description copied from interface: Drawable1DInterface
Gets the line's end point.

Specified by:
getEnd in interface Drawable1DInterface
Returns:
the end point

getStart

public Location getStart()
Description copied from interface: Drawable1DInterface
Gets the line's start point.

Specified by:
getStart in interface Drawable1DInterface
Returns:
the start point

move

public void move(double dx,
                 double dy)
Description copied from interface: DrawableInterface
Moves the object within the canvas in the x and y direction by the amounts specified as parameters.

Specified by:
move in interface DrawableInterface
Specified by:
move in class Drawable
Parameters:
dx - the amount to move in the x-direction.
dy - the amount to move in the y-direction.

moveTo

public void moveTo(double x,
                   double y)
Description copied from interface: DrawableInterface
Moves the object within the canvas to the x and y coordinates provided.

Specified by:
moveTo in interface DrawableInterface
Overrides:
moveTo in class Drawable
Parameters:
x - horizontal coordinate of destination.
y - horizontal coordinate of destination.

setEnd

public void setEnd(double x,
                   double y)
Description copied from interface: Drawable1DInterface
Sets the line's end point.

Specified by:
setEnd in interface Drawable1DInterface
Parameters:
x - x coordinate of new end point
y - y coordinate of new end point

setEnd

public void setEnd(Location point)
Description copied from interface: Drawable1DInterface
Sets the line's end point.

Specified by:
setEnd in interface Drawable1DInterface
Parameters:
point - new endpoint

setEndPoints

public void setEndPoints(double x1,
                         double y1,
                         double x2,
                         double y2)
Description copied from interface: Drawable1DInterface
Sets the line's end points.

Specified by:
setEndPoints in interface Drawable1DInterface
Parameters:
x1 - x coordinate of start
y1 - y coordinate of start
x2 - x coordinate of end
y2 - y coordinate of end

setEndPoints

public void setEndPoints(Location start,
                         Location end)
Description copied from interface: Drawable1DInterface
Sets the line's end points.

Specified by:
setEndPoints in interface Drawable1DInterface
Parameters:
start - first endpoint
end - second endpoint

setStart

public void setStart(double x,
                     double y)
Description copied from interface: Drawable1DInterface
Sets the line's start point.

Specified by:
setStart in interface Drawable1DInterface
Parameters:
x - x coordinate of new start point
y - y coordinate of new start point

setStart

public void setStart(Location point)
Description copied from interface: Drawable1DInterface
Sets the line's start point.

Specified by:
setStart in interface Drawable1DInterface
Parameters:
point - new start point

toString

public String toString()
Generates a string representation of the object.

Overrides:
toString in class Object
Returns:
string representation of the object