com.rolemodelsoft.drawlet.shapes.rectangles
Class RoundedRectangleShape

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractPaintable
        |
        +--com.rolemodelsoft.drawlet.basics.AbstractFigure
              |
              +--com.rolemodelsoft.drawlet.shapes.AbstractShape
                    |
                    +--com.rolemodelsoft.drawlet.shapes.FilledShape
                          |
                          +--com.rolemodelsoft.drawlet.shapes.AbstractRectangleShape
                                |
                                +--com.rolemodelsoft.drawlet.shapes.rectangles.RoundedRectangleShape

public class RoundedRectangleShape
extends AbstractRectangleShape

This provides an implementation of a RectangleShape whose corners are rounded. NOTE: intersection algorithms are currently incomplete and only determine if the Rectangular bounds intersect.

See Also:
Serialized Form

Field Summary
protected  int arcHeight
          The height of the corner arc.
protected  int arcWidth
          The width of the corner arc.
 
Fields inherited from class com.rolemodelsoft.drawlet.shapes.AbstractRectangleShape
height, width, x, y
 
Fields inherited from class com.rolemodelsoft.drawlet.shapes.FilledShape
fillColor, lineColor
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
listeners, locationListeners
 
Constructor Summary
RoundedRectangleShape()
          Constructs a new, default instance of the receiver.
RoundedRectangleShape(int x, int y, int width, int height)
          Constructs a new instance of the receiver initialized with the given values for x, y, width and height.
RoundedRectangleShape(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Constructs a new instance of the receiver initialized with the given values for x, y, width, height, arcWidth, and arcHeight.
RoundedRectangleShape(java.awt.Rectangle rectangle)
          Constructs a new instance of the receiver initialized with the given Rectangle.
RoundedRectangleShape(java.awt.Rectangle rectangle, int arcWidth, int arcHeight)
          Constructs a new instance of the receiver initialized with the given Rectangle, arcWidth, and arcHeight.
 
Method Summary
 boolean contains(int x, int y)
          Checks whether a specified x,y location is "inside" this Figure.
 boolean contains(java.awt.Rectangle box)
          Checks whether a specified Rectangle is "inside" this Figure, where the Rectangle and this Figure are in the same coordinate system In addition to checking topLeft and bottomRight, check topRight and bottomLeft.
protected  boolean cornerExcludes(java.awt.Rectangle corner, int centerX, int centerY, int x, int y)
          Checks whether a specified x,y location is "inside" the specified corner but outside the arc in that corner.
protected  int defaultArcHeight()
          Answer the default/initial value for arc height.
protected  int defaultArcWidth()
          Answer the default/initial value for arc width.
 boolean intersects(java.awt.Rectangle box)
          Answers whether the receiver intersects a Rectangular area.
 void paintFilled(java.awt.Graphics g)
          Paint the shape, filling all contained area.
 void paintStrokes(java.awt.Graphics g)
          Paint the outline of the shape.
 
Methods inherited from class com.rolemodelsoft.drawlet.shapes.AbstractRectangleShape
basicMove, basicReshape, basicResize, basicTranslate, changedShape, defaultHeight, defaultWidth, defaultX, defaultY, getBounds, getSize
 
Methods inherited from class com.rolemodelsoft.drawlet.shapes.FilledShape
defaultFillColor, defaultLineColor, getFillColor, getLineColor, getStyle, isOpaque, isStroked, paint, setFillColor, setLineColor, setStyle
 
Methods inherited from class com.rolemodelsoft.drawlet.shapes.AbstractShape
getHandles, resetBoundsCache, resetSizeCache, reshapedPolygon, reshapedPolygon, setBounds, setSize
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
addPropertyChangeListener, addRelatedLocationListener, changedLocation, changedSize, contains, deleteLocationListeners, disconnect, duplicate, duplicateIn, editTool, estimatedDuplicateSize, figureFromLocator, fireLocationChange, firePropertyChange, firePropertyChange, fireRelationChange, fireShapeChange, fireSizeChange, getLocation, getLocator, intersects, isObsolete, isWithin, isWithin, locatorAt, move, move, postDuplicate, relatedLocationListeners, removePropertyChangeListener, removeRelatedLocationListener, requestConnection, resetLocationCache, setSize, translate
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractPaintable
getBottom, getHeight, getLeft, getRight, getTop, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

arcWidth

protected int arcWidth
The width of the corner arc.

arcHeight

protected int arcHeight
The height of the corner arc.
Constructor Detail

RoundedRectangleShape

public RoundedRectangleShape()
Constructs a new, default instance of the receiver.

RoundedRectangleShape

public RoundedRectangleShape(int x,
                             int y,
                             int width,
                             int height)
Constructs a new instance of the receiver initialized with the given values for x, y, width and height.
Parameters:
x - an integer representing the x coordinate.
y - an integer representing the y coordinate.
width - an integer representing the width.
height - an integer representing the height.

RoundedRectangleShape

public RoundedRectangleShape(int x,
                             int y,
                             int width,
                             int height,
                             int arcWidth,
                             int arcHeight)
Constructs a new instance of the receiver initialized with the given values for x, y, width, height, arcWidth, and arcHeight.
Parameters:
x - an integer representing the x coordinate.
y - an integer representing the y coordinate.
width - an integer representing the width.
height - an integer representing the height.
arcWidth - an integer representing the width of the corners.
arcHeight - an integer representing the height of the corners.

RoundedRectangleShape

public RoundedRectangleShape(java.awt.Rectangle rectangle)
Constructs a new instance of the receiver initialized with the given Rectangle.
Parameters:
rectangle - a Rectangle representing the bounding box.

RoundedRectangleShape

public RoundedRectangleShape(java.awt.Rectangle rectangle,
                             int arcWidth,
                             int arcHeight)
Constructs a new instance of the receiver initialized with the given Rectangle, arcWidth, and arcHeight.
Parameters:
rectangle - a Rectangle representing the bounding box.
arcWidth - an integer representing the width of the corners.
arcHeight - an integer representing the height of the corners.
Method Detail

contains

public boolean contains(int x,
                        int y)
Checks whether a specified x,y location is "inside" this Figure. x and y are defined to be relative to the coordinate system of this figure. This is not guaranteed to be 100% accurate around the edges due to rounding errors, but shouldn't be off by more than a single pixel.
Overrides:
contains in class AbstractFigure
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
boolean value of true if the specified x,y location is "inside" this Figure; false otherwise.
See Also:
AbstractFigure.isWithin(com.rolemodelsoft.drawlet.Figure)

contains

public boolean contains(java.awt.Rectangle box)
Checks whether a specified Rectangle is "inside" this Figure, where the Rectangle and this Figure are in the same coordinate system In addition to checking topLeft and bottomRight, check topRight and bottomLeft. If all four corners are inside, everything is inside.
Overrides:
contains in class AbstractFigure
Parameters:
box - the rectangle to test for inclusion
Returns:
boolean value of true if the specified Rectangle is "inside" this Figure; false otherwise.

cornerExcludes

protected boolean cornerExcludes(java.awt.Rectangle corner,
                                 int centerX,
                                 int centerY,
                                 int x,
                                 int y)
Checks whether a specified x,y location is "inside" the specified corner but outside the arc in that corner. x and y are defined to be relative to the coordinate system of this figure.
Parameters:
corner - the corner in which the rounded edge we are interested in appears.
centerX - the x coordinate of the center of the arc
centerY - the y coordinate of the center of the arc
x - the x coordinate of the location we are examining
y - the y coordinate of the location we are examining
Returns:
boolean value of true if the specified x,y location is "inside" the corner but outside the arc; false otherwise.

defaultArcHeight

protected int defaultArcHeight()
Answer the default/initial value for arc height.
Returns:
an integer representing the default/initial value for arc height.

defaultArcWidth

protected int defaultArcWidth()
Answer the default/initial value for arc width.
Returns:
an integer representing the default/initial value for arc width.

intersects

public boolean intersects(java.awt.Rectangle box)
Answers whether the receiver intersects a Rectangular area. By default, just check if the bounds intersects. Subclasses may wish to do something more sophisticated.
Overrides:
intersects in class AbstractFigure
Parameters:
box - the Rectangular area
Returns:
boolean value of true if the receiver intersects the specified Rectangular area; false otherwise.
See Also:
#bounds

paintFilled

public void paintFilled(java.awt.Graphics g)
Paint the shape, filling all contained area.
Overrides:
paintFilled in class FilledShape
Parameters:
g - the specified Graphics window.

paintStrokes

public void paintStrokes(java.awt.Graphics g)
Paint the outline of the shape.
Overrides:
paintStrokes in class FilledShape
Parameters:
g - the specified Graphics window.