objectdraw
Class FilledRoundedRect

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

public class FilledRoundedRect
extends objectdraw.ObjectDrawRectangularShape

A FilledRoundedRect is a rectangle with rounded corners, filled in with some color. Like other shapes that implement the Drawable2DInterface, its shape is defined by a top left corner, plus a width and height. You can also control the size of the arcs that form the corners.

Author:
Russell Zahniser (russell@zahniser.net)

Constructor Summary
FilledRoundedRect(double x, double y, double width, double height, double arcWidth, double arcHeight, Color color, DrawingCanvas canvas)
          Construct a rounded rectangle starting at (x, y) at its top left corner, and extending the given width and height from there, filled in with the given color.
FilledRoundedRect(double x, double y, double width, double height, double arcWidth, double arcHeight, DrawingCanvas canvas)
          Construct a rounded rectangle starting at (x, y) at its top left corner, and extending the given width and height from there, filled in with black.
FilledRoundedRect(Location point, double width, double height, double arcWidth, double arcHeight, Color color, DrawingCanvas canvas)
          Construct a rounded rectangle starting at point at its top left corner, and extending the given width and height from there, filled in with the given color.
FilledRoundedRect(Location point, double width, double height, double arcWidth, double arcHeight, DrawingCanvas canvas)
          Construct a rounded rectangle starting at point at its top left corner, and extending the given width and height from there, filled in with black.
FilledRoundedRect(Location corner1, Location corner2, double arcWidth, double arcHeight, Color color, DrawingCanvas canvas)
          Construct a rounded rectangle stretching from corner1 to corner2, filled in with the given color.
FilledRoundedRect(Location corner1, Location corner2, double arcWidth, double arcHeight, DrawingCanvas canvas)
          Construct a rounded rectangle stretching from corner1 to corner2, filled in with black.
 
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.
 int getArcHeight()
          Return the height of the arcs of this rounded rectangle, in int precision.
 int getArcWidth()
          Return the width of the arcs of this rounded rectangle, in int precision.
 DrawingCanvas getCanvas()
          Return the canvas that this object is on.
 Color getColor()
          Return the color of this object
 double getDoubleArcHeight()
          Return the height of the arcs of this rounded rectangle, in double precision.
 double getDoubleArcWidth()
          Return the width of the arcs of this rounded rectangle, in double precision.
 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.
 Location getLocation()
          Get this object's location.
 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 drawwn 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 setArcHeight(double a)
          Set the height of the arcs of this rounded rectangle.
 void setArcWidth(double a)
          Set the width of the arcs of this rounded rectangle.
 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 setSize(double width, double height)
          Set the width and height of this object.
 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

FilledRoundedRect

public FilledRoundedRect(double x,
                         double y,
                         double width,
                         double height,
                         double arcWidth,
                         double arcHeight,
                         Color color,
                         DrawingCanvas canvas)
Construct a rounded rectangle starting at (x, y) at its top left corner, and extending the given width and height from there, filled in with the given color. Its corners will be rounded by arcs that have a total width of arcWidth and a total height of arcHeight. So, the straight parts of the edges have lengths width - arcWidth and height - arcHeight.

Parameters:
x - x coordinate of the top left corner
y - y coordinate of the top left corner
width - width of the oval
height - height of the oval
color - Color to draw the oval in
canvas - DrawingCanvas on which to place the oval

FilledRoundedRect

public FilledRoundedRect(double x,
                         double y,
                         double width,
                         double height,
                         double arcWidth,
                         double arcHeight,
                         DrawingCanvas canvas)
Construct a rounded rectangle starting at (x, y) at its top left corner, and extending the given width and height from there, filled in with black. Its corners will be rounded by arcs that have a total width of arcWidth and a total height of arcHeight. So, the straight parts of the edges have lengths width - arcWidth and height - arcHeight.

Parameters:
x - x coordinate of the top left corner
y - y coordinate of the top left corner
width - width of the oval
height - height of the oval
canvas - DrawingCanvas on which to place the oval

FilledRoundedRect

public FilledRoundedRect(Location point,
                         double width,
                         double height,
                         double arcWidth,
                         double arcHeight,
                         Color color,
                         DrawingCanvas canvas)
Construct a rounded rectangle starting at point at its top left corner, and extending the given width and height from there, filled in with the given color. Its corners will be rounded by arcs that have a total width of arcWidth and a total height of arcHeight. So, the straight parts of the edges have lengths width - arcWidth and height - arcHeight.

Parameters:
point - Location of the top left corner
width - width of the oval
height - height of the oval
color - Color to draw the oval in
canvas - DrawingCanvas on which to place the oval

FilledRoundedRect

public FilledRoundedRect(Location point,
                         double width,
                         double height,
                         double arcWidth,
                         double arcHeight,
                         DrawingCanvas canvas)
Construct a rounded rectangle starting at point at its top left corner, and extending the given width and height from there, filled in with black. Its corners will be rounded by arcs that have a total width of arcWidth and a total height of arcHeight. So, the straight parts of the edges have lengths width - arcWidth and height - arcHeight.

Parameters:
point - Location of the top left corner
width - width of the oval
height - height of the oval
canvas - DrawingCanvas on which to place the oval

FilledRoundedRect

public FilledRoundedRect(Location corner1,
                         Location corner2,
                         double arcWidth,
                         double arcHeight,
                         Color color,
                         DrawingCanvas canvas)
Construct a rounded rectangle stretching from corner1 to corner2, filled in with the given color. Its corners will be rounded by arcs that have a total width of arcWidth and a total height of arcHeight. So, the straight parts of the edges have lengths width - arcWidth and height - arcHeight.

Parameters:
corner1 - Location of one corner
corner2 - Location of the opposite corner
color - Color to draw the oval in
canvas - DrawingCanvas on which to place the oval

FilledRoundedRect

public FilledRoundedRect(Location corner1,
                         Location corner2,
                         double arcWidth,
                         double arcHeight,
                         DrawingCanvas canvas)
Construct a rounded rectangle stretching from corner1 to corner2, filled in with black. Its corners will be rounded by arcs that have a total width of arcWidth and a total height of arcHeight. So, the straight parts of the edges have lengths width - arcWidth and height - arcHeight.

Parameters:
corner1 - Location of one corner
corner2 - Location of the opposite corner
canvas - DrawingCanvas on which to place the oval
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

getArcHeight

public int getArcHeight()
Return the height of the arcs of this rounded rectangle, in int precision. Since each corner is a quarter oval, the height of each corner is actually half this.

Returns:
the arc height of this rounded rectangle, in int precision.

getArcWidth

public int getArcWidth()
Return the width of the arcs of this rounded rectangle, in int precision. Since each corner is a quarter oval, the width of each corner is actually half this.

Returns:
the arc width of this rounded rectangle, in int precision.

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

getDoubleArcHeight

public double getDoubleArcHeight()
Return the height of the arcs of this rounded rectangle, in double precision. Since each corner is a quarter oval, the height of each corner is actually half this.

Returns:
the arc height of this rounded rectangle, in double precision.

getDoubleArcWidth

public double getDoubleArcWidth()
Return the width of the arcs of this rounded rectangle, in double precision. Since each corner is a quarter oval, the width of each corner is actually half this.

Returns:
the arc width of this rounded rectangle, in double precision.

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.

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.

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

setArcHeight

public void setArcHeight(double a)
Set the height of the arcs of this rounded rectangle. Since each corner is a quarter oval, the height of each corner is actually half this.

Parameters:
a - new arc height

setArcWidth

public void setArcWidth(double a)
Set the width of the arcs of this rounded rectangle. Since each corner is a quarter oval, the width of each corner is actually half this.

Parameters:
a - new arc width

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

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

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