com.rolemodelsoft.drawlet.shapes.polygons
Class PolygonShape

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.polygons.PolygonShape

public class PolygonShape
extends FilledShape
implements PolygonFigure

This provides a basic concrete implementation of PolygonFigures that are assumed to be movable and reshapable with observers that want to know when their locations or shapes change. Although this is a concrete class, it is acknowledged that there are probably other implementations (e.g. one that uses Locators) which are more flexible.

See Also:
Serialized Form

Field Summary
protected  java.awt.Polygon polygon
          The underlying, defining polygon.
 
Fields inherited from class com.rolemodelsoft.drawlet.shapes.FilledShape
fillColor, lineColor
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
listeners, locationListeners
 
Fields inherited from interface com.rolemodelsoft.drawlet.Figure
FILL_COLOR_PROPERTY, LINE_COLOR_PROPERTY, LOCATION_PROPERTY, RELATION_PROPERTY, SHAPE_PROPERTY, SIZE_PROPERTY, STRING_PROPERTY, STYLE_PROPERTY, TEXT_COLOR_PROPERTY
 
Constructor Summary
PolygonShape()
          Constructs a new instance of the receiver.
PolygonShape(java.awt.Polygon polygon)
          Constructs and initializes a new instance of the receiver based on a defining polygon.
 
Method Summary
protected  void basicReshape(int x, int y, int width, int height)
          Reshapes the Figure to the specified bounding box.
protected  void basicSetPolygon(java.awt.Polygon polygon)
          Set the Polygon associated with the Figure.
protected  void basicTranslate(int x, int y)
          Moves the Figure in the x and y direction.
 boolean contains(int x, int y)
          Checks whether a specified x,y location is "inside" this Figure, where x and y are defined to be relative to the coordinate system of this figure.
protected  java.awt.Polygon defaultPolygon()
          Answer the default/initial value for polygon
 java.lang.Object duplicateIn(java.util.Hashtable duplicates)
          Duplicates the receiver into a Hashtable.
 java.awt.Rectangle getBounds()
          Returns the current bounds of the receiver.
 Handle[] getHandles()
          Answer the handles associated with the receiver.
 java.awt.Polygon getPolygon()
          Answer a Polygon associated with the receiver.
 boolean intersects(int x1, int y1, int x2, int y2)
          Answers whether the receiver intersects a Rectangular area.
 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.
 void setPolygon(java.awt.Polygon polygon)
          Set the Polygon associated with the figure.
 
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
basicResize, resetBoundsCache, resetSizeCache, reshapedPolygon, reshapedPolygon, setBounds, setSize
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
addPropertyChangeListener, addRelatedLocationListener, basicMove, changedLocation, changedShape, changedSize, contains, contains, deleteLocationListeners, disconnect, duplicate, 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, getSize, getTop, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

polygon

protected java.awt.Polygon polygon
The underlying, defining polygon.
Constructor Detail

PolygonShape

public PolygonShape()
Constructs a new instance of the receiver.

PolygonShape

public PolygonShape(java.awt.Polygon polygon)
Constructs and initializes a new instance of the receiver based on a defining polygon.
Parameters:
polygon - the polygon which defines the basic shape of the receiver.
Method Detail

basicReshape

protected void basicReshape(int x,
                            int y,
                            int width,
                            int height)
Reshapes the Figure to the specified bounding box.
Overrides:
basicReshape in class FilledShape
Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the figure
height - the height of the figure

basicSetPolygon

protected void basicSetPolygon(java.awt.Polygon polygon)
Set the Polygon associated with the Figure.
Parameters:
polygon - the Polygon.

basicTranslate

protected void basicTranslate(int x,
                              int y)
Moves the Figure in the x and y direction.
Overrides:
basicTranslate in class FilledShape
Parameters:
x - amount to move in the x direction
y - amount to move in the y direction

contains

public boolean contains(int x,
                        int y)
Checks whether a specified x,y location is "inside" this Figure, where x and y are defined to be relative to the coordinate system of this figure.
Overrides:
contains in class AbstractFigure
Parameters:
x - the x coordinate
y - the y coordinate

defaultPolygon

protected java.awt.Polygon defaultPolygon()
Answer the default/initial value for polygon

duplicateIn

public java.lang.Object duplicateIn(java.util.Hashtable duplicates)
Duplicates the receiver into a Hashtable.
Overrides:
duplicateIn in class AbstractFigure
Parameters:
duplicates - the Hashtable to place the duplicate in.
Returns:
the duplicate.

getBounds

public java.awt.Rectangle getBounds()
Returns the current bounds of the receiver.
Overrides:
getBounds in class FilledShape
Returns:
a Rectangle representing the current bounds of the receiver.

getHandles

public Handle[] getHandles()
Answer the handles associated with the receiver.
Overrides:
getHandles in class AbstractShape
Returns:
an array of Handles.

getPolygon

public java.awt.Polygon getPolygon()
Answer a Polygon associated with the receiver.
Specified by:
getPolygon in interface PolygonFigure
Returns:
a copy of the Polygon which defines the receiver.

intersects

public boolean intersects(int x1,
                          int y1,
                          int x2,
                          int y2)
Answers whether the receiver intersects a Rectangular area. By default, just check if the bounds intersects. Subclasses may wish to do something more sophisticated.
Parameters:
box - the Rectangular area
Returns:
boolean value of true if the receiver intersects the specified Rectangular area; false otherwise.
See Also:
#bounds

intersects

public boolean intersects(java.awt.Rectangle Box)
Answers whether the receiver intersects a Rectangular area.
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

setPolygon

public void setPolygon(java.awt.Polygon polygon)
Set the Polygon associated with the figure. Let observers know what changed. This is a TemplateMethod with hooks: resetBoundsCache(); basicSetPolygon(); changedShape();
Specified by:
setPolygon in interface PolygonFigure
Parameters:
polygon - the Polygon