JHotDraw 7.0.6

org.jhotdraw.draw
Class BezierFigure

java.lang.Object
  extended by org.jhotdraw.draw.AbstractFigure
      extended by org.jhotdraw.draw.AttributedFigure
          extended by org.jhotdraw.draw.BezierFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Figure, DOMStorable
Direct Known Subclasses:
LineFigure

public class BezierFigure
extends AttributedFigure

A BezierFigure can be used to draw arbitrary shapes using a BezierPath. It can be used to draw an open path or a closed shape.

See Also:
Serialized Form

Field Summary
static AttributeKey<java.lang.Boolean> CLOSED
           
protected  BezierPath path
          The BezierPath.
 
Fields inherited from class org.jhotdraw.draw.AbstractFigure
changingDepth, decorator, listenerList
 
Constructor Summary
BezierFigure()
          Creates a new instance.
BezierFigure(boolean isClosed)
          Creates a new instance.
 
Method Summary
 void addNode(BezierPath.Node p)
          Adds a control point.
 void addNode(int index, BezierPath.Node p)
          Adds a node to the list of points.
 void basicAddNode(BezierPath.Node p)
          Adds a control point.
 void basicAddNode(int index, BezierPath.Node p)
          Adds a control point.
 boolean basicJoinSegments(java.awt.geom.Point2D.Double join)
          Joins two segments into one if the given Point2D.Double hits a node of the polyline.
 int basicJoinSegments(java.awt.geom.Point2D.Double join, float tolerance)
          Joins two segments into one if the given Point2D.Double hits a node of the polyline.
protected  void basicRemoveAllNodes()
          Removes the Point2D.Double at the specified index.
protected  void basicRemoveNode(int index)
          Removes the Point2D.Double at the specified index.
 void basicSetAttribute(AttributeKey key, java.lang.Object newValue)
          Sets an attribute of the figure.
 void basicSetBezierPath(BezierPath newValue)
          Sets the bezier path, without cloning and without firing events.
 void basicSetBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
          Sets the logical bounds of the figure and of its decorator figure.
 void basicSetEndPoint(java.awt.geom.Point2D.Double p)
          Convenience method for setting the point coordinate of the end point.
 void basicSetNode(int index, BezierPath.Node p)
          Sets a control point.
 void basicSetPoint(int index, int coord, java.awt.geom.Point2D.Double p)
          Sets the point coordinate of a control point.
 void basicSetPoint(int index, java.awt.geom.Point2D.Double p)
          Sets the point coordinate of control point 0 at the specified node.
 void basicSetStartPoint(java.awt.geom.Point2D.Double p)
          Convenience method for setting the point coordinate of the start point.
 int basicSplitSegment(java.awt.geom.Point2D.Double split)
          Splits the segment at the given Point2D.Double if a segment was hit.
 int basicSplitSegment(java.awt.geom.Point2D.Double split, float tolerance)
          Splits the segment at the given Point2D.Double if a segment was hit.
 void basicTransform(java.awt.geom.AffineTransform tx)
          Moves the figure.
 boolean canConnect()
          Checks if this figure can be connected.
 java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double p)
           
 BezierFigure clone()
          Returns a clone of the figure.
 boolean contains(java.awt.geom.Point2D.Double p)
          Checks if a point is contained by the figure.
 java.util.Collection<Handle> createHandles(int detailLevel)
          Creates handles used to manipulate the figure.
protected  void drawCaps(java.awt.Graphics2D g)
           
protected  void drawFill(java.awt.Graphics2D g)
          This method is called by method draw() to draw the fill area of the figure.
protected  void drawStroke(java.awt.Graphics2D g)
          This method is called by method draw() to draw the text of the figure .
 Connector findCompatibleConnector(Connector c, boolean isStart)
          Gets a compatible connector.
 Connector findConnector(java.awt.geom.Point2D.Double p, ConnectionFigure prototype)
          Returns the Figures connector for the specified location.
 int findNode(java.awt.geom.Point2D.Double p)
          Finds a control point index.
 int findSegment(java.awt.geom.Point2D.Double find)
          Gets the segment of the polyline that is hit by the given Point2D.Double.
 BezierPath getBezierPath()
          Returns a clone of the bezier path of this figure.
 java.awt.geom.Rectangle2D.Double getBounds()
          Returns the logical bounds of the figure as a Rectangle.
protected  BezierPath getCappedPath()
          Returns a path which is cappedPath at the ends, to prevent it from drawing under the end caps.
 java.awt.geom.Point2D.Double getCenter()
           
 java.awt.geom.Point2D.Double getEndPoint()
          Convenience method for getting the end point.
 java.awt.geom.Rectangle2D.Double getFigureDrawBounds()
           
 BezierPath.Node getNode(int index)
          Gets a control point.
 int getNodeCount()
          Gets the node count.
 java.awt.geom.Point2D.Double getOutermostPoint()
           
 java.awt.geom.Point2D.Double getPoint(int index)
          Convenience method for getting the point coordinate of the first control point of the specified node.
 java.awt.geom.Point2D.Double getPoint(int index, int coord)
          Gets the point coordinate of a control point.
 int getPointCount()
          Gets the point count.
 java.awt.geom.Point2D.Double getPointOnPath(float relative, double flatness)
           
 java.lang.Object getRestoreData()
          Gets data which can be used to restore the shape of the figure after a basicTransform has been applied to it.
 java.awt.geom.Point2D.Double getStartPoint()
          Convenience method for getting the start point.
 boolean handleMouseClick(java.awt.geom.Point2D.Double p, java.awt.event.MouseEvent evt, DrawingView view)
          Handles a mouse click.
 void invalidate()
          Informs that a figure needs to be redrawn.
protected  void invalidateCappedPath()
           
 boolean isClosed()
           
 void layout()
           
 void read(DOMInput in)
           
protected  void readPoints(DOMInput in)
           
 void removeAllNodes()
          Removes all points.
 void removeNode(int index)
          Removes the Point2D.Double at the specified index.
 void restoreTo(java.lang.Object geometry)
          Restores the shape of the figure to a previously stored state.
 void setClosed(boolean newValue)
           
 void setNode(int index, BezierPath.Node p)
          Sets a control point.
 void setPoint(int index, int coord, java.awt.geom.Point2D.Double p)
          Sets the point coordinate of a control point.
protected  void validate()
           
 void write(DOMOutput out)
           
protected  void writePoints(DOMOutput out)
           
 
Methods inherited from class org.jhotdraw.draw.AttributedFigure
applyAttributesTo, drawConnectors, drawFigure, drawText, getAttribute, getAttributeKey, getAttributes, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, readAttributes, removeAttribute, setAttribute, setAttributeEnabled, setAttributes, writeAttributes
 
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, addNotify, addUndoableEditListener, basicClone, changed, draw, drawDecorator, findFigureInside, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureRemoved, fireFigureRequestRemove, fireUndoableEditHappened, getActions, getChangingDepth, getCourtingConnection, getCursor, getDecomposition, getDecorator, getDrawBounds, getDrawing, getFontRenderContext, getLayer, getLock, getPreferredSize, getTool, getTooltip, handleDrop, includes, isChanging, isConnectorsVisible, isDrawDecoratorFirst, isInteractive, isVisible, remap, remap, removeFigureListener, removeNotify, removeUndoableEditListener, requestRemove, setBounds, setBounds, setConnectorsVisible, setDecorator, setDrawDecoratorFirst, setInteractive, setVisible, toString, transform, updateDecoratorBounds, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLOSED

public static final AttributeKey<java.lang.Boolean> CLOSED

path

protected BezierPath path
The BezierPath.

Constructor Detail

BezierFigure

public BezierFigure()
Creates a new instance.


BezierFigure

public BezierFigure(boolean isClosed)
Creates a new instance.

Method Detail

findConnector

public Connector findConnector(java.awt.geom.Point2D.Double p,
                               ConnectionFigure prototype)
Returns the Figures connector for the specified location. By default a ChopDiamondConnector is returned.

Specified by:
findConnector in interface Figure
Overrides:
findConnector in class AbstractFigure
Parameters:
p - the location of the connector.
prototype - The prototype used to create a connection or null if unknown. This allows for specific connectors for different connection figures.
See Also:
ChopDiamondConnector

findCompatibleConnector

public Connector findCompatibleConnector(Connector c,
                                         boolean isStart)
Description copied from interface: Figure
Gets a compatible connector. If the provided connector is part of this figure, return the connector. If the provided connector is part of another figure, return a connector with the same semantics for this figure. Return null, if no compatible connector is available.

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

drawStroke

protected void drawStroke(java.awt.Graphics2D g)
Description copied from class: AttributedFigure
This method is called by method draw() to draw the text of the figure . AttributedFigure configures the Graphics2D object with the TEXT_COLOR attribute before calling this method. If the TEXT_COLOR attribute is null, this method is not called.

Specified by:
drawStroke in class AttributedFigure

drawCaps

protected void drawCaps(java.awt.Graphics2D g)

drawFill

protected void drawFill(java.awt.Graphics2D g)
Description copied from class: AttributedFigure
This method is called by method draw() to draw the fill area of the figure. AttributedFigure configures the Graphics2D object with the FILL_COLOR attribute before calling this method. If the FILL_COLOR attribute is null, this method is not called.

Specified by:
drawFill in class AttributedFigure

contains

public boolean contains(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Checks if a point is contained by the figure.

This is used for hit testing by Tool's.


canConnect

public boolean canConnect()
Checks if this figure can be connected. By default filled BezierFigures can be connected.

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

createHandles

public java.util.Collection<Handle> createHandles(int detailLevel)
Description copied from interface: Figure
Creates handles used to manipulate the figure.

Specified by:
createHandles in interface Figure
Overrides:
createHandles in class AbstractFigure
Parameters:
detailLevel - The detail level of the handles. Usually this is 0 for bounding box handles and 1 for point handles.
Returns:
a Collection of handles
See Also:
Handle

getBounds

public java.awt.geom.Rectangle2D.Double getBounds()
Description copied from interface: Figure
Returns the logical bounds of the figure as a Rectangle. The logical bounds are used by some Handle objects for adjusting the figure.


getFigureDrawBounds

public java.awt.geom.Rectangle2D.Double getFigureDrawBounds()
Overrides:
getFigureDrawBounds in class AttributedFigure

validate

protected void validate()
Overrides:
validate in class AbstractFigure

getBezierPath

public BezierPath getBezierPath()
Returns a clone of the bezier path of this figure.


getPointOnPath

public java.awt.geom.Point2D.Double getPointOnPath(float relative,
                                                   double flatness)

basicSetBezierPath

public void basicSetBezierPath(BezierPath newValue)
Sets the bezier path, without cloning and without firing events.


isClosed

public boolean isClosed()

setClosed

public void setClosed(boolean newValue)

basicSetAttribute

public void basicSetAttribute(AttributeKey key,
                              java.lang.Object newValue)
Description copied from class: AttributedFigure
Sets an attribute of the figure. AttributeKey name and semantics are defined by the class implementing the figure interface.

Specified by:
basicSetAttribute in interface Figure
Overrides:
basicSetAttribute in class AttributedFigure
See Also:
AttributeKey.set(org.jhotdraw.draw.Figure, T)

basicSetBounds

public void basicSetBounds(java.awt.geom.Point2D.Double anchor,
                           java.awt.geom.Point2D.Double lead)
Description copied from interface: Figure
Sets the logical bounds of the figure and of its decorator figure.

This is used by Tool's which create a new Figure and by Tool's which connect a Figure to another Figure.

This is a basic operation which does not fire events.

Parameters:
anchor - the start point of the bounds
lead - the end point of the bounds
See Also:
Figure.getBounds()

basicTransform

public void basicTransform(java.awt.geom.AffineTransform tx)
Description copied from class: AbstractFigure
Moves the figure. This is the method that subclasses override.

This is a basic operation for which no events are fired.

Specified by:
basicTransform in interface Figure
Specified by:
basicTransform in class AbstractFigure
Parameters:
tx - The transformation.

invalidate

public void invalidate()
Description copied from class: AbstractFigure
Informs that a figure needs to be redrawn.

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

invalidateCappedPath

protected void invalidateCappedPath()

getCappedPath

protected BezierPath getCappedPath()
Returns a path which is cappedPath at the ends, to prevent it from drawing under the end caps.


layout

public void layout()

addNode

public void addNode(BezierPath.Node p)
Adds a control point.


addNode

public void addNode(int index,
                    BezierPath.Node p)
Adds a node to the list of points.


basicAddNode

public void basicAddNode(BezierPath.Node p)
Adds a control point.


basicAddNode

public void basicAddNode(int index,
                         BezierPath.Node p)
Adds a control point.


setNode

public void setNode(int index,
                    BezierPath.Node p)
Sets a control point.


basicSetNode

public void basicSetNode(int index,
                         BezierPath.Node p)
Sets a control point.


getNode

public BezierPath.Node getNode(int index)
Gets a control point.


getPoint

public java.awt.geom.Point2D.Double getPoint(int index)
Convenience method for getting the point coordinate of the first control point of the specified node.


getPoint

public java.awt.geom.Point2D.Double getPoint(int index,
                                             int coord)
Gets the point coordinate of a control point.


setPoint

public void setPoint(int index,
                     int coord,
                     java.awt.geom.Point2D.Double p)
Sets the point coordinate of a control point.


basicSetPoint

public void basicSetPoint(int index,
                          java.awt.geom.Point2D.Double p)
Sets the point coordinate of control point 0 at the specified node.


basicSetPoint

public void basicSetPoint(int index,
                          int coord,
                          java.awt.geom.Point2D.Double p)
Sets the point coordinate of a control point.


basicSetStartPoint

public void basicSetStartPoint(java.awt.geom.Point2D.Double p)
Convenience method for setting the point coordinate of the start point.


basicSetEndPoint

public void basicSetEndPoint(java.awt.geom.Point2D.Double p)
Convenience method for setting the point coordinate of the end point.


getStartPoint

public java.awt.geom.Point2D.Double getStartPoint()
Convenience method for getting the start point.

Specified by:
getStartPoint in interface Figure
Overrides:
getStartPoint in class AbstractFigure
See Also:
Figure.basicSetBounds(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double)

getEndPoint

public java.awt.geom.Point2D.Double getEndPoint()
Convenience method for getting the end point.

Specified by:
getEndPoint in interface Figure
Overrides:
getEndPoint in class AbstractFigure
See Also:
Figure.basicSetBounds(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double)

findNode

public int findNode(java.awt.geom.Point2D.Double p)
Finds a control point index. Returns -1 if no control point could be found. FIXME - Move this to BezierPath


removeAllNodes

public final void removeAllNodes()
Removes all points.


removeNode

public final void removeNode(int index)
Removes the Point2D.Double at the specified index.


findSegment

public int findSegment(java.awt.geom.Point2D.Double find)
Gets the segment of the polyline that is hit by the given Point2D.Double.

Returns:
the index of the segment or -1 if no segment was hit. XXX - Move this to BezierPath

basicJoinSegments

public boolean basicJoinSegments(java.awt.geom.Point2D.Double join)
Joins two segments into one if the given Point2D.Double hits a node of the polyline.

Returns:
true if the two segments were joined. XXX - Move this to BezierPath

basicSplitSegment

public int basicSplitSegment(java.awt.geom.Point2D.Double split)
Splits the segment at the given Point2D.Double if a segment was hit.

Returns:
the index of the segment or -1 if no segment was hit. XXX - Move this to BezierPath

basicRemoveNode

protected void basicRemoveNode(int index)
Removes the Point2D.Double at the specified index.


basicRemoveAllNodes

protected void basicRemoveAllNodes()
Removes the Point2D.Double at the specified index.


getNodeCount

public int getNodeCount()
Gets the node count.


getPointCount

public int getPointCount()
Gets the point count.


clone

public BezierFigure clone()
Description copied from interface: Figure
Returns a clone of the figure.

Specified by:
clone in interface Figure
Overrides:
clone in class AttributedFigure

restoreTo

public void restoreTo(java.lang.Object geometry)
Description copied from interface: Figure
Restores the shape of the figure to a previously stored state.


getRestoreData

public java.lang.Object getRestoreData()
Description copied from interface: Figure
Gets data which can be used to restore the shape of the figure after a basicTransform has been applied to it.

See Also:
Figure.basicTransform(AffineTransform)

chop

public java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double p)

getCenter

public java.awt.geom.Point2D.Double getCenter()

getOutermostPoint

public java.awt.geom.Point2D.Double getOutermostPoint()

basicJoinSegments

public int basicJoinSegments(java.awt.geom.Point2D.Double join,
                             float tolerance)
Joins two segments into one if the given Point2D.Double hits a node of the polyline.

Returns:
true if the two segments were joined.

basicSplitSegment

public int basicSplitSegment(java.awt.geom.Point2D.Double split,
                             float tolerance)
Splits the segment at the given Point2D.Double if a segment was hit.

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

handleMouseClick

public boolean handleMouseClick(java.awt.geom.Point2D.Double p,
                                java.awt.event.MouseEvent evt,
                                DrawingView view)
Handles a mouse click.

Specified by:
handleMouseClick in interface Figure
Overrides:
handleMouseClick in class AbstractFigure
Parameters:
p - The location of the mouse event.
evt - The mouse event.
view - The drawing view which is the source of the mouse event.
Returns:
Returns true, if the figure consumed the mouse click.

write

public void write(DOMOutput out)
           throws java.io.IOException
Specified by:
write in interface DOMStorable
Overrides:
write in class AttributedFigure
Throws:
java.io.IOException

writePoints

protected void writePoints(DOMOutput out)
                    throws java.io.IOException
Throws:
java.io.IOException

read

public void read(DOMInput in)
          throws java.io.IOException
Specified by:
read in interface DOMStorable
Overrides:
read in class AttributedFigure
Throws:
java.io.IOException

readPoints

protected void readPoints(DOMInput in)
                   throws java.io.IOException
Throws:
java.io.IOException

Copyright 1996-2006 © JHotDraw.org