objectdraw
Class FramedArc

java.lang.Object
  extended by objectdraw.ObjectDrawObject
      extended by objectdraw.ObjectDrawShape
          extended by objectdraw.ObjectDrawRectangularShape
              extended by objectdraw.FramedArc
All Implemented Interfaces:
objectdraw.Dependent, Drawable2DInterface, DrawableInterface, DrawableStrokeInterface, LocatableInterface, Resizable2DInterface

public class FramedArc
extends objectdraw.ObjectDrawRectangularShape
implements DrawableStrokeInterface

A FramedArc is a curved line that forms some portion of an oval. Like other shapes that implement the Drawable2DInterface, its shape is bounded by a top left corner, plus a width and height; these specify the size of the oval it is cut out of, not the space taken up by the arc itself. In addition, it has an angle in degrees specifying at what angle the arc starts, and another saying how many degrees from there the arc extends.

Author:
Russell Zahniser (russell@zahniser.net)

Field Summary
 
Fields inherited from interface objectdraw.DrawableStrokeInterface
CLICK_SIZE, DEFAULT_STROKE
 
Constructor Summary
FramedArc(double x, double y, double width, double height, double startAngle, double arcAngle, Color color, DrawingCanvas canvas)
          Construct a FramedArc whose bounding rectangle has its top left corner at (x, y) and extends the given width and height from there.
FramedArc(double x, double y, double width, double height, double startAngle, double arcAngle, DrawingCanvas canvas)
          Construct a FramedArc whose bounding rectangle has its top left corner at (x, y) and extends the given width and height from there.
FramedArc(Location point, double width, double height, double startAngle, double arcAngle, Color color, DrawingCanvas canvas)
          Construct a FramedArc whose bounding rectangle has its top left corner at point and extends the given width and height from there.
FramedArc(Location point, double width, double height, double startAngle, double arcAngle, DrawingCanvas canvas)
          Construct a FramedArc whose bounding rectangle has its top left corner at point and extends the given width and height from there.
FramedArc(Location corner1, Location corner2, double startAngle, double arcAngle, Color color, DrawingCanvas canvas)
          Construct a FramedArc whose bounding rectangle stretches between corner1 and corner2.
FramedArc(Location corner1, Location corner2, double startAngle, double arcAngle, DrawingCanvas canvas)
          Construct a FramedArc whose bounding rectangle stretches between corner1 and corner2.
 
Method Summary
 void addToCanvas(DrawingCanvas c)
          Place this object on the specified canvas.
 boolean contains(Location point)
          Return true if the given location is inside this object, false otherwise.
 double getArcAngle()
          Return the angular extent of the arc, in degrees.
 DrawingCanvas getCanvas()
          Return the canvas that this object is on.
 Color getColor()
          Return the color of this object
 double getDoubleHeight()
          Return the height of the rectangle bounding this object, in double precision.
 double getDoubleWidth()
          Return the height of the rectangle bounding this object, in double precision.
 double getDoubleX()
          Get this object's x coordinate, in double precision.
 double getDoubleY()
          Get this object's y coordinate, in double precision.
 int getHeight()
          Return the width of the rectangle bounding this object.
 double getLineWidth()
          Return the width of this object's lines.
 Location getLocation()
          Get this object's location.
 double getStartAngle()
          Get the angle at which the arc starts, in degrees.
 BasicStroke getStroke()
          Return the stroke used for this object's lines.
 int getWidth()
          Return the height of the rectangle bounding this object.
 int getX()
          Get this object's x coordinate.
 int getY()
          Get this object's y coordinate.
 void hide()
          Make this object invisible.
 boolean isHidden()
          Return true if this object has been rendered invisible with a call to its hide() method, false if it is still being drawn.
 void move(double dx, double dy)
          Shift (translate) this object left or right by an amount dx, and up or down by an amount dy.
 void moveTo(double x, double y)
          Move the reference point of this object to the given location.
 void moveTo(Location point)
          Move the reference point of this object to the given location.
 boolean overlaps(Drawable2DInterface other)
          Return true if the rectangle bounding this object overlaps with the rectangle bounding another object; false otherwise.
 void removeFromCanvas()
          Remove this object from its canvas.
 void sendBackward()
          Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it.
 void sendForward()
          Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it.
 void sendToBack()
          Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects.
 void sendToFront()
          Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects.
 void setArcAngle(double a)
          Set the angular length of the arc, in degrees.
 void setColor(Color c)
          Change the color of this object.
 void setHeight(double h)
          Set the height of this object, leaving its top edge in place and stretching the bottom.
 void setLineWidth(double width)
          Set the width of this object's lines
 void setSize(double width, double height)
          Set the width and height of this object.
 void setStartAngle(double a)
          Set the start angle of the arc, in degrees.
 void setStroke(BasicStroke stroke)
          Set the stroke used for this object's lines
 void setWidth(double w)
          Set the width of this object, leaving its left edge in place and stretching the right.
 void show()
          Make an object visible again after it had been hidden.
 String toString()
          Return a string describing how this object might be constructed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FramedArc

public FramedArc(double x,
                 double y,
                 double width,
                 double height,
                 double startAngle,
                 double arcAngle,
                 Color color,
                 DrawingCanvas canvas)
Construct a FramedArc whose bounding rectangle has its top left corner at (x, y) and extends the given width and height from there. The arc will start at startAngle, given in degrees in the usual angle system, so that 0 is east, Math.PI / 2 is north, and so on; it will extend arcAngle degrees from there. The sign of arcAngle determines which way the arc goes from startAngle; a negative sign means that the arc extends clockwise, whereas a positive sign means that it extends counterclockwise.

Parameters:
x - x coordinate of top left corner of bounding rectangle
y - y coordinate of top left corner of bounding rectangle
width - width of bounding rectangle
height - height of bounding rectangle
startAngle - start angle, in degrees
arcAngle - arc angle, in degrees
color - Color of the arc
canvas - DrawingCanvas on which to place the arc

FramedArc

public FramedArc(double x,
                 double y,
                 double width,
                 double height,
                 double startAngle,
                 double arcAngle,
                 DrawingCanvas canvas)
Construct a FramedArc whose bounding rectangle has its top left corner at (x, y) and extends the given width and height from there. The arc will start at startAngle, given in degrees in the usual angle system, so that 0 is east, Math.PI / 2 is north, and so on; it will extend arcAngle degrees from there. The sign of arcAngle determines which way the arc goes from startAngle; a negative sign means that the arc extends clockwise, whereas a positive sign means that it extends counterclockwise.

Parameters:
x - x coordinate of top left corner of bounding rectangle
y - y coordinate of top left corner of bounding rectangle
width - width of bounding rectangle
height - height of bounding rectangle
startAngle - start angle, in degrees
arcAngle - arc angle, in degrees
canvas - DrawingCanvas on which to place the arc

FramedArc

public FramedArc(Location point,
                 double width,
                 double height,
                 double startAngle,
                 double arcAngle,
                 Color color,
                 DrawingCanvas canvas)
Construct a FramedArc whose bounding rectangle has its top left corner at point and extends the given width and height from there. The arc will start at startAngle, given in degrees in the usual angle system, so that 0 is east, Math.PI / 2 is north, and so on; it will extend arcAngle degrees from there. The sign of arcAngle determines which way the arc goes from startAngle; a negative sign means that the arc extends clockwise, whereas a positive sign means that it extends counterclockwise.

Parameters:
point - Location of the top left corner of the bounding rectangle
width - width of bounding rectangle
height - height of bounding rectangle
startAngle - start angle, in degrees
arcAngle - arc angle, in degrees
color - Color of the arc
canvas - DrawingCanvas on which to place the arc

FramedArc

public FramedArc(Location point,
                 double width,
                 double height,
                 double startAngle,
                 double arcAngle,
                 DrawingCanvas canvas)
Construct a FramedArc whose bounding rectangle has its top left corner at point and extends the given width and height from there. The arc will start at startAngle, given in degrees in the usual angle system, so that 0 is east, Math.PI / 2 is north, and so on; it will extend arcAngle degrees from there. The sign of arcAngle determines which way the arc goes from startAngle; a negative sign means that the arc extends clockwise, whereas a positive sign means that it extends counterclockwise.

Parameters:
point - Location of the top left corner of the bounding rectangle
width - width of bounding rectangle
height - height of bounding rectangle
startAngle - start angle, in degrees
arcAngle - arc angle, in degrees
canvas - DrawingCanvas on which to place the arc

FramedArc

public FramedArc(Location corner1,
                 Location corner2,
                 double startAngle,
                 double arcAngle,
                 Color color,
                 DrawingCanvas canvas)
Construct a FramedArc whose bounding rectangle stretches between corner1 and corner2. The arc will start at startAngle, given in degrees in the usual angle system, so that 0 is east, Math.PI / 2 is north, and so on; it will extend arcAngle degrees from there. The sign of arcAngle determines which way the arc goes from startAngle; a negative sign means that the arc extends clockwise, whereas a positive sign means that it extends counterclockwise.

Parameters:
corner1 - Location of one corner of the bounding rectangle
corner2 - Location of the opposite corner of the bounding rectangle
startAngle - start angle, in degrees
arcAngle - arc angle, in degrees
color - Color of the arc
canvas - DrawingCanvas on which to place the arc

FramedArc

public FramedArc(Location corner1,
                 Location corner2,
                 double startAngle,
                 double arcAngle,
                 DrawingCanvas canvas)
Construct a FramedArc whose bounding rectangle stretches between corner1 and corner2. The arc will start at startAngle, given in degrees in the usual angle system, so that 0 is east, Math.PI / 2 is north, and so on; it will extend arcAngle degrees from there. The sign of arcAngle determines which way the arc goes from startAngle; a negative sign means that the arc extends clockwise, whereas a positive sign means that it extends counterclockwise.

Parameters:
corner1 - Location of one corner of the bounding rectangle
corner2 - Location of the opposite corner of the bounding rectangle
startAngle - start angle, in degrees
arcAngle - arc angle, in degrees
canvas - DrawingCanvas on which to place the arc
Method Detail

addToCanvas

public void addToCanvas(DrawingCanvas c)
Place this object on the specified canvas. The object will be removed from its current canvas, if it is on a canvas that is not the one it is being moved to. The object will be at the front of the canvas, as if it had just been drawn. If the given canvas is null the object is simply removed from its current canvas.

Specified by:
addToCanvas in interface DrawableInterface
Overrides:
addToCanvas in class objectdraw.ObjectDrawShape
Parameters:
c - DrawingCanvas to place this object on

contains

public boolean contains(Location point)
Return true if the given location is inside this object, false otherwise. Because Lines and FramedArcs have no "inside", a point is considered to be contained in one of them as long as it is within a few pixels of the line.

Specified by:
contains in interface DrawableInterface
Overrides:
contains in class objectdraw.ObjectDrawRectangularShape
Parameters:
point - Location to test
Returns:
whether the given location is inside this shape

getArcAngle

public double getArcAngle()
Return the angular extent of the arc, in degrees. A negative angle means that the arc goes clockwise from the start angle; a positive angle means that it extends counterclockwise. The end angle is always at (startAngle + arcAngle).

Returns:
the arc angle

getCanvas

public DrawingCanvas getCanvas()
Return the canvas that this object is on. If it has been removed from its canvas, this method will return null.

Specified by:
getCanvas in interface DrawableInterface
Overrides:
getCanvas in class objectdraw.ObjectDrawShape
Returns:
the DrawingCanvas that this object is on.

getColor

public Color getColor()
Return the color of this object

Specified by:
getColor in interface DrawableInterface
Overrides:
getColor in class objectdraw.ObjectDrawShape
Returns:
the Color of this object

getDoubleHeight

public double getDoubleHeight()
Return the height of the rectangle bounding this object, in double precision.

Specified by:
getDoubleHeight in interface Drawable2DInterface
Overrides:
getDoubleHeight in class objectdraw.ObjectDrawRectangularShape
Returns:
the height of the rectangle bounding this object, in double precision.

getDoubleWidth

public double getDoubleWidth()
Return the height of the rectangle bounding this object, in double precision.

Specified by:
getDoubleWidth in interface Drawable2DInterface
Overrides:
getDoubleWidth in class objectdraw.ObjectDrawRectangularShape
Returns:
the height of the rectangle bounding this object, in double precision.

getDoubleX

public double getDoubleX()
Get this object's x coordinate, in double precision.

Specified by:
getDoubleX in interface LocatableInterface
Overrides:
getDoubleX in class objectdraw.ObjectDrawRectangularShape
Returns:
this object's x coordinate, in double precision

getDoubleY

public double getDoubleY()
Get this object's y coordinate, in double precision.

Specified by:
getDoubleY in interface LocatableInterface
Overrides:
getDoubleY in class objectdraw.ObjectDrawRectangularShape
Returns:
this object's y coordinate, in double precision

getHeight

public int getHeight()
Return the width of the rectangle bounding this object.

Specified by:
getHeight in interface Drawable2DInterface
Overrides:
getHeight in class objectdraw.ObjectDrawRectangularShape
Returns:
the width of the rectangle bounding this object.

getLineWidth

public double getLineWidth()
Return the width of this object's lines.

Specified by:
getLineWidth in interface DrawableStrokeInterface
Returns:
the width of this object's lines

getLocation

public Location getLocation()
Get this object's location. Translating this Location object will have the same effect as moving the object. So, the following two lines of code are equivalent:

object.move(10, 20);
object.getLocation().translate(10, 20);


If you want to create a Location offset by some amount from the Location of this object, without actually moving this object, use the offset() method in Location, which creates a new Location.

Specified by:
getLocation in interface LocatableInterface
Overrides:
getLocation in class objectdraw.ObjectDrawRectangularShape
Returns:
the Location of this object.

getStartAngle

public double getStartAngle()
Get the angle at which the arc starts, in degrees. Angles are positioned starting at 0 at the x axis and going counterclockwise from there, as is customary in math.

Returns:
the start angle

getStroke

public BasicStroke getStroke()
Return the stroke used for this object's lines.

Specified by:
getStroke in interface DrawableStrokeInterface
Returns:
the stroke used for this object's lines

getWidth

public int getWidth()
Return the height of the rectangle bounding this object.

Specified by:
getWidth in interface Drawable2DInterface
Overrides:
getWidth in class objectdraw.ObjectDrawRectangularShape
Returns:
the height of the rectangle bounding this object.

getX

public int getX()
Get this object's x coordinate.

Specified by:
getX in interface LocatableInterface
Overrides:
getX in class objectdraw.ObjectDrawRectangularShape
Returns:
this object's x coordinate

getY

public int getY()
Get this object's y coordinate.

Specified by:
getY in interface LocatableInterface
Overrides:
getY in class objectdraw.ObjectDrawRectangularShape
Returns:
this object's y coordinate

hide

public void hide()
Make this object invisible. It stays in position on its canvas; it is simply not drawn. This method has no effect if the object was already hidden.

Specified by:
hide in interface DrawableInterface
Overrides:
hide in class objectdraw.ObjectDrawShape

isHidden

public boolean isHidden()
Return true if this object has been rendered invisible with a call to its hide() method, false if it is still being drawn.

Specified by:
isHidden in interface DrawableInterface
Overrides:
isHidden in class objectdraw.ObjectDrawShape
Returns:
whether this object is hidden

move

public void move(double dx,
                 double dy)
Shift (translate) this object left or right by an amount dx, and up or down by an amount dy. A negative dx indicates a shift to the left; a negative dy indicates a shift up

Specified by:
move in interface DrawableInterface
Overrides:
move in class objectdraw.ObjectDrawShape
Parameters:
dx - amount of x translation
dy - amount of y translation

moveTo

public void moveTo(double x,
                   double y)
Move the reference point of this object to the given location. For a Drawable2D object, the reference point is the top left corner; for a line, it is the start point.

Specified by:
moveTo in interface DrawableInterface
Overrides:
moveTo in class objectdraw.ObjectDrawShape
Parameters:
x - x coordinate to move to
y - y coordinate to move to

moveTo

public void moveTo(Location point)
Move the reference point of this object to the given location. For a Drawable2D object, the reference point is the top left corner; for a line, it is the start point.

Specified by:
moveTo in interface DrawableInterface
Overrides:
moveTo in class objectdraw.ObjectDrawShape
Parameters:
point - Location to move to

overlaps

public boolean overlaps(Drawable2DInterface other)
Return true if the rectangle bounding this object overlaps with the rectangle bounding another object; false otherwise.

Specified by:
overlaps in interface Drawable2DInterface
Overrides:
overlaps in class objectdraw.ObjectDrawRectangularShape
Parameters:
other - another two dimensional object to check for overlapping with
Returns:
whether the bounding rectangles of the two objects overlap

removeFromCanvas

public void removeFromCanvas()
Remove this object from its canvas.

Specified by:
removeFromCanvas in interface DrawableInterface
Overrides:
removeFromCanvas in class objectdraw.ObjectDrawShape

sendBackward

public void sendBackward()
Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it.

Specified by:
sendBackward in interface DrawableInterface
Overrides:
sendBackward in class objectdraw.ObjectDrawShape

sendForward

public void sendForward()
Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it.

Specified by:
sendForward in interface DrawableInterface
Overrides:
sendForward in class objectdraw.ObjectDrawShape

sendToBack

public void sendToBack()
Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects.

Specified by:
sendToBack in interface DrawableInterface
Overrides:
sendToBack in class objectdraw.ObjectDrawShape

sendToFront

public void sendToFront()
Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects.

Specified by:
sendToFront in interface DrawableInterface
Overrides:
sendToFront in class objectdraw.ObjectDrawShape

setArcAngle

public void setArcAngle(double a)
Set the angular length of the arc, in degrees. A negative angle will cause the arc to extend clockwise from the start angle; a positive angle will make it extend counterclockwise.

Parameters:
a - new arc angle

setColor

public void setColor(Color c)
Change the color of this object.

Specified by:
setColor in interface DrawableInterface
Overrides:
setColor in class objectdraw.ObjectDrawShape
Parameters:
c - new Color for this object

setHeight

public void setHeight(double h)
Set the height of this object, leaving its top edge in place and stretching the bottom.

Specified by:
setHeight in interface Resizable2DInterface
Overrides:
setHeight in class objectdraw.ObjectDrawRectangularShape
Parameters:
h - new height

setLineWidth

public void setLineWidth(double width)
Set the width of this object's lines

Specified by:
setLineWidth in interface DrawableStrokeInterface
Parameters:
width - the new width of this object's lines

setSize

public void setSize(double width,
                    double height)
Set the width and height of this object. Its upper left corner will stay fixed in place, and the opposite corner will move to make it the new size.

Specified by:
setSize in interface Resizable2DInterface
Overrides:
setSize in class objectdraw.ObjectDrawRectangularShape
Parameters:
width - new width
height - new height

setStartAngle

public void setStartAngle(double a)
Set the start angle of the arc, in degrees. Angles are positioned starting at 0 at the x axis and going counterclockwise from there, as is customary in math.

Parameters:
a - new start angle

setStroke

public void setStroke(BasicStroke stroke)
Set the stroke used for this object's lines

Specified by:
setStroke in interface DrawableStrokeInterface
Parameters:
stroke - the new stroke for this object's lines

setWidth

public void setWidth(double w)
Set the width of this object, leaving its left edge in place and stretching the right.

Specified by:
setWidth in interface Resizable2DInterface
Overrides:
setWidth in class objectdraw.ObjectDrawRectangularShape
Parameters:
w - new width

show

public void show()
Make an object visible again after it had been hidden. This method has no effect if the object was already visible.

Specified by:
show in interface DrawableInterface
Overrides:
show in class objectdraw.ObjectDrawShape

toString

public String toString()
Return a string describing how this object might be constructed.

Overrides:
toString in class objectdraw.ObjectDrawObject