uci.gef
Class Fig

java.lang.Object
  |
  +--uci.gef.Fig
Direct Known Subclasses:
FigCircle, FigEdge, FigGroup, FigImage, FigLine, FigPoly, FigRect, FigText

public class Fig
extends Object
implements Cloneable, Serializable, PropertyChangeListener, PopupGenerator

This class is the base class for basic drawing objects such as rectangles, lines, text, circles, etc. Also, class FigGroup implements a composite figure. Fig's are Diagram elements that can be placed in any LayerDiagram. Fig's are also used to define the look of FigNodes on NetNodes.

See Also:
Serialized Form

Field Summary
protected  int[] _dashes
           
protected  Color _fillColor
          Fill color of fig object.
protected  boolean _filled
          True if the object should fill in its area.
protected  Fig _group
           
protected  int _h
           
protected  Layer _layer
          The Layer that this Fig is in.
protected  Color _lineColor
          Outline color of fig object.
protected  int _lineWidth
          Thickness of line around object, for now limited to 0 or 1.
protected  boolean _locked
          True if this object is locked and cannot be moved by the user.
protected  int _w
           
protected  int _x
          Coordinates of the Fig's bounding box.
protected  int _y
           
 int BORDER
          Margin between this Fig and automatically routed arcs.
static int[][] DASH_ARRAYS
           
static String[] DASHED_CHOICES
          The size of the dashes drawn when the Fig is dashed.
 int MIN_SIZE
          The smallest size that the user can drag this Fig.
 
Constructor Summary
Fig()
          Most subclasses will not use this constructor, it is only useful for subclasses that redefine most of the infrastructure provided by class Fig.
Fig(int x, int y, int w, int h)
          Construct a new Fig with the given bounds.
Fig(int x, int y, int w, int h, Color lineColor, Color fillColor)
          Construct a new Fig with the given bounds and colors.
Fig(int x, int y, int w, int h, Color lineColor, Color fillColor, Object own)
          Construct a new Fig with the given bounds, colors, and owner.
 
Method Summary
 void addPoint(int x, int y)
           
 void addPropertyChangeListener(PropertyChangeListener l)
          The specified PropertyChangeListeners propertyChange method will be called each time the value of any bound property is changed.
 void align(Rectangle r, int direction, Editor ed)
          Align this Fig with the given rectangle.
 void calcBounds()
          Update the bounds of this Fig.
 Point center()
          Return the center of the given Fig.
 String classNameAndBounds()
           
 void cleanUp()
           
 Object clone()
           
 Point connectionPoint(Point anotherPt)
          Return a point that should be used for arcs that to toward the given point.
 boolean contains(int x, int y)
          Reply true if the given point is inside the given Fig.
 boolean contains(Point p)
          Reply true if the given point is inside this Fig by calling contains(int x, int y).
 boolean contains(Rectangle r)
          Reply true if the all four corners of the given rectangle are inside this Fig, as determined by contains(int x, int y).
protected  int countCornersContained(int x, int y, int w, int h)
          Reply the number of corners of the given rectangle that are inside this Fig, as determined by contains(int x, int y).
 void createDrag(int anchorX, int anchorY, int x, int y, int snapX, int snapY)
          Resize the object for drag on creation.
 void damage()
          This Fig has changed in some way, tell its Layer to record my bounding box as a damaged region so that I will eventualy be redrawn.
 void delete()
          Remove this Fig from the Layer being edited by the given editor.
 void dispose()
          Delete whatever application object this Fig is representing, the Fig itself should automatically be deleted as a side-effect.
protected  int drawDashedLine(Graphics g, int phase, int x1, int y1, int x2, int y2)
           
protected  void drawDashedPerimeter(Graphics g)
           
 void endTrans()
          This is called after an Cmd mondifies a Fig and the Fig needs to be redrawn in its new position.
protected  void firePropChange(String propName, boolean oldV, boolean newV)
           
protected  void firePropChange(String propName, int oldV, int newV)
           
protected  void firePropChange(String propName, Object oldV, Object newV)
          Creates a PropertyChangeEvent and calls all registered listeners propertyChanged() method.
 Rectangle getBounds()
          Return a Rectangle that completely encloses this Fig.
 Point getClosestPoint(Point anotherPt)
           
 boolean getDashed()
          Get the dashed attribute
 int getDashed01()
           
 String getDashedString()
           
 Vector getEnclosedFigs()
           
 Fig getEnclosingFig()
           
 Color getFillColor()
           
 boolean getFilled()
           
 int getFilled01()
           
 Point getFirstPoint()
           
 Vector getGravityPoints()
           
 Fig getGroup()
           
 int getHalfHeight()
           
 int getHalfWidth()
           
 int getHeight()
           
 String getId()
           
 Point getLastPoint()
           
 Layer getLayer()
           
 Color getLineColor()
           
 int getLineWidth()
           
 Point getLocation()
          Returns a point that is the upper left corner of the Fig's bounding box.
 boolean getLocked()
           
 Dimension getMinimumSize()
          Returns the minimum size of the Fig.
 int getNumPoints()
           
 Object getOwner()
           
 int getPerimeterLength()
          Return the length of the path around this Fig.
 Point[] getPoints()
           
 Point getPoints(int i)
           
 Vector getPopUpActions(MouseEvent me)
           
 Dimension getPreferedSize()
          Returns the prefered size of the Fig.
 Dimension getSize()
          Returns the size of the Fig.
 String getTipString(MouseEvent me)
           
 Rectangle getTrapRect()
           
 boolean getUseTrapRect()
           
 int getWidth()
           
 int getX()
           
 int[] getXs()
           
 int getY()
           
 int[] getYs()
           
 boolean hit(Rectangle r)
          Reply true if the given rectangle contains some pixels of the Fig.
 void insertPoint(int i, int x, int y)
           
 boolean intersects(Rectangle r)
          Reply true if the object intersects the given rectangle.
 boolean isLowerRightResizable()
          Returns true if this Fig can be resized by the user.
 boolean isMovable()
          Returns true if this Fig can be moved around by the user.
 boolean isReshapable()
          Returns true if this Fig can be reshaped by the user.
 boolean isResizable()
          Returns true if this Fig can be resized by the user.
 boolean isRotatable()
          Returns true if this Fig can be rotated by the user.
 Selection makeSelection()
          Returns a custom Selection object for use when this Fig is selected by the user.
 boolean OK()
          Check class invariants to make sure the Fig is in a valid state.
 void paint(Graphics g)
          Method to paint this Fig.
 Point pointAlongPerimeter(int dist)
          Return a point at the given distance along the path around this Fig.
 void postLoad()
           
 void postSave()
           
 void preSave()
           
 void print(Graphics g)
          Draw the Fig on a PrintGraphics.
 void propertyChange(PropertyChangeEvent pce)
          By default just pass it up to enclosing groups.
 void removePoint(int i)
           
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove this PropertyChangeListener from the JellyBeans internal list.
 void reorder(int func, Layer lay)
          Change the back-to-front ordering of a Fig in LayerDiagram.
 Rectangle routingRect()
          Reply a rectangle that arcs should not route through.
 void setBounds(int x, int y, int w, int h)
          Set the bounds of this Fig.
 void setBounds(Rectangle r)
          Change my bounding box to the given Rectangle.
 void setDashed(boolean now_dashed)
          Set line to be dashed or not
 void setDashedString(String dashString)
           
 void setEnclosingFig(Fig f)
           
 void setFillColor(Color col)
          Sets the color that will be used if the Fig is filled.
 void setFilled(boolean f)
          Sets a flag to either fill the Fig with its fillColor or not.
 void setGroup(Fig f)
          Sets the enclosing FigGroup of this Fig.
 void setHeight(int h)
           
 void setLayer(Layer lay)
          Sets the Layer that this Fig belongs to.
 void setLineColor(Color col)
          Sets the color to be used if the lineWidth is > 0.
 void setLineWidth(int w)
          Set the line width.
 void setLocation(int x, int y)
          Move the Fig to the given position.
 void setLocation(Point p)
          Move the Fig to the given position.
 void setLocked(boolean b)
          Sets whether this Fig is locked or not.
 void setNumPoints(int npoints)
           
 void setOwner(Object own)
          Sets the owner object of this Fig.
 void setPoints(Handle h, int x, int y)
           
 void setPoints(Handle h, Point p)
           
 void setPoints(int i, int x, int y)
           
 void setPoints(int i, Point p)
           
 void setPoints(Point[] ps)
          Get and set the points along a path for Figs that are path-like.
 void setSize(Dimension d)
          Sets the size of the Fig.
 void setSize(int w, int h)
          Sets the size of the Fig.
 void setWidth(int w)
           
 void setX(int x)
           
 void setXs(int[] xs)
           
 void setY(int y)
           
 void setYs(int[] ys)
           
 void startTrans()
          This indicates that some Cmd is starting a manipulation on the receiving Fig and that redrawing must take place at the objects old location.
 void stuffBounds(Rectangle r)
          Reshape the given rectangle to be my bounding box.
 void stuffPointAlongPerimeter(int dist, Point res)
           
 void translate(int dx, int dy)
          Change the position of the object from were it is to were it is plus dx and dy.
 boolean within(Rectangle r)
          Reply true if the entire Fig is contained within the given Rectangle.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_SIZE

public final int MIN_SIZE
The smallest size that the user can drag this Fig.

DASHED_CHOICES

public static String[] DASHED_CHOICES
The size of the dashes drawn when the Fig is dashed.

DASH_ARRAYS

public static int[][] DASH_ARRAYS

_layer

protected Layer _layer
The Layer that this Fig is in. Each Fig can be in exactly one Layer, but there can be multiple Editors on a given Layer.

_locked

protected boolean _locked
True if this object is locked and cannot be moved by the user.

_x

protected int _x
Coordinates of the Fig's bounding box. It is the responsibility of subclasses to make sure that these values are ALWAYS up-to-date.

_y

protected int _y

_w

protected int _w

_h

protected int _h

_lineColor

protected Color _lineColor
Outline color of fig object.

_fillColor

protected Color _fillColor
Fill color of fig object.

_lineWidth

protected int _lineWidth
Thickness of line around object, for now limited to 0 or 1.

_dashes

protected int[] _dashes

_filled

protected boolean _filled
True if the object should fill in its area.

_group

protected Fig _group

BORDER

public final int BORDER
Margin between this Fig and automatically routed arcs.
Constructor Detail

Fig

public Fig(int x,
           int y,
           int w,
           int h,
           Color lineColor,
           Color fillColor,
           Object own)
Construct a new Fig with the given bounds, colors, and owner.

Fig

public Fig(int x,
           int y,
           int w,
           int h,
           Color lineColor,
           Color fillColor)
Construct a new Fig with the given bounds and colors.

Fig

public Fig(int x,
           int y,
           int w,
           int h)
Construct a new Fig with the given bounds.

Fig

public Fig()
Most subclasses will not use this constructor, it is only useful for subclasses that redefine most of the infrastructure provided by class Fig.
Method Detail

clone

public Object clone()
Overrides:
clone in class Object

OK

public boolean OK()
Check class invariants to make sure the Fig is in a valid state. This is useful for debugging. needs-more-work.

setLayer

public void setLayer(Layer lay)
Sets the Layer that this Fig belongs to. Fires PropertyChangeEvent "layer".

getLayer

public Layer getLayer()

setLocked

public void setLocked(boolean b)
Sets whether this Fig is locked or not. Most Cmds check to see if Figs are locked and will not request modifications to locked Figs. Fires PropertyChangeEvent "locked".

getLocked

public boolean getLocked()

getTrapRect

public Rectangle getTrapRect()

getUseTrapRect

public boolean getUseTrapRect()

getEnclosingFig

public Fig getEnclosingFig()

setEnclosingFig

public void setEnclosingFig(Fig f)

getEnclosedFigs

public Vector getEnclosedFigs()

setOwner

public void setOwner(Object own)
Sets the owner object of this Fig. Fires PropertyChangeEvent "owner"

getOwner

public Object getOwner()

getId

public String getId()

setGroup

public void setGroup(Fig f)
Sets the enclosing FigGroup of this Fig. The enclosing group is always notified of property changes, without need to add a listener.

getGroup

public Fig getGroup()

setLineColor

public void setLineColor(Color col)
Sets the color to be used if the lineWidth is > 0. If col is null, sets the lineWidth to 0. Fires PropertyChangeEvent "lineColor", or "lineWidth".

getLineColor

public Color getLineColor()

setFillColor

public void setFillColor(Color col)
Sets the color that will be used if the Fig is filled. If col is null, turns off filling. Fires PropertyChangeEvent "fillColor", or "filled".

getFillColor

public Color getFillColor()

setFilled

public void setFilled(boolean f)
Sets a flag to either fill the Fig with its fillColor or not. Fires PropertyChangeEvent "filled".

getFilled

public boolean getFilled()

getFilled01

public int getFilled01()

setLineWidth

public void setLineWidth(int w)
Set the line width. Zero means lines are not draw. One draws them one pixel wide. Larger widths are not yet supported. Fires PropertyChangeEvent "lineWidth".

getLineWidth

public int getLineWidth()

setDashedString

public void setDashedString(String dashString)

getDashedString

public String getDashedString()

setDashed

public void setDashed(boolean now_dashed)
Set line to be dashed or not

getDashed

public boolean getDashed()
Get the dashed attribute

getDashed01

public int getDashed01()

getTipString

public String getTipString(MouseEvent me)

print

public void print(Graphics g)
Draw the Fig on a PrintGraphics. This just calls paint.

paint

public void paint(Graphics g)
Method to paint this Fig. By default it paints an "empty" space, subclasses should override this method.

drawDashedPerimeter

protected void drawDashedPerimeter(Graphics g)

drawDashedLine

protected int drawDashedLine(Graphics g,
                             int phase,
                             int x1,
                             int y1,
                             int x2,
                             int y2)

classNameAndBounds

public String classNameAndBounds()

getBounds

public Rectangle getBounds()
Return a Rectangle that completely encloses this Fig.

stuffBounds

public void stuffBounds(Rectangle r)
Reshape the given rectangle to be my bounding box.

setBounds

public final void setBounds(Rectangle r)
Change my bounding box to the given Rectangle. Just calls setBounds(x, y, w, h).

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Set the bounds of this Fig. Fires PropertyChangeEvent "bounds".

delete

public void delete()
Remove this Fig from the Layer being edited by the given editor.

dispose

public void dispose()
Delete whatever application object this Fig is representing, the Fig itself should automatically be deleted as a side-effect. Simple Figs have no underlying model, so they are just deleted. Figs that graphically present some part of an underlying model should NOT delete themselves, instead they should ask the model to dispose, and IF it does then the figs will be notified.

makeSelection

public Selection makeSelection()
Returns a custom Selection object for use when this Fig is selected by the user. Normally SelectionManger makes the Selection using its own rules. This is for special cases.

isMovable

public boolean isMovable()
Returns true if this Fig can be moved around by the user.

isResizable

public boolean isResizable()
Returns true if this Fig can be resized by the user.

isLowerRightResizable

public boolean isLowerRightResizable()
Returns true if this Fig can be resized by the user.

isReshapable

public boolean isReshapable()
Returns true if this Fig can be reshaped by the user.

isRotatable

public boolean isRotatable()
Returns true if this Fig can be rotated by the user.

damage

public void damage()
This Fig has changed in some way, tell its Layer to record my bounding box as a damaged region so that I will eventualy be redrawn. This method can be called directly, but using startTrans() and endTrans() instead is generally faster, simpler, and better avoids "screen dirt".

startTrans

public void startTrans()
This indicates that some Cmd is starting a manipulation on the receiving Fig and that redrawing must take place at the objects old location. This adds a damage region to all editors that are displaying this Fig. This method also locks the RedrawManager so that no redraws will take place during the transaction. Locking the RedrawManager is key to avoiding "screen dirt". Each call to startTrans() MUST be matched with a call to endTrans().

endTrans

public void endTrans()
This is called after an Cmd mondifies a Fig and the Fig needs to be redrawn in its new position. This also unlocks the RedrawManager. In general, endTrans() should be * paired with a startTrans(), although it is alright to have extra calls to endTrans().

routingRect

public Rectangle routingRect()
Reply a rectangle that arcs should not route through. Basically this is the bounding box plus some margin around all egdes.

reorder

public void reorder(int func,
                    Layer lay)
Change the back-to-front ordering of a Fig in LayerDiagram. Should the Fig have any say in it?
See Also:
LayerDiagram.reorder(uci.gef.Fig, int), CmdReorder

translate

public void translate(int dx,
                      int dy)
Change the position of the object from were it is to were it is plus dx and 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 property "bounds".

setLocation

public final void setLocation(Point p)
Move the Fig to the given position.

setLocation

public void setLocation(int x,
                        int y)
Move the Fig to the given position. By default translates the Fig so that the upper left corner of its bounding box is at the location. Fires property "bounds".

getLocation

public Point getLocation()
Returns a point that is the upper left corner of the Fig's bounding box.

getSize

public Dimension getSize()
Returns the size of the Fig.

setSize

public final void setSize(Dimension d)
Sets the size of the Fig. Fires property "bounds".

setSize

public void setSize(int w,
                    int h)
Sets the size of the Fig. Fires property "bounds".

getMinimumSize

public Dimension getMinimumSize()
Returns the minimum size of the Fig. This is the smallest size that the user can make this Fig by dragging. You can ignore this and make Figs smaller programmitically if you must.

getPreferedSize

public Dimension getPreferedSize()
Returns the prefered size of the Fig. This will be useful for automated layout. By default just uses the current size. Subclasses must override to return something useful.

getPopUpActions

public Vector getPopUpActions(MouseEvent me)
Specified by:
getPopUpActions in interface PopupGenerator

setX

public void setX(int x)

getX

public int getX()

setY

public void setY(int y)

getY

public int getY()

setWidth

public void setWidth(int w)

getWidth

public int getWidth()

getHalfWidth

public int getHalfWidth()

setHeight

public void setHeight(int h)

getHeight

public int getHeight()

getHalfHeight

public int getHalfHeight()

setPoints

public void setPoints(Point[] ps)
Get and set the points along a path for Figs that are path-like.

getFirstPoint

public Point getFirstPoint()

getLastPoint

public Point getLastPoint()

getPoints

public Point[] getPoints()

setPoints

public final void setPoints(int i,
                            Point p)

setPoints

public final void setPoints(Handle h,
                            Point p)

setPoints

public void setPoints(int i,
                      int x,
                      int y)

setPoints

public void setPoints(Handle h,
                      int x,
                      int y)

getPoints

public Point getPoints(int i)

getNumPoints

public int getNumPoints()

setNumPoints

public void setNumPoints(int npoints)

getXs

public int[] getXs()

setXs

public void setXs(int[] xs)

getYs

public int[] getYs()

setYs

public void setYs(int[] ys)

addPoint

public void addPoint(int x,
                     int y)

insertPoint

public void insertPoint(int i,
                        int x,
                        int y)

removePoint

public void removePoint(int i)

getPerimeterLength

public int getPerimeterLength()
Return the length of the path around this Fig. By default, returns the perimeter of the Fig's bounding box. Subclasses like FigPoly have more specific logic.

pointAlongPerimeter

public Point pointAlongPerimeter(int dist)
Return a point at the given distance along the path around this Fig. By default, uses perimeter of the Fig's bounding box. Subclasses like FigPoly have more specific logic.

stuffPointAlongPerimeter

public void stuffPointAlongPerimeter(int dist,
                                     Point res)

align

public void align(Rectangle r,
                  int direction,
                  Editor ed)
Align this Fig with the given rectangle. Some subclasses may need to know the editor that initiated this action.

contains

public boolean contains(int x,
                        int y)
Reply true if the given point is inside the given Fig. By default reply true if the point is in my bounding box. Subclasses like FigCircle and FigEdge do more specific checks.
See Also:
FigCircle, FigEdge

contains

public final boolean contains(Point p)
Reply true if the given point is inside this Fig by calling contains(int x, int y).

contains

public boolean contains(Rectangle r)
Reply true if the all four corners of the given rectangle are inside this Fig, as determined by contains(int x, int y).

within

public boolean within(Rectangle r)
Reply true if the entire Fig is contained within the given Rectangle. This can be used by ModeSelect to select Figs that are totally within the selection rectangle.

hit

public boolean hit(Rectangle r)
Reply true if the given rectangle contains some pixels of the Fig. This is used to determine if the user is trying to select this Fig. Rather than ask if the mouse point is in the Fig, I use a small rectangle around the mouse point so that small objects and lines are easier to select.

countCornersContained

protected int countCornersContained(int x,
                                    int y,
                                    int w,
                                    int h)
Reply the number of corners of the given rectangle that are inside this Fig, as determined by contains(int x, int y).

intersects

public boolean intersects(Rectangle r)
Reply true if the object intersects the given rectangle. Used for selective redrawing and by ModeSelect to select all Figs that are partly within the selection rectangle.

center

public Point center()
Return the center of the given Fig. By default the center is the center of its bounding box. Subclasses may want to define something else.

connectionPoint

public Point connectionPoint(Point anotherPt)
Return a point that should be used for arcs that to toward the given point. By default, this makes arcs end on the edge that is nearest the given point. needs-more-work: define gravity points, berths

getGravityPoints

public Vector getGravityPoints()

getClosestPoint

public Point getClosestPoint(Point anotherPt)

createDrag

public void createDrag(int anchorX,
                       int anchorY,
                       int x,
                       int y,
                       int snapX,
                       int snapY)
Resize the object for drag on creation. It bypasses the things done in resize so that the position of the object can be kept as the anchor point. Needs-More-Work: do I really need this function?
See Also:
FigLine.createDrag(int, int, int, int, int, int)

calcBounds

public void calcBounds()
Update the bounds of this Fig. By default it is assumed that the bounds have already been updated, so this does nothing.
See Also:
FigText.calcBounds()

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
The specified PropertyChangeListeners propertyChange method will be called each time the value of any bound property is changed. Note: the JavaBeans specification does not require PropertyChangeListeners to run in any particular order.

Since most Fig's will never have any listeners, and I want Figs to be fairly light-weight objects, listeners are kept in a global Hashtable, keyed by Fig. NOTE: It is important that all listeners eventually remove themselves, otherwise this will prevent garbage collection.


removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove this PropertyChangeListener from the JellyBeans internal list. If the PropertyChangeListener isn't on the list, silently do nothing.

firePropChange

protected void firePropChange(String propName,
                              Object oldV,
                              Object newV)
Creates a PropertyChangeEvent and calls all registered listeners propertyChanged() method.

firePropChange

protected void firePropChange(String propName,
                              int oldV,
                              int newV)

firePropChange

protected void firePropChange(String propName,
                              boolean oldV,
                              boolean newV)

propertyChange

public void propertyChange(PropertyChangeEvent pce)
By default just pass it up to enclosing groups. Subclasses of FigNode may want to override this method.
Specified by:
propertyChange in interface PropertyChangeListener

preSave

public void preSave()

postSave

public void postSave()

postLoad

public void postLoad()

cleanUp

public void cleanUp()