uci.gef
Class FigPoly

java.lang.Object
  |
  +--uci.gef.Fig
        |
        +--uci.gef.FigPoly
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:
ActionRemoveVertex, ActionInsertVertex, FigEdgeRectilinear, 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 uci.gef.Fig
_dashes, _fillColor, _filled, _group, _h, _layer, _lineColor, _lineWidth, _locked, _w, _x, _y, BORDER, DASH_ARRAYS, DASHED_CHOICES, MIN_SIZE
 
Constructor Summary
FigPoly()
          Construct a new FigPoly.
FigPoly(Color lineColor)
          Construct a new FigPoly w/ the given line color.
FigPoly(Color lineColor, 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(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()
           
 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 conatined within this polygon.
protected  void drawDashedPerimeter(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.
 Point getClosestPoint(Point anotherPt)
          Returns the point that other connected Figs should attach to.
 Point getFirstPoint()
           
 int getFixedHandles()
          Reply the number of fixed handles.
 Vector getGravityPoints()
           
 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.
 Point getPoints(int i)
          return the point at index i.
 Vector getPointsVector()
           
 Vector getPointsVectorNotFirst()
           
 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(Rectangle r)
           
 void insertPoint(int i, int x, int y)
          Inserts a point at index i.
 boolean isReshapable()
           
 boolean isResizable()
          FigPolys are resizeable and reshapable, but not rotatable (yet).
 boolean isRotatable()
           
 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(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(Point start, 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(Polygon p)
          Set the current vector of points.
 void setRectilinear(boolean r)
          Set the rectilinear flag.
 void stuffPointAlongPerimeter(int dist, 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 uci.gef.Fig
addPropertyChangeListener, align, center, classNameAndBounds, connectionPoint, contains, contains, createDrag, damage, delete, dispose, drawDashedLine, endTrans, firePropChange, firePropChange, firePropChange, getBounds, getDashed, getDashed01, getDashedString, getEnclosedFigs, getEnclosingFig, getFillColor, getFilled, getFilled01, getGroup, getHalfHeight, getHalfWidth, getHeight, getId, getLayer, getLineColor, getLineWidth, getLocation, getLocked, getMinimumSize, getOwner, getPoints, getPopUpActions, getPreferedSize, getSize, getTipString, getTrapRect, getUseTrapRect, getWidth, getX, getY, intersects, isLowerRightResizable, isMovable, makeSelection, pointAlongPerimeter, postLoad, postSave, preSave, print, propertyChange, removePropertyChangeListener, reorder, routingRect, setBounds, setDashed, setDashedString, setEnclosingFig, setFillColor, setFilled, setGroup, setHeight, setLayer, setLineColor, setLineWidth, setLocation, setLocation, setLocked, setNumPoints, setOwner, setPoints, setPoints, setPoints, setPoints, setSize, setSize, setWidth, setX, setXs, setY, setYs, startTrans, stuffBounds, 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.

_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(Color lineColor)
Construct a new FigPoly w/ the given line color.

FigPoly

public FigPoly(Color lineColor,
               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 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 Polygon getPolygon()
Get the current vector of points as a java.awt.Polygon.

setPolygon

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

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.

setEndPoints

public void setEndPoints(Point start,
                         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(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.

getPoints

public Point getPoints(int i)
return the point at index i.
Overrides:
getPoints in class Fig

getPointsVector

public Vector getPointsVector()

getPointsVectorNotFirst

public Vector getPointsVectorNotFirst()

getFirstPoint

public Point getFirstPoint()
Overrides:
getFirstPoint in class Fig

getLastPoint

public 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
Overrides:
setPoints in class Fig

cleanUp

public void cleanUp()
Overrides:
cleanUp in class Fig

getClosestPoint

public Point getClosestPoint(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 Vector getGravityPoints()
Overrides:
getGravityPoints in class Fig

paint

public void paint(Graphics g)
Paint the FigPoly on the given Graphics
Overrides:
paint in class Fig

drawDashedPerimeter

protected void drawDashedPerimeter(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

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

isReshapable

public boolean isReshapable()
Overrides:
isReshapable in class Fig

isRotatable

public boolean isRotatable()
Overrides:
isRotatable in class Fig

countCornersContained

protected int countCornersContained(int x,
                                    int y,
                                    int w,
                                    int h)
Return the number of corners of the given rectangle that are conatined within this polygon.
Overrides:
countCornersContained in class Fig
See Also:
Fig.hit(java.awt.Rectangle)

hit

public boolean hit(Rectangle r)
Overrides:
hit in class Fig

calcBounds

public void calcBounds()
Update the bounding box.
Overrides:
calcBounds in class Fig