org.tigris.gef.presentation
Class FigLine

java.lang.Object
  extended by org.tigris.gef.presentation.Fig
      extended by org.tigris.gef.presentation.FigLine
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, PopupGenerator

public class FigLine
extends Fig

Class to display lines in diagrams.

See Also:
Serialized Form

Field Summary
protected  int _x1
          Coordinates of the start and end points of the line.
protected  int _x2
           
protected  int _y1
           
protected  int _y2
           
 
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
FigLine(int x1, int y1, int x2, int y2)
          Construct a new FigLine with the given coordinates and attributes.
FigLine(int x1, int y1, int x2, int y2, java.awt.Color lineColor)
          Construct a new FigLine with the given coordinates and color.
 
Method Summary
 void calcBounds()
          Update the bounding box so that it encloses (_x1, _y1)--(_x2, _y2).
 java.awt.Point connectionPoint(java.awt.Point anotherPt)
          Replys the point that other connected Figs should attach to.
 void createDrag(int anchorX, int anchorY, int x, int y, int snapX, int snapY)
          Resize the object for drag on creation.
 int getNumPoints()
          Returns the number of points.
 int getPerimeterLength()
          return the approximate arc length of the path in pixel units
 java.awt.Point getPoint(int i)
          returns the ith point.
 java.awt.Point[] getPoints()
          returns an array of lenfth 2 that has the line's endpoints.
 int getX1()
           
 int getX2()
           
 int[] getXs()
          Returns an array of the X coordinates of all (2) points.
 int getY1()
           
 int getY2()
           
 int[] getYs()
          Returns an array of the Y coordinates of all (2) points.
 boolean hit(java.awt.Rectangle r)
          Reply true if the given point is "near" the line.
 boolean intersects(java.awt.Rectangle rect)
          Tests, if the given rectangle intersects with this line
 boolean intersectsPerimeter(java.awt.Rectangle rect)
          Tests if the given rectangle intersects with the perimeter of this polygon.
 boolean isReshapable()
          Returns true if this Fig can be reshaped by the user.
 boolean isResizable()
          Lines can be reshaped, but not resized or rotated (for now).
 boolean isRotatable()
          Returns true if this Fig can be rotated by the user.
 void paint(java.awt.Graphics g)
          Paint this line object.
 void setBounds(int x, int y, int w, int h)
          Sets the bounds of the line.
 void setPoints(int i, int x, int y)
          Move point i to location (x, y).
 void setPoints(java.awt.Point[] ps)
          Sets both endpoints of a line.
 void setShape(int x1, int y1, int x2, int y2)
          Set both end points.
 void setShape(java.awt.Point p1, java.awt.Point p2)
          Set both end points.
 void setX1(int x1)
          Set one of the end point coordinates.
 void setX2(int x2)
           
 void setY1(int y1)
           
 void setY2(int y2)
           
 void stuffPointAlongPerimeter(int dist, java.awt.Point res)
          return a point that is dist pixels along the path
 void translate(int dx, int dy)
          Translate (move) this Fig.
 
Methods inherited from class org.tigris.gef.presentation.Fig
addAnnotation, addPoint, addPropertyChangeListener, align, center, classNameAndBounds, cleanUp, clone, contains, contains, contains, countCornersContained, damage, deleteFromModel, drawDashedLine, drawDashedPerimeter, endTrans, firePropChange, firePropChange, firePropChange, getAnnotationOwner, getAnnotationStrategy, getBounds, getBounds, getClosestPoint, getContext, getDashed, getDashed01, getDashedString, getEnclosedFigs, getEnclosingFig, getFillColor, getFilled, getFilled01, getFirstPoint, getGravityPoints, getGroup, getHalfHeight, getHalfWidth, getHandleBox, getHeight, getId, getLastPoint, getLayer, getLineColor, getLineWidth, getLocation, getLocked, getMinimumSize, getOwner, getPopUpActions, getPreferredSize, getPrivateData, getResource, getSingle, getSize, getTipString, getTrapRect, getUseTrapRect, getVisState, getWidth, getX, getY, hasFillColor, hasLineColor, initAnnotations, insertPoint, isAnnotation, isCopyable, isCutable, isLowerRightResizable, isMovable, isSelected, isVisible, makeSelection, OK, pointAlongPerimeter, postLoad, postSave, preSave, print, propertyChange, redraw, removeAnnotation, removeAnnotation, removeFromDiagram, removePoint, 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, 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

_x1

protected int _x1
Coordinates of the start and end points of the line. Note: _x, _y, _w, and _h from class Fig are always updated by calcBounds() whenever _x1, _y1, _x2, or _y2 change.


_y1

protected int _y1

_x2

protected int _x2

_y2

protected int _y2
Constructor Detail

FigLine

public FigLine(int x1,
               int y1,
               int x2,
               int y2,
               java.awt.Color lineColor)
Construct a new FigLine with the given coordinates and color.


FigLine

public FigLine(int x1,
               int y1,
               int x2,
               int y2)
Construct a new FigLine with the given coordinates and attributes.

Method Detail

setShape

public final void setShape(java.awt.Point p1,
                           java.awt.Point p2)
Set both end points. Fires PropertyChange with "bounds".


setShape

public void setShape(int x1,
                     int y1,
                     int x2,
                     int y2)
Set both end points. Fires PropertyChange with "bounds".


getX1

public int getX1()

getY1

public int getY1()

getX2

public int getX2()

getY2

public int getY2()

setX1

public void setX1(int x1)
Set one of the end point coordinates. Each of these methods fires PropertyChange with "bounds".


setY1

public void setY1(int y1)

setX2

public void setX2(int x2)

setY2

public void setY2(int y2)

isResizable

public boolean isResizable()
Lines can be reshaped, but not resized or rotated (for now).

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

setPoints

public void setPoints(java.awt.Point[] ps)
Sets both endpoints of a line. Length of array must be 2. Fires PropertyChange with "bounds".

Overrides:
setPoints in class Fig

getPoints

public java.awt.Point[] getPoints()
returns an array of lenfth 2 that has the line's endpoints.

Overrides:
getPoints in class Fig

setPoints

public void setPoints(int i,
                      int x,
                      int y)
Move point i to location (x, y). Argument i must be 0 or 1. Fires PropertyChange with "bounds".


getPoint

public java.awt.Point getPoint(int i)
returns the ith point. Argument i must be 0 or 1.

Overrides:
getPoint in class Fig

getNumPoints

public int getNumPoints()
Returns the number of points. Lines always have 2 points.

Overrides:
getNumPoints in class Fig

getXs

public int[] getXs()
Returns an array of the X coordinates of all (2) points.

Overrides:
getXs in class Fig

getYs

public int[] getYs()
Returns an array of the Y coordinates of all (2) points.

Overrides:
getYs in class Fig

getPerimeterLength

public int getPerimeterLength()
return the approximate arc length of the path in pixel units

Overrides:
getPerimeterLength in class Fig

stuffPointAlongPerimeter

public void stuffPointAlongPerimeter(int dist,
                                     java.awt.Point res)
return a point that is dist pixels along the path

Overrides:
stuffPointAlongPerimeter in class Fig

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Sets the bounds of the line. The line is scaled to fit within the new bounding box. Fires PropertyChange with "bounds".

Overrides:
setBounds in class Fig

connectionPoint

public java.awt.Point connectionPoint(java.awt.Point anotherPt)
Replys the point that other connected Figs should attach to. Currently replys the point on the this line that is closest to the given point.

Overrides:
connectionPoint in class Fig

translate

public void translate(int dx,
                      int dy)
Translate (move) this Fig. Fires PropertyChange with "bounds".

Overrides:
translate in class Fig

calcBounds

public void calcBounds()
Update the bounding box so that it encloses (_x1, _y1)--(_x2, _y2).

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

paint

public void paint(java.awt.Graphics g)
Paint this line object.

Overrides:
paint in class Fig

hit

public boolean hit(java.awt.Rectangle r)
Reply true if the given point is "near" the line. Nearness allows the user to more easily select the line with the mouse. Needs-More-Work: I should probably have two functions contains() which gives a strict geometric version, and hit() which is for selection by mouse clicks.

Overrides:
hit in class Fig
Parameters:
r - the rectangular hit area
Returns:
true if the hit rectangle strikes this fig

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. Fires PropertyChange with "bounds".

Overrides:
createDrag in class Fig
See Also:
createDrag(int, int, int, int, int, int)

intersectsPerimeter

public boolean intersectsPerimeter(java.awt.Rectangle rect)
Tests if the given rectangle intersects with the perimeter of this polygon. For this implementation the polygon is just a 2 dimensional straight line. So this method is the same as intersects.

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

intersects

public boolean intersects(java.awt.Rectangle rect)
Tests, if the given rectangle intersects with this line

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