objectdraw
Class Drawable

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

abstract class Drawable
extends Object
implements Serializable, DrawableInterface

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.

Version:
1.1.1 released February 2005

Field Summary
protected  CanvasManager canvasContent
          The contents of the canvas on which the object is displayed.
protected  Color color
          The object's color.
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)
          Places an existing object on a specified DrawingCanvas.
protected  void clearCanvasContent()
          Set canvasContent to null to indicate object has been removed from its canvas.
abstract  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.
 DrawingCanvas getCanvas()
          Determine which (if any) DrawingCanvas this object is positioned on
 Color getColor()
          Retrieves the color of the object.
 void hide()
          Temporarily hides an object on a DrawingCanvas from view.
 boolean isHidden()
          Determine whether an object is currently visible on its canvas
abstract  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.
(package private)  void setCanvasContent(CanvasManager cc)
          Save a reference to the CanvasManager for the canvas in which this object is currently displayed.
 void setColor(Color c)
          Sets the color of the object.
protected  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

canvasContent

protected transient CanvasManager canvasContent
The contents of the canvas on which the object is displayed. If this field is null, then the object is not displayed on a canvas.


color

protected Color color
The object's color.


shown

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

Constructor Detail

Drawable

public Drawable()
Creates a new Drawable object.

Method Detail

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

clearCanvasContent

protected void clearCanvasContent()
Set canvasContent to null to indicate object has been removed from its canvas. This is really just a step in performing the removeFromCanvas operation. It is placed here in a separate method rather than in removeFromCanvas since it needs to be invoked from the removeFromCanvas method of the CanvasManager to ensure correct synchronization.


contains

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

Parameters:
g - the graphics context into which the object is drawn

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

getColor

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

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

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

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.

move

public abstract 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
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
Parameters:
x - horizontal coordinate of destination.
y - horizontal coordinate of destination.

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.

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

sendBackward

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

Specified by:
sendBackward in interface DrawableInterface

sendForward

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

Specified by:
sendForward in interface DrawableInterface

sendToBack

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

Specified by:
sendToBack in interface DrawableInterface

sendToFront

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

Specified by:
sendToFront in interface DrawableInterface

setCanvasContent

void setCanvasContent(CanvasManager cc)
Save a reference to the CanvasManager for the canvas in which this object is currently displayed. This is really just a step in performing the addToCanvas operation. It is placed here in a separate method rather than in addToCanvas since it needs to be synchronized.

Parameters:
cc - the manager for this object's canvas

setColor

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

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

setStateChanged

protected void setStateChanged()
Sets the state of the object to be changed so that it gets repainted. Normally this will not need to be called by programmers as methods changing the object will automatically call this method.


show

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

Specified by:
show in interface DrawableInterface