com.rolemodelsoft.drawlet.shapes.lines
Class LinearShape

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

public abstract class LinearShape
extends AbstractShape
implements LineFigure

This provides basic default functionality for LineFigures that are assumed to be moveable and reshapeable with observers that want to know when their locations or shapes change. It provides most of its functionality based on its bounds, plus some additional facilities which assume the line is made up of multiple locators, and forces concrete subclasses to define, at a minimum: paint(Graphics); getLocator(int); getNumberOfPoints(); basicAddLocator(Locator,int); basicSetLocator(Locator,int); basicRemoveLocator(int);

See Also:
Serialized Form

Field Summary
protected  java.awt.Color lineColor
          The color with which to paint the line.
 
Fields inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
listeners, locationListeners
 
Fields inherited from interface com.rolemodelsoft.drawlet.Figure
FILL_COLOR_PROPERTY, LINE_COLOR_PROPERTY, LOCATION_PROPERTY, RELATION_PROPERTY, SHAPE_PROPERTY, SIZE_PROPERTY, STRING_PROPERTY, STYLE_PROPERTY, TEXT_COLOR_PROPERTY
 
Constructor Summary
LinearShape()
           
 
Method Summary
 void addLocator(int index, Locator locator)
          Add the locator at the appropriate position.
 void addLocator(Locator locator)
          Add the locator at the end.
protected abstract  void basicAddLocator(int index, Locator locator)
          Add the locator at the given position.
protected abstract  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 abstract  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" the receiver, where x and y are defined to be relative to the coordinate system of the receiver.
protected  java.awt.Color defaultLineColor()
          Answer the default/initial value for lineColor
 java.awt.Rectangle getBounds()
          Returns the current bounds of the receiver.
 Handle[] getHandles()
          Answer the handles associated with the receiver.
 java.awt.Color getLineColor()
          Answer the Color to use when drawing lines.
abstract  Locator getLocator(int index)
          Answer the indexth locator.
abstract  int getNumberOfPoints()
          Answer the number of points which define the receiver.
 DrawingStyle getStyle()
          Answer the style which defines how to paint the figure.
protected  boolean insideSegment(int x, int y, int x0, int y0, int x1, int y1)
          Answer whether the point specified is inside the specified line segment.
protected  double insideTolerance()
          Answer a number to define how close we have to be to the geometric line to be considered inside it.
protected  double insideTolerance(double slope)
          Answer a number to define how close we have to be to the geometric line to be considered inside it, given a particular slope.
 boolean intersects(java.awt.Rectangle bounds)
          Answers whether the receiver intersects a rectangular area.
 Locator locatorAt(int x, int y)
          Answers a locator corresponding to a significant point on the receiver.
 void paint(java.awt.Graphics g)
          Paints the receiver.
 void removeLocator(int index)
          Remove the locator at the given position.
 Locator requestConnection(Figure requestor, int x, int y)
          Answers a Locator corresponding to a significant point on the receiver that will serve as a connection to the other figure.
 void setLineColor(java.awt.Color color)
          Set the Color to use when drawing lines.
 void setLocator(int index, Locator locator)
          Set the locator at the appropriate position.
 void setStyle(DrawingStyle style)
          Set the DrawingStyle defining how to paint the receuver.
 
Methods inherited from class com.rolemodelsoft.drawlet.shapes.AbstractShape
basicResize, resetBoundsCache, resetSizeCache, reshapedPolygon, reshapedPolygon, setBounds, setSize
 
Methods inherited from class com.rolemodelsoft.drawlet.basics.AbstractFigure
addPropertyChangeListener, addRelatedLocationListener, basicMove, changedLocation, changedShape, changedSize, contains, contains, deleteLocationListeners, disconnect, duplicate, duplicateIn, editTool, estimatedDuplicateSize, figureFromLocator, fireLocationChange, firePropertyChange, firePropertyChange, fireRelationChange, fireShapeChange, fireSizeChange, getLocation, getLocator, intersects, isObsolete, isWithin, isWithin, move, move, postDuplicate, relatedLocationListeners, removePropertyChangeListener, removeRelatedLocationListener, resetLocationCache, 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

lineColor

protected java.awt.Color lineColor
The color with which to paint the line.
Constructor Detail

LinearShape

public LinearShape()
Method Detail

addLocator

public void addLocator(int index,
                       Locator locator)
Add the locator at the appropriate position. This is a TemplateMethod with hooks: resetBoundsCache() basicAddLocator() changedShape()
Specified by:
addLocator in interface LineFigure
Parameters:
locator - the new Locator to add.
index - the index of the locator desired.

addLocator

public void addLocator(Locator locator)
Add the locator at the end.
Specified by:
addLocator in interface LineFigure
Parameters:
locator - the new Locator to add.

basicAddLocator

protected abstract void basicAddLocator(int index,
                                        Locator locator)
Add the locator at the given position.
Parameters:
index - the index to add the Locator at.
locator - the new Locator.

basicRemoveLocator

protected abstract void basicRemoveLocator(int index)
Remove the locator at the given position.
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 AbstractShape
Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the figure
height - the height of the figure
See Also:
getBounds()

basicSetLocator

protected abstract void basicSetLocator(int index,
                                        Locator locator)
Set the locator at the given position.
Parameters:
index - the index of the locator to be set.
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 AbstractFigure
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" the receiver, where x and y are defined to be relative to the coordinate system of the receiver.
Overrides:
contains in class AbstractFigure
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.

defaultLineColor

protected java.awt.Color defaultLineColor()
Answer the default/initial value for lineColor
Returns:
a Color representing the default/initial value for lineColor

getBounds

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

getHandles

public Handle[] getHandles()
Answer the handles associated with the receiver.
Overrides:
getHandles in class AbstractShape
Returns:
an array containing the Handles associated with the receiver

getLineColor

public java.awt.Color getLineColor()
Answer the Color to use when drawing lines.
Returns:
the Color to use when drawing lines

getLocator

public abstract Locator getLocator(int index)
Answer the indexth locator.
Specified by:
getLocator in interface LineFigure
Parameters:
index - the index of the locator desired.
Returns:
the Locator at the indexth position

getNumberOfPoints

public abstract int getNumberOfPoints()
Answer the number of points which define the receiver.
Specified by:
getNumberOfPoints in interface LineFigure
Returns:
an integer representing the number of points which define the receiver

getStyle

public DrawingStyle getStyle()
Answer the style which defines how to paint the figure.
Overrides:
getStyle in class AbstractFigure
Returns:
the DrawingStyle which defines how to paint the figure

insideSegment

protected boolean insideSegment(int x,
                                int y,
                                int x0,
                                int y0,
                                int x1,
                                int y1)
Answer whether the point specified is inside the specified line segment.
Parameters:
x - the x coordinate of the point being tested.
y - the y coordinate of the point being tested.
x0 - the x coordinate of the beginning of the line segment.
y0 - the y coordinate of the beginning of the line segment.
x1 - the x coordinate of the end of the line segment.
y2 - the y coordinate of the end of the line segment.
Returns:
boolean value of true if the point specified is inside the line segment specified; false otherwise.

insideTolerance

protected double insideTolerance()
Answer a number to define how close we have to be to the geometric line to be considered inside it.
Returns:
a double representing a number to define how close we have to be to be considered inside it

insideTolerance

protected double insideTolerance(double slope)
Answer a number to define how close we have to be to the geometric line to be considered inside it, given a particular slope.
Returns:
a double representing a number to define how close we have to the geometric line defined by the given slope in order to be considered inside it

intersects

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

locatorAt

public Locator locatorAt(int x,
                         int y)
Answers a locator corresponding to a significant point on the receiver. By default, answer a point with the same relative position as x and y are at the time of the request.
Overrides:
locatorAt in class AbstractFigure
Parameters:
x - the x coordinate of the requested locator
y - the y coordinate of the requested locator
Returns:
a Locator corresponding to a significant point on the receiver

paint

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

removeLocator

public void removeLocator(int index)
Remove the locator at the given position. This is a TemplateMethod with hooks: resetBoundsCache() basicRemoveLocator() changedShape()
Specified by:
removeLocator in interface LineFigure
Parameters:
index - the index of the locator to be removed.

requestConnection

public Locator requestConnection(Figure requestor,
                                 int x,
                                 int y)
Answers a Locator corresponding to a significant point on the receiver that will serve as a connection to the other figure. By default, make it the middle of the receiver. Subclasses may wish to do something more meaningful.
Overrides:
requestConnection in class AbstractFigure
Parameters:
x - the x coordinate of the requested locator
y - the y coordinate of the requested locator
Returns:
a Locator corresponding to a significant point on the receiver that will serve as a connection to the given figure

setLineColor

public void setLineColor(java.awt.Color color)
Set the Color to use when drawing lines.
Parameters:
color - the color

setLocator

public void setLocator(int index,
                       Locator locator)
Set the locator at the appropriate position. This is a TemplateMethod with hooks: resetBoundsCache() basicSetLocator() changedShape()
Specified by:
setLocator in interface LineFigure
Parameters:
index - the index of the locator desired.
locator - the new Locator.

setStyle

public void setStyle(DrawingStyle style)
Set the DrawingStyle defining how to paint the receuver.
Overrides:
setStyle in class AbstractFigure
Parameters:
style - the specified DrawingStyle.