public class BezierFigure extends AbstractAttributedFigure
Figure
which draws an opened or a closed bezier path.
A bezier figure can be used to draw arbitrary shapes using a
BezierPath
. It can be used to draw an open path or a closed shape.
A BezierFigure can have straight path segments and curved segments. A straight path segment can be added by clicking on the drawing area. Curved segments can be added by dragging the mouse pointer over the drawing area.
To creation of the BezierFigure can be finished by adding a segment which closes the path, or by double clicking on the drawing area, or by selecting a different tool in the DrawingEditor.
Decorator
The start and end point of a BezierFigure
can be decorated with
a line decoration.
Component: BezierFigure
;
Decorator: LineDecoration
.
BezierPath
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected BezierPath |
path
The BezierPath.
|
changingDepth, listenerList
propertySupport
CONNECTABLE_PROPERTY, REMOVABLE_PROPERTY, SELECTABLE_PROPERTY, TRANSFORMABLE_PROPERTY
Constructor and Description |
---|
BezierFigure()
Creates an empty
BezierFigure , for example without any
BezierPath.Node s. |
BezierFigure(boolean isClosed)
Creates an empty BezierFigure, for example without any
BezierPath.Node s. |
Modifier and Type | Method and Description |
---|---|
void |
addNode(BezierPath.Node p)
Adds a control point.
|
void |
addNode(int index,
BezierPath.Node p)
Adds a node to the list of points.
|
java.awt.geom.Point2D.Double |
chop(java.awt.geom.Point2D.Double p) |
BezierFigure |
clone()
Returns a clone of the figure, with clones of all aggregated figures,
such as children and decorators.
|
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,
double tolerance)
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 untransformed 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.Rectangle2D.Double |
getDrawingArea()
Returns the drawing area of the figure as a Rectangle.
|
java.awt.geom.Point2D.Double |
getEndPoint()
Convenience method for getting the end point.
|
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.
|
java.awt.geom.Point2D.Double |
getPointOnPath(float relative,
double flatness) |
java.awt.geom.Point2D.Double |
getStartPoint()
Convenience method for getting the start point.
|
java.lang.Object |
getTransformRestoreData()
Gets data which can be used to restore the transformation of the figure
without loss of precision, after a transform has been applied to it.
|
boolean |
handleMouseClick(java.awt.geom.Point2D.Double p,
java.awt.event.MouseEvent evt,
DrawingView view)
Handles a mouse click.
|
void |
invalidate()
Invalidates cached data of the Figure.
|
boolean |
isClosed() |
boolean |
joinSegments(java.awt.geom.Point2D.Double join,
double tolerance)
Joins two segments into one if the given Point2D.Double hits a node
of the polyline.
|
int |
joinSegments(java.awt.geom.Point2D.Double join,
float tolerance)
Joins two segments into one if the given Point2D.Double hits a node
of the polyline.
|
void |
layout() |
void |
read(DOMInput in) |
protected void |
readPoints(DOMInput in) |
protected void |
removeAllNodes()
Removes the Point2D.Double at the specified index.
|
BezierPath.Node |
removeNode(int index)
Removes the Node at the specified index.
|
void |
restoreTransformTo(java.lang.Object geometry)
Restores the transform of the figure to a previously stored state.
|
<T> void |
set(AttributeKey<T> key,
T newValue)
Sets an attribute of the figure.
|
void |
setBezierPath(BezierPath newValue) |
void |
setBounds(java.awt.geom.Point2D.Double anchor,
java.awt.geom.Point2D.Double lead)
Sets the location of the first and the last
BezierPath.Node
of the BezierFigure. |
void |
setClosed(boolean newValue) |
void |
setEndPoint(java.awt.geom.Point2D.Double p)
Convenience method for setting the point coordinate of the end point.
|
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.
|
void |
setPoint(int index,
java.awt.geom.Point2D.Double p)
Sets the point coordinate of control point 0 at the specified node.
|
void |
setStartPoint(java.awt.geom.Point2D.Double p)
Convenience method for setting the point coordinate of the start point.
|
int |
splitSegment(java.awt.geom.Point2D.Double split,
double tolerance)
Splits the segment at the given Point2D.Double if a segment was hit.
|
int |
splitSegment(java.awt.geom.Point2D.Double split,
float tolerance)
Splits the segment at the given Point2D.Double if a segment was hit.
|
void |
transform(java.awt.geom.AffineTransform tx)
Transforms the shape of the Figure.
|
protected void |
validate() |
void |
write(DOMOutput out) |
protected void |
writePoints(DOMOutput out) |
applyAttributesTo, draw, drawText, get, getAttributeKey, getAttributes, getAttributesRestoreData, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, readAttributes, removeAttribute, restoreAttributesTo, setAttributeEnabled, setAttributes, writeAttributes
addFigureListener, addNotify, changed, findFigureInside, fireAreaInvalidated, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureHandlesChanged, fireFigureRemoved, fireFigureRequestRemove, fireUndoableEditHappened, getActions, getChangingDepth, getConnectors, getCursor, getDecomposition, getDrawing, getFontRenderContext, getLayer, getLock, getPreferredSize, getTool, getToolTipText, handleDrop, includes, isChanging, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, remap, removeFigureListener, removeNotify, requestRemove, setBounds, setConnectable, setRemovable, setSelectable, setTransformable, setVisible, toString, willChange
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addPropertyChangeListener, removePropertyChangeListener
protected BezierPath path
public BezierFigure()
BezierFigure
, for example without any
BezierPath.Node
s.
The BezierFigure will not draw anything, if at least two nodes
are added to it. The BezierPath
created by this constructor
is not closed.public BezierFigure(boolean isClosed)
BezierPath.Node
s.
The BezierFigure will not draw anything, unless at least two nodes
are added to it.isClosed
- Specifies whether the BezierPath
shall
be closed.public Connector findConnector(java.awt.geom.Point2D.Double p, ConnectionFigure prototype)
ChopBezierConnector
is returned.findConnector
in interface Figure
findConnector
in class AbstractFigure
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.ChopRectangleConnector
public Connector findCompatibleConnector(Connector c, boolean isStart)
Figure
findCompatibleConnector
in interface Figure
findCompatibleConnector
in class AbstractFigure
protected void drawStroke(java.awt.Graphics2D g)
AbstractAttributedFigure
drawStroke
in class AbstractAttributedFigure
protected void drawCaps(java.awt.Graphics2D g)
protected void drawFill(java.awt.Graphics2D g)
AbstractAttributedFigure
drawFill
in class AbstractAttributedFigure
public boolean contains(java.awt.geom.Point2D.Double p)
Figure
This is used for hit testing by Tool's.
public java.util.Collection<Handle> createHandles(int detailLevel)
Figure
createHandles
in interface Figure
createHandles
in class AbstractFigure
detailLevel
- The detail level of the handles. Usually this is 0 for
bounding box handles and 1 for point handles. The value -1 is used
by the SelectAreaTracker and the HandleTracker to highlight figures, over which the mouse
pointer is hovering.Handle
public java.awt.geom.Rectangle2D.Double getBounds()
Figure
The bounds are used by Handle objects for adjusting the figure and for aligning the figure on a grid.
public java.awt.geom.Rectangle2D.Double getDrawingArea()
Figure
The drawing area is used to inform DrawingView
about the
area that is needed to draw this figure.
The drawing area needs to be large enough, to take line width, line caps and other decorations into account that exceed the bounds of the Figure.
getDrawingArea
in interface Figure
getDrawingArea
in class AbstractAttributedFigure
protected void validate()
validate
in class AbstractFigure
public BezierPath getBezierPath()
public void setBezierPath(BezierPath newValue)
public java.awt.geom.Point2D.Double getPointOnPath(float relative, double flatness)
public boolean isClosed()
public void setClosed(boolean newValue)
public <T> void set(AttributeKey<T> key, T newValue)
AbstractAttributedFigure
set
in interface Figure
set
in class AbstractAttributedFigure
AttributeKey.set(org.jhotdraw.draw.Figure, T)
public void setBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
BezierPath.Node
of the BezierFigure.
If the BezierFigure has not at least two nodes, nodes are added
to the figure until the BezierFigure has at least two nodes.setBounds
in interface Figure
setBounds
in class AbstractFigure
anchor
- the start point of the boundslead
- the end point of the boundsFigure.getBounds()
public void transform(java.awt.geom.AffineTransform tx)
Figure
This is a basic operation which does not fire events. Use the following code sequence, if you need event firing:
figure.willChange(); figure.transform(...); figure.changed();
tx
- The transformation.Figure.getTransformRestoreData()
,
Figure.restoreTransformTo(java.lang.Object)
public void invalidate()
AbstractFigure
invalidate
in class AbstractFigure
protected BezierPath getCappedPath()
public void layout()
public void addNode(BezierPath.Node p)
public void addNode(int index, BezierPath.Node p)
public void setNode(int index, BezierPath.Node p)
public BezierPath.Node getNode(int index)
public java.awt.geom.Point2D.Double getPoint(int index)
public java.awt.geom.Point2D.Double getPoint(int index, int coord)
public void setPoint(int index, java.awt.geom.Point2D.Double p)
public void setPoint(int index, int coord, java.awt.geom.Point2D.Double p)
public void setStartPoint(java.awt.geom.Point2D.Double p)
public void setEndPoint(java.awt.geom.Point2D.Double p)
public java.awt.geom.Point2D.Double getStartPoint()
getStartPoint
in interface Figure
getStartPoint
in class AbstractFigure
Figure.setBounds(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double)
public java.awt.geom.Point2D.Double getEndPoint()
getEndPoint
in interface Figure
getEndPoint
in class AbstractFigure
Figure.setBounds(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double)
public int findNode(java.awt.geom.Point2D.Double p)
public int findSegment(java.awt.geom.Point2D.Double find, double tolerance)
find
- a Point on the bezier pathtolerance
- a tolerance, tolerance should take into account
the line width, plus 2 divided by the zoom factor.public boolean joinSegments(java.awt.geom.Point2D.Double join, double tolerance)
join
- a Point at a node on the bezier pathtolerance
- a tolerance, tolerance should take into account
the line width, plus 2 divided by the zoom factor.public int splitSegment(java.awt.geom.Point2D.Double split, double tolerance)
split
- a Point on (or near) a line segment on the bezier pathtolerance
- a tolerance, tolerance should take into account
the line width, plus 2 divided by the zoom factor.public BezierPath.Node removeNode(int index)
protected void removeAllNodes()
public int getNodeCount()
public BezierFigure clone()
Figure
clone
in interface Figure
clone
in class AbstractAttributedFigure
public void restoreTransformTo(java.lang.Object geometry)
Figure
public java.lang.Object getTransformRestoreData()
Figure
Figure.transform(AffineTransform)
public java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double p)
public java.awt.geom.Point2D.Double getCenter()
public java.awt.geom.Point2D.Double getOutermostPoint()
public int joinSegments(java.awt.geom.Point2D.Double join, float tolerance)
public int splitSegment(java.awt.geom.Point2D.Double split, float tolerance)
public boolean handleMouseClick(java.awt.geom.Point2D.Double p, java.awt.event.MouseEvent evt, DrawingView view)
handleMouseClick
in interface Figure
handleMouseClick
in class AbstractFigure
p
- The location of the mouse event.evt
- The mouse event.view
- The drawing view which is the source of the mouse event.public void write(DOMOutput out) throws java.io.IOException
write
in interface DOMStorable
write
in class AbstractAttributedFigure
java.io.IOException
protected void writePoints(DOMOutput out) throws java.io.IOException
java.io.IOException
public void read(DOMInput in) throws java.io.IOException
read
in interface DOMStorable
read
in class AbstractAttributedFigure
java.io.IOException
protected void readPoints(DOMInput in) throws java.io.IOException
java.io.IOException