Documentation of 'org.jhotdraw.draw.BezierFigure' Java class
BezierFigure
org.jhotdraw.draw

Class BezierFigure

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Figure, DOMStorable
    Direct Known Subclasses:
    LineFigure, ODGBezierFigure, SVGBezierFigure


    public class BezierFigure
    extends AbstractAttributedFigure
    A 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.


    Design Patterns

    Decorator
    The start and end point of a BezierFigure can be decorated with a line decoration.
    Component: BezierFigure; Decorator: LineDecoration.


    See Also:
    BezierPath, Serialized Form
    • Constructor Detail

      • BezierFigure

        public BezierFigure()
        Creates an empty BezierFigure, for example without any BezierPath.Nodes. The BezierFigure will not draw anything, if at least two nodes are added to it. The BezierPath created by this constructor is not closed.
      • BezierFigure

        public BezierFigure(boolean isClosed)
        Creates an empty BezierFigure, for example without any BezierPath.Nodes. The BezierFigure will not draw anything, unless at least two nodes are added to it.
        Parameters:
        isClosed - Specifies whether the BezierPath shall be closed.
    • Method Detail

      • 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. Returns null, if no compatible connector is available.
        Specified by:
        findCompatibleConnector in interface Figure
        Overrides:
        findCompatibleConnector in class AbstractFigure
      • 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.

      • 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. 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: Figure
        Returns 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: Figure
        Returns the drawing area of the figure as a Rectangle.

        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.

        Specified by:
        getDrawingArea in interface Figure
        Overrides:
        getDrawingArea in class AbstractAttributedFigure
      • 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)
      • setBounds

        public 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. 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:
        setBounds in interface Figure
        Overrides:
        setBounds in class AbstractFigure
        Parameters:
        anchor - the start point of the bounds
        lead - the end point of the bounds
        See Also:
        Figure.getBounds()
      • transform

        public void transform(java.awt.geom.AffineTransform tx)
        Description copied from interface: Figure
        Transforms 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: AbstractFigure
        Invalidates 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(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.
      • 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 path
        tolerance - 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 path
        tolerance - 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 path
        tolerance - 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: Figure
        Returns 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:
        clone in interface Figure
        Overrides:
        clone in class AbstractAttributedFigure
      • restoreTransformTo

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

        public java.lang.Object getTransformRestoreData()
        Description copied from interface: Figure
        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.
        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:
        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 event was consumed.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.