org.tigris.gef.presentation
Class FigPoly

java.lang.Object
  extended by org.tigris.gef.presentation.Fig
      extended by org.tigris.gef.presentation.FigPoly
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, PopupGenerator
Direct Known Subclasses:
FigInk, FigSpline

public class FigPoly
extends Fig

Primitive Fig to paint Polygons on a LayerDiagram. FigPolys contain a set of points that define the polygon, a boolean to determine if the polygon should be constrained to rectilinear (strict horizontal and vertical) segments, and a number of handles that cannot be moved by user dragging. A FigPoly is not closed unless the last point equals the first point. Thus, FigPolys can be used to represent polylines such as FigEdgeRectilinear.

See Also:
FigEdgeRectiline, Serialized Form

Field Summary
protected  int _fixedHandles
          The number of handles at each end of the polygon that cannot be dragged by the user.
 boolean _isComplete
          Flag to indicate when the polygon is completed
protected  boolean _isSelfLoop
          Flag to indicate when the polygon is used as a self-loop for a node
protected  int _npoints
          The total number of points.
protected  boolean _rectilinear
          Flag to control how the polygon is drawn
protected  int[] _xpoints
          The array of x coordinates.
protected  int[] _ypoints
          The array of y coordinates.
protected static double FUDGEFACTOR
          The radian angle at which a point can be deleted.
 
Fields inherited from class org.tigris.gef.presentation.Fig
_allowsSaving, _context, _dashes, _dashPeriod, _dashStyle, _filled, _h, _w, _x, _y, an, annotationOwner, annotationStatus, BORDER, MIN_SIZE
 
Constructor Summary
FigPoly()
          Construct a new FigPoly.
FigPoly(java.awt.Color lineColor)
          Construct a new FigPoly w/ the given line color.
FigPoly(java.awt.Color lineColor, java.awt.Color fillColor)
          Construct a new FigPoly w/ the given line color and fill color.
FigPoly(int x, int y)
          Construct a new FigPoly w/ the given point.
 
Method Summary
 void addPoint(int x, int y)
          Add a point to this polygon.
 void addPoint(java.awt.Point p)
          Add a point to this polygon.
protected  void appendTwoPoints()
          Add two points at the end of the polygon.
 void calcBounds()
          Update the bounding box.
protected  boolean canMoveVertex(int i, boolean ov)
          Reply true if the point at the given index can be moved.
 void cleanUp()
           
 java.lang.Object clone()
           
 boolean contains(int x, int y)
          Reply true iff the given point is inside this FigPoly.
protected  int countCornersContained(int x, int y, int w, int h)
          Return the number of corners of the given rectangle that are contained within this polygon.
protected  void drawDashedPerimeter(java.awt.Graphics g)
          A faster implementation of drawDashedPerimeter for polygons.
protected  int findHandle(int x, int y)
          Reply the index of the vertex that the given mouse point is near.
 java.awt.Point getClosestPoint(java.awt.Point anotherPt)
          Returns the point that other connected Figs should attach to.
 java.awt.Point getFirstPoint()
          USED BY PGML.tee
 int getFixedHandles()
          Reply the number of fixed handles.
 java.util.List getGravityPoints()
           
 java.awt.Point getLastPoint()
           
 int getNumPoints()
          Return the number of points in this polygon
 int getPerimeterLength()
          Returns the length of the perimeter of the polygon, which is the sum of all the lengths of its segments.
 java.awt.Point getPoint(int i)
          Find the required line break and return it's corordinates as a Point.
 java.awt.Point[] getPoints()
          USED BY PGML.tee
 java.util.List getPointsList()
          USED BY PGML.tee
 java.awt.Polygon getPolygon()
          Get the current vector of points as a java.awt.Polygon.
 boolean getRectilinear()
          Return true if the polygon should be constrained to rectilinear segments.
 int[] getXs()
          Returns the array of X coordinates of points
 int[] getYs()
          Returns the array of Y coordinates of points
protected  void growIfNeeded()
          Increase the memory used to store polygon points, if needed.
 boolean hit(java.awt.Rectangle rect)
          Tests, if the given rectangle hits this polygon.
 void insertPoint(int i, int x, int y)
          Inserts a point at index i.
 boolean intersectsPerimeter(java.awt.Rectangle rect)
          Tests, if the given rectangle intersects with the perimeter of this polygon.
 boolean isPerimeterClosed()
          Tests, if the perimeter of the polygon is closed, i.e.
 boolean isReshapable()
          Returns true if this Fig can be reshaped by the user.
 boolean isResizable()
          FigPolys are resizeable and reshapable, but not rotatable (yet).
 boolean isRotatable()
          Returns true if this Fig can be rotated by the user.
 boolean isSelfLoop()
           
 void moveVertex(Handle h, int x, int y, boolean ov)
          Move the point indicated by the given Handle object to the given location.
 boolean OK()
          Class invarient to make sure this object is in a valid state.
 void paint(java.awt.Graphics g)
          Paint the FigPoly on the given Graphics
protected  void prependTwoPoints()
          Add two points to the front of the list of points.
 void removePoint(int i)
          Removes the point at index i.
 void setBounds(int x, int y, int w, int h)
          Sets the FigPoly's bounding box to the given coordinates.
 void setEndPoints(java.awt.Point start, java.awt.Point end)
          Set the end points of this polygon, regardless of the number of fixed handles.
 void setFixedHandles(int n)
          Set the number of points near each end of the polygon that cannot be dragged by the user.
 void setPoints(Handle h, int mX, int mY)
          When the user drags the handles, move individual points
 void setPolygon(java.awt.Polygon p)
          Set the current vector of points.
 void setRectilinear(boolean r)
          Set the rectilinear flag.
 void setSelfLoop(boolean self)
           
 void stuffPointAlongPerimeter(int dist, java.awt.Point res)
          Returns a point along the perimeter at distance dist from the start of the polygon.
 void translate(int dx, int dy)
          Change the position of the object from were it is to were it is plus dx or dy.
 
Methods inherited from class org.tigris.gef.presentation.Fig
addAnnotation, addPropertyChangeListener, align, center, classNameAndBounds, connectionPoint, contains, contains, createDrag, damage, deleteFromModel, drawDashedLine, endTrans, firePropChange, firePropChange, firePropChange, getAnnotationOwner, getAnnotationStrategy, getBounds, getBounds, getContext, getDashed, getDashed01, getDashedString, getEnclosedFigs, getEnclosingFig, getFillColor, getFilled, getFilled01, getGroup, getHalfHeight, getHalfWidth, getHandleBox, getHeight, getId, getLayer, getLineColor, getLineWidth, getLocation, getLocked, getMinimumSize, getOwner, getPopUpActions, getPreferredSize, getPrivateData, getResource, getSingle, getSize, getTipString, getTrapRect, getUseTrapRect, getVisState, getWidth, getX, getY, hasFillColor, hasLineColor, initAnnotations, intersects, isAnnotation, isCopyable, isCutable, isLowerRightResizable, isMovable, isSelected, isVisible, makeSelection, pointAlongPerimeter, postLoad, postSave, preSave, print, propertyChange, redraw, removeAnnotation, removeAnnotation, removeFromDiagram, removePropertyChangeListener, reorder, routingRect, savingAllowed, setAnnotationOwner, setAnnotationStatus, setAnnotationStrategy, setBounds, setCenter, setContext, setDashed, setDashedString, setEnclosingFig, setFillColor, setFilled, setGroup, setHandleBox, setHeight, setLayer, setLineColor, setLineWidth, setLocation, setLocation, setLocked, setMovable, setNumPoints, setOwner, setPoint, setPoint, setPoint, setPoint, setPoints, setPrivateData, setResizable, setResource, setSavingAllowed, setSingle, setSize, setSize, setVisible, setVisState, setWidth, setX, setXs, setY, setYs, stuffBounds, translateAnnotations, unsetAnnotationOwner, updateAnnotationPositions, updateVisState, within
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FUDGEFACTOR

protected static final double FUDGEFACTOR
The radian angle at which a point can be deleted.

See Also:
Constant Field Values

_npoints

protected int _npoints
The total number of points.


_xpoints

protected int[] _xpoints
The array of x coordinates.


_ypoints

protected int[] _ypoints
The array of y coordinates.


_rectilinear

protected boolean _rectilinear
Flag to control how the polygon is drawn


_isComplete

public boolean _isComplete
Flag to indicate when the polygon is completed


_isSelfLoop

protected boolean _isSelfLoop
Flag to indicate when the polygon is used as a self-loop for a node


_fixedHandles

protected int _fixedHandles
The number of handles at each end of the polygon that cannot be dragged by the user. -1 indicates that any point can be dragged. 0 indicates that the endpoints cannot be dragged. 1 would indicate that the first 2 points and the last 2 points cannot be dragged.

Constructor Detail

FigPoly

public FigPoly(java.awt.Color lineColor)
Construct a new FigPoly w/ the given line color.


FigPoly

public FigPoly(java.awt.Color lineColor,
               java.awt.Color fillColor)
Construct a new FigPoly w/ the given line color and fill color.


FigPoly

public FigPoly()
Construct a new FigPoly.


FigPoly

public FigPoly(int x,
               int y)
Construct a new FigPoly w/ the given point.

Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class Fig

OK

public boolean OK()
Class invarient to make sure this object is in a valid state. Useful for debugging.

Overrides:
OK in class Fig

getPolygon

public java.awt.Polygon getPolygon()
Get the current vector of points as a java.awt.Polygon.


setPolygon

public void setPolygon(java.awt.Polygon p)
Set the current vector of points.


setSelfLoop

public void setSelfLoop(boolean self)

getNumPoints

public int getNumPoints()
Return the number of points in this polygon

Overrides:
getNumPoints in class Fig

getRectilinear

public boolean getRectilinear()
Return true if the polygon should be constrained to rectilinear segments.


setRectilinear

public void setRectilinear(boolean r)
Set the rectilinear flag. Setting this flag to true will not change the current shape of the polygon, instead future dragging by the user will move near-by points to be rectilinear.


getFixedHandles

public int getFixedHandles()
Reply the number of fixed handles. 0 indicates that the end points of the polygon cannot be dragged by the user.


setFixedHandles

public void setFixedHandles(int n)
Set the number of points near each end of the polygon that cannot be dragged by the user.


isSelfLoop

public boolean isSelfLoop()

setEndPoints

public void setEndPoints(java.awt.Point start,
                         java.awt.Point end)
Set the end points of this polygon, regardless of the number of fixed handles. This is used when nodes move.


translate

public void translate(int dx,
                      int dy)
Change the position of the object from were it is to were it is plus dx or dy. Often called when an object is dragged. This could be very useful if local-coordinate systems are used because deltas need less transforming... maybe. Fires PropertyChange with "bounds".

Overrides:
translate in class Fig

addPoint

public void addPoint(int x,
                     int y)
Add a point to this polygon. Fires PropertyChange with "bounds".

Overrides:
addPoint in class Fig

addPoint

public final void addPoint(java.awt.Point p)
Add a point to this polygon.


canMoveVertex

protected boolean canMoveVertex(int i,
                                boolean ov)
Reply true if the point at the given index can be moved. The index must be valid, and the number of fixed handles must not * include this index, unless ov is true to override the fixed * handles.


moveVertex

public void moveVertex(Handle h,
                       int x,
                       int y,
                       boolean ov)
Move the point indicated by the given Handle object to the given location. Fixed handles cannot be moved, unless ov is set to true to override the fixed handle constaint. Fires PropertyChange with "bounds".


prependTwoPoints

protected void prependTwoPoints()
Add two points to the front of the list of points. Needed to introduce new handles at the front of the polygon when the user drags a point just after a fixed handle.


appendTwoPoints

protected void appendTwoPoints()
Add two points at the end of the polygon. Needed if the user drags a point just before a fixed handle.


removePoint

public void removePoint(int i)
Removes the point at index i. Needs-More-Work: this can mess up rectilinear polygons so that they have one non-rectilinear segment. Fires PropertyChange with "bounds".

Overrides:
removePoint in class Fig

insertPoint

public void insertPoint(int i,
                        int x,
                        int y)
Inserts a point at index i. Needs-More-Work: this can mess up rectilinear polygons so that they have one non-rectilinear segment. Fires PropertyChange with "bounds".

Overrides:
insertPoint in class Fig

growIfNeeded

protected void growIfNeeded()
Increase the memory used to store polygon points, if needed.


getPoint

public java.awt.Point getPoint(int i)
Find the required line break and return it's corordinates as a Point. This results in a new object instantiation on every call, if multiple calls are required consider getXs() and getYs() for performance.

Overrides:
getPoint in class Fig
Parameters:
i - the position of the point to return
Returns:
the point at position i

getPointsList

public java.util.List getPointsList()
USED BY PGML.tee


getPoints

public java.awt.Point[] getPoints()
USED BY PGML.tee

Overrides:
getPoints in class Fig

getFirstPoint

public java.awt.Point getFirstPoint()
USED BY PGML.tee

Overrides:
getFirstPoint in class Fig

getLastPoint

public java.awt.Point getLastPoint()
Overrides:
getLastPoint in class Fig

setPoints

public void setPoints(Handle h,
                      int mX,
                      int mY)
When the user drags the handles, move individual points


cleanUp

public void cleanUp()
Overrides:
cleanUp in class Fig

getClosestPoint

public java.awt.Point getClosestPoint(java.awt.Point anotherPt)
Returns the point that other connected Figs should attach to. By default, returns the point closest to anotherPt.

Overrides:
getClosestPoint in class Fig

getGravityPoints

public java.util.List getGravityPoints()
Overrides:
getGravityPoints in class Fig

paint

public void paint(java.awt.Graphics g)
Paint the FigPoly on the given Graphics

Overrides:
paint in class Fig

drawDashedPerimeter

protected void drawDashedPerimeter(java.awt.Graphics g)
A faster implementation of drawDashedPerimeter for polygons.

Overrides:
drawDashedPerimeter in class Fig

findHandle

protected int findHandle(int x,
                         int y)
Reply the index of the vertex that the given mouse point is near.


contains

public boolean contains(int x,
                        int y)
Reply true iff the given point is inside this FigPoly.

Overrides:
contains in class Fig
See Also:
FigCircle, FigEdge

getXs

public int[] getXs()
Returns the array of X coordinates of points

Overrides:
getXs in class Fig

getYs

public int[] getYs()
Returns the array of Y coordinates of points

Overrides:
getYs in class Fig

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Sets the FigPoly's bounding box to the given coordinates. Scales all points into the new bounding box. Fires PropertyChange with "bounds".

Overrides:
setBounds in class Fig

getPerimeterLength

public int getPerimeterLength()
Returns the length of the perimeter of the polygon, which is the sum of all the lengths of its segments.

Overrides:
getPerimeterLength in class Fig

stuffPointAlongPerimeter

public void stuffPointAlongPerimeter(int dist,
                                     java.awt.Point res)
Returns a point along the perimeter at distance dist from the start of the polygon.

Overrides:
stuffPointAlongPerimeter in class Fig

isResizable

public boolean isResizable()
FigPolys are resizeable and reshapable, but not rotatable (yet).

Overrides:
isResizable in class Fig
Returns:
true if this Fig can be resized by the user.

isReshapable

public boolean isReshapable()
Description copied from class: Fig
Returns true if this Fig can be reshaped by the user.

Overrides:
isReshapable in class Fig

isRotatable

public boolean isRotatable()
Description copied from class: Fig
Returns true if this Fig can be rotated by the user.

Overrides:
isRotatable in class Fig

isPerimeterClosed

public boolean isPerimeterClosed()
Tests, if the perimeter of the polygon is closed, i.e. if the last point of the polygon is equal to the first point.

Returns:
True, if the perimeter is closed, otherwise false.

countCornersContained

protected int countCornersContained(int x,
                                    int y,
                                    int w,
                                    int h)
Return the number of corners of the given rectangle that are contained within this polygon.

Overrides:
countCornersContained in class Fig
See Also:
Fig.hit(java.awt.Rectangle)

hit

public boolean hit(java.awt.Rectangle rect)
Tests, if the given rectangle hits this polygon.

Overrides:
hit in class Fig
Parameters:
rect - The rectangle to be tested.
Returns:
True, if the rectangle hit this polygon, otherwise false.

intersectsPerimeter

public boolean intersectsPerimeter(java.awt.Rectangle rect)
Tests, if the given rectangle intersects with the perimeter of this polygon.

Overrides:
intersectsPerimeter in class Fig
Parameters:
rect - The rectangle to be tested.
Returns:
True, if the rectangle intersects the perimeter, otherwise false.

calcBounds

public void calcBounds()
Update the bounding box.

Overrides:
calcBounds in class Fig
See Also:
FigText.calcBounds()