objectdraw
Class Line

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

public class Line
extends objectdraw.Drawable
implements Drawable1DInterface

Line is an implementation of a drawable line segment object.

Version:
1.1.2 released July 2006
See Also:
Serialized Form

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
 void addToCanvas(DrawingCanvas c)
          Places an existing object on a specified DrawingCanvas.
 boolean contains(Location point)
          Determines if a particular position on the DrawingCanvas is contained within the object.
 DrawingCanvas getCanvas()
          Determine which (if any) DrawingCanvas this object is positioned on
 java.awt.Color getColor()
          Retrieves the color of the object.
 Location getEnd()
          Gets the line's end point.
 Location getStart()
          Gets the line's start point.
 void hide()
          Temporarily hides an object on a DrawingCanvas from view.
 boolean isHidden()
          Determine whether an object is currently visible on its canvas
 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 moveTo(Location point)
          Moves the object within the canvas to the specified Location
 void removeFromCanvas()
          Permanently removes the object from the canvas it is currently on.
 void sendBackward()
          Sends the object backward.
 void sendForward()
          Sends the object forward.
 void sendToBack()
          Sends the object to the back.
 void sendToFront()
          Sends the object to the front.
 void setColor(java.awt.Color c)
          Sets the color of the object.
 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.
 void show()
          Shows the object if it has been hidden.
 java.lang.String toString()
          Generates a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, 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
 

Constructor Detail

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.

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.
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

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

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

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

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

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

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

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

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

toString

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

Returns:
string representation of the object

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

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

addToCanvas

public void addToCanvas(DrawingCanvas c)
Description copied from interface: DrawableInterface
Places an existing object on a specified DrawingCanvas. This method will fail if the object is already on a canvas. Therefore, to move an object from one canvas to another one must use removeFromCanvas() followed by addToCanvas. This method can also be invoked to place a Drawable object on a DrawingCanvas after the object is loaded from a file or other stream.

Specified by:
addToCanvas in interface DrawableInterface
Parameters:
c - the canvas on which the object should be drawn

removeFromCanvas

public void removeFromCanvas()
Description copied from interface: DrawableInterface
Permanently removes the object from the canvas it is currently on. If you want to just make an object temporarily invisible, use hide() instead.

Specified by:
removeFromCanvas in interface DrawableInterface

getCanvas

public DrawingCanvas getCanvas()
Description copied from interface: DrawableInterface
Determine which (if any) DrawingCanvas this object is positioned on

Specified by:
getCanvas in interface DrawableInterface
Returns:
the DrawingCanvas holding this object or null if it the object is not currently associated with any canvas

hide

public void hide()
Description copied from interface: DrawableInterface
Temporarily hides an object on a DrawingCanvas from view. This method should only be used if the object may later be made visible again using the show() method. If the goal is to remove an object from the display permanently, the removeFromCanvas() method should be used instead.

Specified by:
hide in interface DrawableInterface

show

public void show()
Description copied from interface: DrawableInterface
Shows the object if it has been hidden.

Specified by:
show in interface DrawableInterface

isHidden

public boolean isHidden()
Description copied from interface: DrawableInterface
Determine whether an object is currently visible on its canvas

Specified by:
isHidden in interface DrawableInterface
Returns:
true if the object is currently hidden.

moveTo

public void moveTo(Location point)
Description copied from interface: DrawableInterface
Moves the object within the canvas to the specified Location

Specified by:
moveTo in interface DrawableInterface
Parameters:
point - the destination for moving the object.

setColor

public void setColor(java.awt.Color c)
Description copied from interface: DrawableInterface
Sets the color of the object.

Specified by:
setColor in interface DrawableInterface
Parameters:
c - the color.

getColor

public java.awt.Color getColor()
Description copied from interface: DrawableInterface
Retrieves the color of the object.

Specified by:
getColor in interface DrawableInterface
Returns:
the object's color.

sendForward

public void sendForward()
Description copied from interface: DrawableInterface
Sends the object forward.

Specified by:
sendForward in interface DrawableInterface

sendBackward

public void sendBackward()
Description copied from interface: DrawableInterface
Sends the object backward.

Specified by:
sendBackward in interface DrawableInterface

sendToFront

public void sendToFront()
Description copied from interface: DrawableInterface
Sends the object to the front.

Specified by:
sendToFront in interface DrawableInterface

sendToBack

public void sendToBack()
Description copied from interface: DrawableInterface
Sends the object to the back.

Specified by:
sendToBack in interface DrawableInterface