JHotDraw 6.0b1

org.jhotdraw.figures
Class PolyLineFigure

java.lang.Object
  extended by org.jhotdraw.standard.AbstractFigure
      extended by org.jhotdraw.figures.PolyLineFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Figure, Storable
Direct Known Subclasses:
LineConnection, LineFigure

public class PolyLineFigure
extends AbstractFigure

A poly line figure consists of a list of points. It has an optional line decoration at the start and end.

See Also:
LineDecoration, Serialized Form

Field Summary
static int ARROW_TIP_BOTH
           
static int ARROW_TIP_END
           
static int ARROW_TIP_NONE
           
static int ARROW_TIP_START
           
protected  LineDecoration fEndDecoration
           
protected  java.awt.Color fFrameColor
           
protected  java.util.List fPoints
           
protected  LineDecoration fStartDecoration
           
 
Constructor Summary
PolyLineFigure()
           
PolyLineFigure(int size)
           
PolyLineFigure(int x, int y)
           
 
Method Summary
 void addPoint(int x, int y)
          Adds a node to the list of points.
 void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
          Sets the display box of a figure.
protected  void basicMoveBy(int dx, int dy)
          Moves the figure.
 Connector connectorAt(int x, int y)
          Returns the Figures connector for the specified location.
 boolean containsPoint(int x, int y)
          Checks if a point is inside the figure.
 java.awt.Rectangle displayBox()
          Gets the display box of a figure.
 void draw(java.awt.Graphics g)
          Draws the figure.
protected  void drawLine(java.awt.Graphics g, int x1, int y1, int x2, int y2)
          Can be overriden in subclasses to draw different types of lines (e.g.
 int findSegment(int x, int y)
          Gets the segment of the polyline that is hit by the given point.
 java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
          Gets the attribute with the given name.
 java.lang.Object getAttribute(java.lang.String name)
          Deprecated. use getAttribute(FigureAttributeConstant) instead
 LineDecoration getEndDecoration()
          Returns the end decoration.
protected  java.awt.Color getFrameColor()
           
 LineDecoration getStartDecoration()
          Returns the start decoration.
 HandleEnumeration handles()
          Returns the handles of a Figure that can be used to manipulate some of its attributes.
 void insertPointAt(java.awt.Point p, int i)
          Insert a node at the given point.
protected  java.awt.Rectangle invalidateRectangle(java.awt.Rectangle r)
          Hook method to change the rectangle that will be invalidated
 boolean isEmpty()
          Checks if the figure is empty.
 boolean joinSegments(int x, int y)
          Joins to segments into one if the given point hits a node of the polyline.
static Locator locator(int pointIndex)
          Creates a locator for the point with the given index.
 java.awt.Point pointAt(int i)
           
 int pointCount()
           
 java.util.Iterator points()
           
 void read(StorableInput dr)
          Reads the Figure from a StorableInput.
 void removePointAt(int i)
           
 void setAttribute(FigureAttributeConstant attributeConstant, java.lang.Object value)
          Sets the attribute with the given name.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Deprecated. use setAttribute(FigureAttributeConstant, Object) instead
 void setEndDecoration(LineDecoration l)
          Sets the end decoration.
protected  void setFrameColor(java.awt.Color c)
           
 void setPointAt(java.awt.Point p, int i)
          Changes the position of a node.
 void setStartDecoration(LineDecoration l)
          Sets the start decoration.
 int splitSegment(int x, int y)
          Splits the segment at the given point if a segment was hit.
 void write(StorableOutput dw)
          Stores the Figure to a StorableOutput.
 
Methods inherited from class org.jhotdraw.standard.AbstractFigure
addDependendFigure, addFigureChangeListener, addToContainer, canConnect, center, changed, clone, connectedTextLocator, connectionInsets, connectorVisibility, decompose, displayBox, displayBox, figures, findFigureInside, getDecoratedFigure, getDependendFigures, getTextHolder, getZValue, includes, invalidate, listener, moveBy, release, removeDependendFigure, removeFigureChangeListener, removeFromContainer, setZValue, size, visit, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARROW_TIP_NONE

public static final int ARROW_TIP_NONE
See Also:
Constant Field Values

ARROW_TIP_START

public static final int ARROW_TIP_START
See Also:
Constant Field Values

ARROW_TIP_END

public static final int ARROW_TIP_END
See Also:
Constant Field Values

ARROW_TIP_BOTH

public static final int ARROW_TIP_BOTH
See Also:
Constant Field Values

fPoints

protected java.util.List fPoints

fStartDecoration

protected LineDecoration fStartDecoration

fEndDecoration

protected LineDecoration fEndDecoration

fFrameColor

protected java.awt.Color fFrameColor
Constructor Detail

PolyLineFigure

public PolyLineFigure()

PolyLineFigure

public PolyLineFigure(int size)

PolyLineFigure

public PolyLineFigure(int x,
                      int y)
Method Detail

displayBox

public java.awt.Rectangle displayBox()
Description copied from class: AbstractFigure
Gets the display box of a figure.

Specified by:
displayBox in interface Figure
Specified by:
displayBox in class AbstractFigure
See Also:
Figure.basicDisplayBox(java.awt.Point, java.awt.Point)

isEmpty

public boolean isEmpty()
Description copied from class: AbstractFigure
Checks if the figure is empty. The default implementation returns true if the width or height of its display box is < 3

Specified by:
isEmpty in interface Figure
Overrides:
isEmpty in class AbstractFigure
See Also:
Figure.isEmpty()

handles

public HandleEnumeration handles()
Description copied from class: AbstractFigure
Returns the handles of a Figure that can be used to manipulate some of its attributes.

Specified by:
handles in interface Figure
Specified by:
handles in class AbstractFigure
Returns:
a type-safe iterator of handles
See Also:
Handle

basicDisplayBox

public void basicDisplayBox(java.awt.Point origin,
                            java.awt.Point corner)
Description copied from class: AbstractFigure
Sets the display box of a figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicDisplayBox in interface Figure
Specified by:
basicDisplayBox in class AbstractFigure
Parameters:
origin - the new origin
corner - the new corner
See Also:
AbstractFigure.displayBox(java.awt.Point, java.awt.Point)

addPoint

public void addPoint(int x,
                     int y)
Adds a node to the list of points.


points

public java.util.Iterator points()

pointCount

public int pointCount()

basicMoveBy

protected void basicMoveBy(int dx,
                           int dy)
Description copied from class: AbstractFigure
Moves the figure. This is the method that subclassers override. Clients usually call displayBox.

Specified by:
basicMoveBy in class AbstractFigure
See Also:
AbstractFigure.moveBy(int, int)

setPointAt

public void setPointAt(java.awt.Point p,
                       int i)
Changes the position of a node.


insertPointAt

public void insertPointAt(java.awt.Point p,
                          int i)
Insert a node at the given point.


removePointAt

public void removePointAt(int i)

splitSegment

public int splitSegment(int x,
                        int y)
Splits the segment at the given point if a segment was hit.

Returns:
the index of the segment or -1 if no segment was hit.

pointAt

public java.awt.Point pointAt(int i)

joinSegments

public boolean joinSegments(int x,
                            int y)
Joins to segments into one if the given point hits a node of the polyline.

Returns:
true if the two segments were joined.

connectorAt

public Connector connectorAt(int x,
                             int y)
Description copied from class: AbstractFigure
Returns the Figures connector for the specified location. By default a ChopBoxConnector is returned.

Specified by:
connectorAt in interface Figure
Overrides:
connectorAt in class AbstractFigure
See Also:
ChopBoxConnector

setStartDecoration

public void setStartDecoration(LineDecoration l)
Sets the start decoration.


getStartDecoration

public LineDecoration getStartDecoration()
Returns the start decoration.


setEndDecoration

public void setEndDecoration(LineDecoration l)
Sets the end decoration.


getEndDecoration

public LineDecoration getEndDecoration()
Returns the end decoration.


draw

public void draw(java.awt.Graphics g)
Description copied from interface: Figure
Draws the figure.

Parameters:
g - the Graphics to draw into

drawLine

protected void drawLine(java.awt.Graphics g,
                        int x1,
                        int y1,
                        int x2,
                        int y2)
Can be overriden in subclasses to draw different types of lines (e.g. dotted lines)


containsPoint

public boolean containsPoint(int x,
                             int y)
Description copied from class: AbstractFigure
Checks if a point is inside the figure.

Specified by:
containsPoint in interface Figure
Overrides:
containsPoint in class AbstractFigure

findSegment

public int findSegment(int x,
                       int y)
Gets the segment of the polyline that is hit by the given point.

Returns:
the index of the segment or -1 if no segment was hit.

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Deprecated. use getAttribute(FigureAttributeConstant) instead

Gets the attribute with the given name. PolyLineFigure maps "ArrowMode"to a line decoration.

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AbstractFigure

getAttribute

public java.lang.Object getAttribute(FigureAttributeConstant attributeConstant)
Gets the attribute with the given name. PolyLineFigure maps "ArrowMode"to a line decoration.

Specified by:
getAttribute in interface Figure
Overrides:
getAttribute in class AbstractFigure

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Deprecated. use setAttribute(FigureAttributeConstant, Object) instead

Sets the attribute with the given name. PolyLineFigure interprets "ArrowMode"to set the line decoration.

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AbstractFigure

setAttribute

public void setAttribute(FigureAttributeConstant attributeConstant,
                         java.lang.Object value)
Sets the attribute with the given name. PolyLineFigure interprets "ArrowMode"to set the line decoration.

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class AbstractFigure

write

public void write(StorableOutput dw)
Description copied from class: AbstractFigure
Stores the Figure to a StorableOutput.

Specified by:
write in interface Storable
Overrides:
write in class AbstractFigure

read

public void read(StorableInput dr)
          throws java.io.IOException
Description copied from class: AbstractFigure
Reads the Figure from a StorableInput.

Specified by:
read in interface Storable
Overrides:
read in class AbstractFigure
Throws:
java.io.IOException

locator

public static Locator locator(int pointIndex)
Creates a locator for the point with the given index.


getFrameColor

protected java.awt.Color getFrameColor()

setFrameColor

protected void setFrameColor(java.awt.Color c)

invalidateRectangle

protected java.awt.Rectangle invalidateRectangle(java.awt.Rectangle r)
Hook method to change the rectangle that will be invalidated

Overrides:
invalidateRectangle in class AbstractFigure

JHotDraw 6.0b1