com.rolemodelsoft.drawlet.shapes.lines
Class Line

java.lang.Object
  |
  +--com.rolemodelsoft.drawlet.basics.AbstractPaintable
        |
        +--com.rolemodelsoft.drawlet.basics.AbstractFigure
              |
              +--com.rolemodelsoft.drawlet.shapes.AbstractShape
                    |
                    +--com.rolemodelsoft.drawlet.shapes.lines.LinearShape
                          |
                          +--com.rolemodelsoft.drawlet.shapes.lines.Line
Direct Known Subclasses:
ConnectingLine

public class Line
extends LinearShape

This provides a basic implementation of Lines. It is not expected that the locators that make up this line be connected to other figures.

See Also:
Serialized Form

Field Summary
protected  Locator[] points
          The locators which define the points of the line.
protected  java.awt.Polygon polygon
          A cache to keep the bounds for efficient reference.
 
Fields inherited from class com.rolemodelsoft.drawlet.shapes.lines.LinearShape
lineColor
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
listeners, locationListeners
 
Constructor Summary
Line(int beginX, int beginY, int endX, int endY)
          Constructs and initializes a new instance of a line.
Line(Locator[] locators)
          Constructs and initializes a new instance of a line.
Line(Locator begin, Locator end)
          Constructs and initializes a new instance of a line.
 
Method Summary
protected  void basicAddLocator(int index, Locator locator)
          Add the locator at the given position.
protected  void basicRemoveLocator(int index)
          Remove the locator at the given position.
protected  void basicReshape(int x, int y, int width, int height)
          Reshapes the receiver to the specified bounding box.
protected  void basicSetLocator(int index, Locator locator)
          Set the locator at the given position.
protected  void basicTranslate(int x, int y)
          Moves the receiver in the x and y direction.
 boolean contains(int x, int y)
          Checks whether a specified x,y location is "inside" this Figure, where x and y are defined to be relative to the coordinate system of this figure.
 java.lang.Object duplicateIn(java.util.Hashtable duplicates)
          Duplicates the receiver in the given Hashtable.
protected  int estimatedDuplicateSize()
          Answers the expected number of significant duplicates when duplicating the receiver.
 java.awt.Rectangle getBounds()
          Returns the current bounds of the receiver.
 Locator getLocator(int index)
          Answer the indexth locator.
 int getNumberOfPoints()
          Answer the number of points which define the receiver.
protected  java.awt.Polygon getPolygon()
          Answer the Polygon associated with the receiver.
 boolean intersects(java.awt.Rectangle bounds)
          Answers whether the receiver intersects a Rectangular area.
 void paint(java.awt.Graphics g)
          Paints the receiver.
 void postDuplicate(java.util.Hashtable duplicates)
          After a series of Figures are duplicated, this can be sent to each of the duplicates to resolve any changes it might like to reconcile.
protected  void resetBoundsCache()
          Flush caches with respect to determining bounds.
protected  void resetLocationCache()
          Flush caches with respect to determining location.
protected  void resetSizeCache()
          Flush caches with respect to determining size.
 
Methods inherited from class com.rolemodelsoft.drawlet.shapes.lines.LinearShape
addLocator, addLocator, defaultLineColor, getHandles, getLineColor, getStyle, insideSegment, insideTolerance, insideTolerance, locatorAt, removeLocator, requestConnection, setLineColor, setLocator, setStyle
 
Methods inherited from class com.rolemodelsoft.drawlet.shapes.AbstractShape
basicResize, reshapedPolygon, reshapedPolygon, setBounds, setSize
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
addPropertyChangeListener, addRelatedLocationListener, basicMove, changedLocation, changedShape, changedSize, contains, contains, deleteLocationListeners, disconnect, duplicate, editTool, figureFromLocator, fireLocationChange, firePropertyChange, firePropertyChange, fireRelationChange, fireShapeChange, fireSizeChange, getLocation, getLocator, intersects, isObsolete, isWithin, isWithin, move, move, relatedLocationListeners, removePropertyChangeListener, removeRelatedLocationListener, setSize, translate
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractPaintable
getBottom, getHeight, getLeft, getRight, getSize, getTop, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

protected Locator[] points
The locators which define the points of the line.

polygon

protected transient java.awt.Polygon polygon
A cache to keep the bounds for efficient reference.
Constructor Detail

Line

public Line(Locator[] locators)
Constructs and initializes a new instance of a line.
Parameters:
locators - the locators which define the points of the line
Throws:
java.lang.IllegalArgumentException - If their are not at least 2 locators.

Line

public Line(int beginX,
            int beginY,
            int endX,
            int endY)
Constructs and initializes a new instance of a line.
Parameters:
beginX - the x coordinate for the first point defining the line
beginY - the y coordinate for the first point defining the line
endX - the x coordinate for the second point defining the line
endY - the y coordinate for the second point defining the line

Line

public Line(Locator begin,
            Locator end)
Constructs and initializes a new instance of a line.
Parameters:
begin - the locator which is the first point defining the line
end - the locator which is the second point defining the line
Method Detail

basicAddLocator

protected void basicAddLocator(int index,
                               Locator locator)
Add the locator at the given position.
Overrides:
basicAddLocator in class LinearShape
Parameters:
index - the index of the locator desired.
locator - the new Locator.

basicRemoveLocator

protected void basicRemoveLocator(int index)
Remove the locator at the given position.
Overrides:
basicRemoveLocator in class LinearShape
Parameters:
index - the index of the locator no longer desired.

basicReshape

protected void basicReshape(int x,
                            int y,
                            int width,
                            int height)
Reshapes the receiver to the specified bounding box.
Overrides:
basicReshape in class LinearShape
Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the receiver
height - the height of the receiver
See Also:
getBounds()

basicSetLocator

protected void basicSetLocator(int index,
                               Locator locator)
Set the locator at the given position.
Overrides:
basicSetLocator in class LinearShape
Parameters:
index - the index of the locator desired.
locator - the new Locator.

basicTranslate

protected void basicTranslate(int x,
                              int y)
Moves the receiver in the x and y direction.
Overrides:
basicTranslate in class LinearShape
Parameters:
x - amount to move in the x direction
y - amount to move in the y direction

contains

public boolean contains(int x,
                        int y)
Checks whether a specified x,y location is "inside" this Figure, where x and y are defined to be relative to the coordinate system of this figure.
Overrides:
contains in class LinearShape
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
boolean value of true if the specified x,y location is "inside this Figure; false otherwise.

duplicateIn

public java.lang.Object duplicateIn(java.util.Hashtable duplicates)
Duplicates the receiver in the given Hashtable.
Overrides:
duplicateIn in class AbstractFigure
Parameters:
duplicates - the Hashtable to put the new duplicate in
Returns:
an Object which is a duplicate of the receiver

estimatedDuplicateSize

protected int estimatedDuplicateSize()
Answers the expected number of significant duplicates when duplicating the receiver. Subclasses may wish to override.
Overrides:
estimatedDuplicateSize in class AbstractFigure

getBounds

public java.awt.Rectangle getBounds()
Returns the current bounds of the receiver.
Overrides:
getBounds in class LinearShape
Returns:
a Rectangle representing the current bounds of the receiver.

getLocator

public Locator getLocator(int index)
Answer the indexth locator.
Overrides:
getLocator in class LinearShape
Parameters:
index - the index of the locator desired.
Returns:
the Locator at the given index

getNumberOfPoints

public int getNumberOfPoints()
Answer the number of points which define the receiver.
Overrides:
getNumberOfPoints in class LinearShape
Returns:
an integer representing the number of points which define the receiver

getPolygon

protected java.awt.Polygon getPolygon()
Answer the Polygon associated with the receiver.
Returns:
the Polygon associated with the receiver.

intersects

public boolean intersects(java.awt.Rectangle bounds)
Answers whether the receiver intersects a Rectangular area.
Overrides:
intersects in class LinearShape
Parameters:
bounds - the Rectangular area
Returns:
boolean value of true if the receiver intersects the given rectangular area; false otherwise.

paint

public void paint(java.awt.Graphics g)
Paints the receiver.
Overrides:
paint in class LinearShape
Parameters:
g - the specified Graphics window

postDuplicate

public void postDuplicate(java.util.Hashtable duplicates)
After a series of Figures are duplicated, this can be sent to each of the duplicates to resolve any changes it might like to reconcile. In this case, remove any dependency on any figures defining original points. If there is an available duplicate corresponding to the original, use it as the original was used. If not, convert it to a non-Figure- dependent point.
Overrides:
postDuplicate in class AbstractFigure
Parameters:
duplicates - a Hashtable where originals as keys and duplicates as elements

resetBoundsCache

protected void resetBoundsCache()
Flush caches with respect to determining bounds.
Overrides:
resetBoundsCache in class AbstractShape

resetLocationCache

protected void resetLocationCache()
Flush caches with respect to determining location.
Overrides:
resetLocationCache in class AbstractFigure

resetSizeCache

protected void resetSizeCache()
Flush caches with respect to determining size.
Overrides:
resetSizeCache in class AbstractShape