CH.ifa.draw.contrib
Class PolygonFigure

java.lang.Object
  extended by CH.ifa.draw.standard.AbstractFigure
      extended by CH.ifa.draw.figures.AttributeFigure
          extended by CH.ifa.draw.contrib.PolygonFigure
All Implemented Interfaces:
Figure, Storable, java.io.Serializable, java.lang.Cloneable

public class PolygonFigure
extends AttributeFigure

A scalable, rotatable polygon with an arbitrary number of points

See Also:
Serialized Form

Field Summary
protected  java.awt.Polygon fPoly
           
 
Fields inherited from interface CH.ifa.draw.framework.Figure
POPUP_MENU
 
Constructor Summary
PolygonFigure()
           
PolygonFigure(int x, int y)
           
PolygonFigure(java.awt.Polygon p)
           
 
Method Summary
 void addPoint(int x, int y)
          Adds a node to the list of points.
 void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
          Sets the display box of a figure.
 void basicMoveBy(int dx, int dy)
          Moves the figure.
static java.awt.Rectangle bounds(java.awt.Polygon p)
          replacement for builtin Polygon.getBounds that doesn't always update?
 java.awt.Point center()
          Gets the center of a figure.
static java.awt.Point center(java.awt.Polygon p)
           
 java.awt.Point chop(java.awt.Point p)
           
static java.awt.Point chop(java.awt.Polygon poly, java.awt.Point p)
           
 Connector connectorAt(int x, int y)
          Returns the Figures connector for the specified location.
 boolean containsPoint(int x, int y)
          Checks if a point is inside the figure.
 java.awt.Rectangle displayBox()
          Gets the display box of a figure.
static double distanceFromLine(int xa, int ya, int xb, int yb, int xc, int yc)
          compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point
 void drawBackground(java.awt.Graphics g)
          Draws the background of the figure.
 void drawFrame(java.awt.Graphics g)
          Draws the frame of the figure.
 int findSegment(int x, int y)
          Gets the segment that is hit by the given point.
 java.awt.Polygon getPolygon()
          return a copy of the raw polygon
 java.util.Vector handles()
          Returns the handles of a Figure that can be used to manipulate some of its attributes.
 void insertPointAt(java.awt.Point p, int i)
          Insert a node at the given point.
 boolean isEmpty()
          Checks if the figure is empty.
static Locator locator(int pointIndex)
          Creates a locator for the point with the given index.
 java.awt.Point outermostPoint()
          Return the point on the polygon that is furthest from the center
 java.awt.Point pointAt(int i)
           
 int pointCount()
           
 java.util.Enumeration points()
           
 void read(StorableInput dr)
          Reads the Figure from a StorableInput.
 void removePointAt(int i)
           
 void scaleRotate(java.awt.Point anchor, java.awt.Polygon originalPolygon, java.awt.Point p)
          Scale and rotate relative to anchor
 void setPointAt(java.awt.Point p, int i)
          Changes the position of a node.
 void smoothPoints()
          Remove points that are nearly colinear with others
 int splitSegment(int x, int y)
          Splits the segment at the given point if a segment was hit.
 void write(StorableOutput dw)
          Stores the Figure to a StorableOutput.
 
Methods inherited from class CH.ifa.draw.figures.AttributeFigure
draw, getAttribute, getDefaultAttribute, getFillColor, getFrameColor, setAttribute
 
Methods inherited from class CH.ifa.draw.standard.AbstractFigure
addFigureChangeListener, addToContainer, canConnect, changed, clone, connectedTextLocator, connectionInsets, connectorVisibility, decompose, displayBox, displayBox, figures, findFigureInside, includes, invalidate, listener, moveBy, release, removeFigureChangeListener, removeFromContainer, size, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fPoly

protected java.awt.Polygon fPoly
Constructor Detail

PolygonFigure

public PolygonFigure()

PolygonFigure

public PolygonFigure(int x,
                     int y)

PolygonFigure

public PolygonFigure(java.awt.Polygon p)
Method Detail

displayBox

public java.awt.Rectangle displayBox()
Description copied from class: AbstractFigure
Gets the display box of a figure.

Specified by:
displayBox in interface Figure
Specified by:
displayBox in class AbstractFigure
See Also:
Figure.basicDisplayBox(java.awt.Point, java.awt.Point)

isEmpty

public boolean isEmpty()
Description copied from class: AbstractFigure
Checks if the figure is empty. The default implementation returns true if the width or height of its display box is < 3

Specified by:
isEmpty in interface Figure
Overrides:
isEmpty in class AbstractFigure
See Also:
Figure.isEmpty()

handles

public java.util.Vector handles()
Description copied from class: AbstractFigure
Returns the handles of a Figure that can be used to manipulate some of its attributes.

Specified by:
handles in interface Figure
Specified by:
handles in class AbstractFigure
Returns:
a Vector of handles
See Also:
Handle

basicDisplayBox

public void basicDisplayBox(java.awt.Point origin,
                            java.awt.Point corner)
Description copied from class: AbstractFigure
Sets the display box of a figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicDisplayBox in interface Figure
Specified by:
basicDisplayBox in class AbstractFigure
Parameters:
origin - the new origin
corner - the new corner
See Also:
AbstractFigure.displayBox(java.awt.Point, java.awt.Point)

getPolygon

public java.awt.Polygon getPolygon()
return a copy of the raw polygon


center

public java.awt.Point center()
Description copied from class: AbstractFigure
Gets the center of a figure. A convenice method that is rarely overridden.

Specified by:
center in interface Figure
Overrides:
center in class AbstractFigure

points

public java.util.Enumeration points()

pointCount

public int pointCount()

basicMoveBy

public void basicMoveBy(int dx,
                        int dy)
Description copied from class: AbstractFigure
Moves the figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicMoveBy in class AbstractFigure
See Also:
AbstractFigure.moveBy(int, int)

drawBackground

public void drawBackground(java.awt.Graphics g)
Description copied from class: AttributeFigure
Draws the background of the figure.

Overrides:
drawBackground in class AttributeFigure
See Also:
AttributeFigure.draw(java.awt.Graphics)

drawFrame

public void drawFrame(java.awt.Graphics g)
Description copied from class: AttributeFigure
Draws the frame of the figure.

Overrides:
drawFrame in class AttributeFigure
See Also:
AttributeFigure.draw(java.awt.Graphics)

containsPoint

public boolean containsPoint(int x,
                             int y)
Description copied from class: AbstractFigure
Checks if a point is inside the figure.

Specified by:
containsPoint in interface Figure
Overrides:
containsPoint in class AbstractFigure

connectorAt

public Connector connectorAt(int x,
                             int y)
Description copied from class: AbstractFigure
Returns the Figures connector for the specified location. By default a ChopBoxConnector is returned.

Specified by:
connectorAt in interface Figure
Overrides:
connectorAt in class AbstractFigure
See Also:
ChopBoxConnector

addPoint

public void addPoint(int x,
                     int y)
Adds a node to the list of points.


setPointAt

public void setPointAt(java.awt.Point p,
                       int i)
Changes the position of a node.


insertPointAt

public void insertPointAt(java.awt.Point p,
                          int i)
Insert a node at the given point.


removePointAt

public void removePointAt(int i)

scaleRotate

public void scaleRotate(java.awt.Point anchor,
                        java.awt.Polygon originalPolygon,
                        java.awt.Point p)
Scale and rotate relative to anchor


smoothPoints

public void smoothPoints()
Remove points that are nearly colinear with others


splitSegment

public int splitSegment(int x,
                        int y)
Splits the segment at the given point if a segment was hit.

Returns:
the index of the segment or -1 if no segment was hit.

pointAt

public java.awt.Point pointAt(int i)

outermostPoint

public java.awt.Point outermostPoint()
Return the point on the polygon that is furthest from the center


findSegment

public int findSegment(int x,
                       int y)
Gets the segment that is hit by the given point.

Returns:
the index of the segment or -1 if no segment was hit.

chop

public java.awt.Point chop(java.awt.Point p)

write

public void write(StorableOutput dw)
Description copied from class: AttributeFigure
Stores the Figure to a StorableOutput.

Specified by:
write in interface Storable
Overrides:
write in class AttributeFigure

read

public void read(StorableInput dr)
          throws java.io.IOException
Description copied from class: AttributeFigure
Reads the Figure from a StorableInput.

Specified by:
read in interface Storable
Overrides:
read in class AttributeFigure
Throws:
java.io.IOException

locator

public static Locator locator(int pointIndex)
Creates a locator for the point with the given index.


distanceFromLine

public static double distanceFromLine(int xa,
                                      int ya,
                                      int xb,
                                      int yb,
                                      int xc,
                                      int yc)
compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point


bounds

public static java.awt.Rectangle bounds(java.awt.Polygon p)
replacement for builtin Polygon.getBounds that doesn't always update?


center

public static java.awt.Point center(java.awt.Polygon p)

chop

public static java.awt.Point chop(java.awt.Polygon poly,
                                  java.awt.Point p)