objectdraw
Class Drawable

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

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

Drawable is a general base class for objects being placed on a DrawingCanvas. Basic functionality includes the ability to show, hide, set the color of, and move Drawables.

See Also:
Serialized Form

Field Summary
protected  DrawingCanvas canvas
          The canvas in which the object exists.
protected  CanvasManager canvasContent
          The contents of the canvas on which the object exists.
protected  java.awt.Color color
          The object's color.
protected static boolean DEBUGGING
           
protected  boolean shown
          Whether the object is currently visible on its canvas
 
Constructor Summary
Drawable()
          Creates a new Drawable object.
 
Method Summary
 void addToCanvas(DrawingCanvas c)
          Sets the drawing canvas for the object.
abstract  boolean contains(Location point)
          Determines if the object contains the given point.
 void draw(java.awt.Graphics g)
          Draws the object.
 java.awt.Color getColor()
          Retrieves the color of the object.
 void hide()
          Hides the object.
 boolean isHidden()
          returns True if the object is currently hidden.
abstract  void move(double dx, double dy)
          Moves the object within the canvas by the amount specified in the x and y direction.
 void moveTo(double x, double y)
          Moves the object within the canvas to the specified coordinates
abstract  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 setStateChanged()
          Sets the state of the object to be changed so that it gets repainted.
 void show()
          Shows the object if it has been hidden.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected transient DrawingCanvas canvas
The canvas in which the object exists.

canvasContent

protected transient CanvasManager canvasContent
The contents of the canvas on which the object exists.

color

protected java.awt.Color color
The object's color.

shown

protected boolean shown
Whether the object is currently visible on its canvas

DEBUGGING

protected static final boolean DEBUGGING
Constructor Detail

Drawable

public Drawable()
Creates a new Drawable object.
Parameters:
c - the canvas in which the object will be created
Method Detail

addToCanvas

public void addToCanvas(DrawingCanvas c)
Sets the drawing canvas for the object. This should be called when a Drawable object is loaded from a file or other stream since the DrawingCanvas is not serialized. This does nothing if the object is already on a canvas.
Specified by:
addToCanvas in interface DrawableInterface
Parameters:
c - the canvas on which the object will be drawn

removeFromCanvas

public void removeFromCanvas()
Permanently removes the object from the canvas it is currently on. If you want to just make an object temporarily invisible, call hide instead.
Specified by:
removeFromCanvas in interface DrawableInterface
Parameters:
c - the canvas on which the object will be drawn

setStateChanged

public void setStateChanged()
Sets the state of the object to be changed so that it gets repainted.

draw

public void draw(java.awt.Graphics g)
Draws the object.
Specified by:
draw in interface DrawableInterface
Parameters:
g - the graphics context into which the object is drawn

hide

public void hide()
Hides the object.
Specified by:
hide in interface DrawableInterface

show

public void show()
Shows the object if it has been hidden.
Specified by:
show in interface DrawableInterface

isHidden

public boolean isHidden()
returns True if the object is currently hidden.
Specified by:
isHidden in interface DrawableInterface
Following copied from interface: objectdraw.DrawableInterface
Returns:
True if the object is currently hidden.

moveTo

public abstract void moveTo(Location point)
Moves the object within the canvas to the specified Location
Specified by:
moveTo in interface DrawableInterface
Parameters:
point - the coordinates of the upper left corner of the object's new bounding box

moveTo

public void moveTo(double x,
                   double y)
Moves the object within the canvas to the specified coordinates
Specified by:
moveTo in interface DrawableInterface
Parameters:
x - the x-coordinate of the upper left corner of the object's bounding box
y - the y-coordinate of the upper left corner of the object's bounding box

move

public abstract void move(double dx,
                          double dy)
Moves the object within the canvas by the amount specified in the x and y direction.
Specified by:
move in interface DrawableInterface
Parameters:
dx - the amount to move in the x-direction
dy - the amount to move in the y-direction

contains

public abstract boolean contains(Location point)
Determines if the object contains the given point.
Specified by:
contains in interface DrawableInterface
Parameters:
point - the point
Returns:
true if point is contained in the object; false otherwise.

setColor

public void setColor(java.awt.Color c)
Sets the color of the object.
Specified by:
setColor in interface DrawableInterface
Parameters:
c - the color

getColor

public java.awt.Color getColor()
Retrieves the color of the object.
Specified by:
getColor in interface DrawableInterface
Returns:
the color

sendForward

public void sendForward()
Sends the object forward.
Specified by:
sendForward in interface DrawableInterface

sendBackward

public void sendBackward()
Sends the object backward.
Specified by:
sendBackward in interface DrawableInterface

sendToFront

public void sendToFront()
Sends the object to the front.
Specified by:
sendToFront in interface DrawableInterface

sendToBack

public void sendToBack()
Sends the object to the back.
Specified by:
sendToBack in interface DrawableInterface