Class BezierFigure
- java.lang.Object
-
- org.jhotdraw.beans.AbstractBean
-
- org.jhotdraw.draw.AbstractFigure
-
- org.jhotdraw.draw.AbstractAttributedFigure
-
- org.jhotdraw.draw.BezierFigure
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Figure, DOMStorable
- Direct Known Subclasses:
- LineFigure, ODGBezierFigure, SVGBezierFigure
public class BezierFigure extends AbstractAttributedFigure
AFigurewhich 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.
Design PatternsDecorator
The start and end point of aBezierFigurecan be decorated with a line decoration.
Component:BezierFigure; Decorator:LineDecoration.- See Also:
BezierPath, Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.jhotdraw.draw.Figure
CONNECTABLE_PROPERTY, REMOVABLE_PROPERTY, SELECTABLE_PROPERTY, TRANSFORMABLE_PROPERTY
-
-
Constructor Summary
Constructors Constructor and Description BezierFigure()Creates an emptyBezierFigure, for example without anyBezierPath.Nodes.BezierFigure(boolean isClosed)Creates an empty BezierFigure, for example without anyBezierPath.Nodes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddNode(BezierPath.Node p)Adds a control point.voidaddNode(int index, BezierPath.Node p)Adds a node to the list of points.java.awt.geom.Point2D.Doublechop(java.awt.geom.Point2D.Double p)BezierFigureclone()Returns a clone of the figure, with clones of all aggregated figures, such as children and decorators.booleancontains(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.ConnectorfindCompatibleConnector(Connector c, boolean isStart)Gets a compatible connector.ConnectorfindConnector(java.awt.geom.Point2D.Double p, ConnectionFigure prototype)Returns the Figures connector for the specified location.intfindNode(java.awt.geom.Point2D.Double p)Finds a control point index.intfindSegment(java.awt.geom.Point2D.Double find, double tolerance)Gets the segment of the polyline that is hit by the given Point2D.Double.BezierPathgetBezierPath()Returns a clone of the bezier path of this figure.java.awt.geom.Rectangle2D.DoublegetBounds()Returns the untransformed logical bounds of the figure as a Rectangle.java.awt.geom.Point2D.DoublegetCenter()java.awt.geom.Rectangle2D.DoublegetDrawingArea()Returns the drawing area of the figure as a Rectangle.java.awt.geom.Point2D.DoublegetEndPoint()Convenience method for getting the end point.BezierPath.NodegetNode(int index)Gets a control point.intgetNodeCount()Gets the node count.java.awt.geom.Point2D.DoublegetOutermostPoint()java.awt.geom.Point2D.DoublegetPoint(int index)Convenience method for getting the point coordinate of the first control point of the specified node.java.awt.geom.Point2D.DoublegetPoint(int index, int coord)Gets the point coordinate of a control point.java.awt.geom.Point2D.DoublegetPointOnPath(float relative, double flatness)java.awt.geom.Point2D.DoublegetStartPoint()Convenience method for getting the start point.java.lang.ObjectgetTransformRestoreData()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.booleanhandleMouseClick(java.awt.geom.Point2D.Double p, java.awt.event.MouseEvent evt, DrawingView view)Handles a mouse click.voidinvalidate()Invalidates cached data of the Figure.booleanisClosed()booleanjoinSegments(java.awt.geom.Point2D.Double join, double tolerance)Joins two segments into one if the given Point2D.Double hits a node of the polyline.intjoinSegments(java.awt.geom.Point2D.Double join, float tolerance)Joins two segments into one if the given Point2D.Double hits a node of the polyline.voidlayout()voidread(DOMInput in)BezierPath.NoderemoveNode(int index)Removes the Node at the specified index.voidrestoreTransformTo(java.lang.Object geometry)Restores the transform of the figure to a previously stored state.<T> voidset(AttributeKey<T> key, T newValue)Sets an attribute of the figure.voidsetBezierPath(BezierPath newValue)voidsetBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)Sets the location of the first and the lastBezierPath.Nodeof the BezierFigure.voidsetClosed(boolean newValue)voidsetEndPoint(java.awt.geom.Point2D.Double p)Convenience method for setting the point coordinate of the end point.voidsetNode(int index, BezierPath.Node p)Sets a control point.voidsetPoint(int index, int coord, java.awt.geom.Point2D.Double p)Sets the point coordinate of a control point.voidsetPoint(int index, java.awt.geom.Point2D.Double p)Sets the point coordinate of control point 0 at the specified node.voidsetStartPoint(java.awt.geom.Point2D.Double p)Convenience method for setting the point coordinate of the start point.intsplitSegment(java.awt.geom.Point2D.Double split, double tolerance)Splits the segment at the given Point2D.Double if a segment was hit.intsplitSegment(java.awt.geom.Point2D.Double split, float tolerance)Splits the segment at the given Point2D.Double if a segment was hit.voidtransform(java.awt.geom.AffineTransform tx)Transforms the shape of the Figure.voidwrite(DOMOutput out)-
Methods inherited from class org.jhotdraw.draw.AbstractAttributedFigure
draw, get, getAttributes, getAttributesRestoreData, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, removeAttribute, restoreAttributesTo, setAttributeEnabled, setAttributes
-
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, addNotify, changed, findFigureInside, fireAreaInvalidated, fireFigureChanged, getActions, getConnectors, getCursor, getDecomposition, getLayer, getPreferredSize, getTool, getToolTipText, handleDrop, includes, isConnectable, isRemovable, isSelectable, isTransformable, isVisible, remap, removeFigureListener, removeNotify, requestRemove, setBounds, setConnectable, setRemovable, setSelectable, setTransformable, setVisible, toString, willChange
-
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jhotdraw.draw.Figure
addPropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
BezierFigure
public BezierFigure()
Creates an emptyBezierFigure, for example without anyBezierPath.Nodes. The BezierFigure will not draw anything, if at least two nodes are added to it. TheBezierPathcreated by this constructor is not closed.
-
BezierFigure
public BezierFigure(boolean isClosed)
Creates an empty BezierFigure, for example without anyBezierPath.Nodes. The BezierFigure will not draw anything, unless at least two nodes are added to it.- Parameters:
isClosed- Specifies whether theBezierPathshall be closed.
-
-
Method Detail
-
findConnector
public Connector findConnector(java.awt.geom.Point2D.Double p, ConnectionFigure prototype)
Returns the Figures connector for the specified location. By default aChopBezierConnectoris returned.- Specified by:
findConnectorin interfaceFigure- Overrides:
findConnectorin classAbstractFigure- 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:
ChopRectangleConnector
-
findCompatibleConnector
public Connector findCompatibleConnector(Connector c, boolean isStart)
Description copied from interface:FigureGets 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. Returns null, if no compatible connector is available.- Specified by:
findCompatibleConnectorin interfaceFigure- Overrides:
findCompatibleConnectorin classAbstractFigure
-
contains
public boolean contains(java.awt.geom.Point2D.Double p)
Description copied from interface:FigureChecks if a point is contained by the figure.This is used for hit testing by Tool's.
-
createHandles
public java.util.Collection<Handle> createHandles(int detailLevel)
Description copied from interface:FigureCreates handles used to manipulate the figure.- Specified by:
createHandlesin interfaceFigure- Overrides:
createHandlesin classAbstractFigure- Parameters:
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.- Returns:
- a Collection of handles
- See Also:
Handle
-
getBounds
public java.awt.geom.Rectangle2D.Double getBounds()
Description copied from interface:FigureReturns the untransformed logical bounds of the figure as a Rectangle.The bounds are used by Handle objects for adjusting the figure and for aligning the figure on a grid.
-
getDrawingArea
public java.awt.geom.Rectangle2D.Double getDrawingArea()
Description copied from interface:FigureReturns the drawing area of the figure as a Rectangle.The drawing area is used to inform
DrawingViewabout 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.
- Specified by:
getDrawingAreain interfaceFigure- Overrides:
getDrawingAreain classAbstractAttributedFigure
-
getBezierPath
public BezierPath getBezierPath()
Returns a clone of the bezier path of this figure.
-
setBezierPath
public void setBezierPath(BezierPath newValue)
-
getPointOnPath
public java.awt.geom.Point2D.Double getPointOnPath(float relative, double flatness)
-
isClosed
public boolean isClosed()
-
setClosed
public void setClosed(boolean newValue)
-
set
public <T> void set(AttributeKey<T> key, T newValue)
Description copied from class:AbstractAttributedFigureSets an attribute of the figure. AttributeKey name and semantics are defined by the class implementing the figure interface.- Specified by:
setin interfaceFigure- Overrides:
setin classAbstractAttributedFigure- See Also:
AttributeKey.set(org.jhotdraw.draw.Figure, T)
-
setBounds
public void setBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)Sets the location of the first and the lastBezierPath.Nodeof 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.- Specified by:
setBoundsin interfaceFigure- Overrides:
setBoundsin classAbstractFigure- Parameters:
anchor- the start point of the boundslead- the end point of the bounds- See Also:
Figure.getBounds()
-
transform
public void transform(java.awt.geom.AffineTransform tx)
Description copied from interface:FigureTransforms the shape of the Figure. Transformations using double precision arithmethics are inherently lossy operations. Therefore it is recommended to use getTransformRestoreData() restoreTransformTo() to provide lossless undo/redo functionality.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();
- Parameters:
tx- The transformation.- See Also:
Figure.getTransformRestoreData(),Figure.restoreTransformTo(java.lang.Object)
-
invalidate
public void invalidate()
Description copied from class:AbstractFigureInvalidates cached data of the Figure. This method must execute fast, because it can be called very often.
-
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.
-
setNode
public void setNode(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, java.awt.geom.Point2D.Double p)Sets the point coordinate of control point 0 at the specified node.
-
setPoint
public void setPoint(int index, int coord, java.awt.geom.Point2D.Double p)Sets the point coordinate of a control point.
-
setStartPoint
public void setStartPoint(java.awt.geom.Point2D.Double p)
Convenience method for setting the point coordinate of the start point. If the BezierFigure has not at least two nodes, nodes are added to the figure until the BezierFigure has at least two nodes.
-
setEndPoint
public void setEndPoint(java.awt.geom.Point2D.Double p)
Convenience method for setting the point coordinate of the end point. If the BezierFigure has not at least two nodes, nodes are added to the figure until the BezierFigure has at least two nodes.
-
getStartPoint
public java.awt.geom.Point2D.Double getStartPoint()
Convenience method for getting the start point.- Specified by:
getStartPointin interfaceFigure- Overrides:
getStartPointin classAbstractFigure- See Also:
Figure.setBounds(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:
getEndPointin interfaceFigure- Overrides:
getEndPointin classAbstractFigure- See Also:
Figure.setBounds(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
-
findSegment
public int findSegment(java.awt.geom.Point2D.Double find, double tolerance)Gets the segment of the polyline that is hit by the given Point2D.Double.- Parameters:
find- a Point on the bezier pathtolerance- a tolerance, tolerance should take into account the line width, plus 2 divided by the zoom factor.- Returns:
- the index of the segment or -1 if no segment was hit.
-
joinSegments
public 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.- Parameters:
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.- Returns:
- true if the two segments were joined.
-
splitSegment
public int splitSegment(java.awt.geom.Point2D.Double split, double tolerance)Splits the segment at the given Point2D.Double if a segment was hit.- Parameters:
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.- Returns:
- the index of the segment or -1 if no segment was hit.
-
removeNode
public BezierPath.Node removeNode(int index)
Removes the Node at the specified index.
-
getNodeCount
public int getNodeCount()
Gets the node count.
-
clone
public BezierFigure clone()
Description copied from interface:FigureReturns a clone of the figure, with clones of all aggregated figures, such as children and decorators. The cloned figure does not clone the list of FigureListeners from its original.- Specified by:
clonein interfaceFigure- Overrides:
clonein classAbstractAttributedFigure
-
restoreTransformTo
public void restoreTransformTo(java.lang.Object geometry)
Description copied from interface:FigureRestores the transform of the figure to a previously stored state.
-
getTransformRestoreData
public java.lang.Object getTransformRestoreData()
Description copied from interface:FigureGets data which can be used to restore the transformation of the figure without loss of precision, after a transform has been applied to it.- See Also:
Figure.transform(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()
-
joinSegments
public 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.- Returns:
- true if the two segments were joined.
-
splitSegment
public int splitSegment(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:
handleMouseClickin interfaceFigure- Overrides:
handleMouseClickin classAbstractFigure- 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 event was consumed.
-
write
public void write(DOMOutput out) throws java.io.IOException
- Specified by:
writein interfaceDOMStorable- Overrides:
writein classAbstractAttributedFigure- Throws:
java.io.IOException
-
read
public void read(DOMInput in) throws java.io.IOException
- Specified by:
readin interfaceDOMStorable- Overrides:
readin classAbstractAttributedFigure- Throws:
java.io.IOException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG