Package diva.canvas

Class AbstractFigure

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractFigure()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(java.awt.geom.Point2D p)
      Test whether this figure contains the point given.
      java.awt.geom.Rectangle2D getBounds()
      Get the bounding box of this figure.
      Interactor getInteractor()
      Return the interactor of this figure.
      CanvasLayer getLayer()
      Get the most immediate layer containing this figure.
      java.awt.geom.Point2D getOrigin()
      Return the origin of the figure in the enclosing transform context, which in this base class is the center of the bounds returned by getBounds().
      CanvasComponent getParent()
      Return the parent of this figure.
      abstract java.awt.Shape getShape()
      Get the outline shape of this figure.
      java.lang.String getToolTipText()
      Return the tooltip string for this figure, or null if the figure does not have a tooltip.
      TransformContext getTransformContext()
      Return the transform context of the figure.
      java.lang.Object getUserObject()
      Get the user object of this figure.
      boolean hit​(java.awt.geom.Rectangle2D r)
      Test if this figure intersects the given rectangle, and the interior of the figure is not transparent to hits.
      boolean intersects​(java.awt.geom.Rectangle2D r)
      Test if this figure intersects the given rectangle.
      boolean isVisible()
      Test the visibility flag of this figure.
      abstract void paint​(java.awt.Graphics2D g)
      Paint the figure.
      void paint​(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
      Repaint the figure in the given rectangle.
      void repaint()
      Schedule a repaint of the figure.
      void repaint​(DamageRegion d)
      Schedule a repaint of the figure within the given damage region.
      void setInteractor​(Interactor interactor)
      Set the interactor of this figure.
      void setParent​(CanvasComponent fc)
      Set the parent of this figure.
      void setToolTipText​(java.lang.String s)
      Set the tooltip string for this figure.
      void setUserObject​(java.lang.Object o)
      Set the user object.
      void setVisible​(boolean flag)
      Set the visibility flag of this figure.
      abstract void transform​(java.awt.geom.AffineTransform at)
      Transform the figure with the supplied transform.
      void translate​(double x, double y)
      Move the figure the indicated distance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractFigure

        public AbstractFigure()
    • Method Detail

      • contains

        public boolean contains​(java.awt.geom.Point2D p)
        Test whether this figure contains the point given. This default implementation tests using the figure's shape.
        Specified by:
        contains in interface Figure
        Parameters:
        p - The given point
        Returns:
        true if the point is contained by this figure.
      • getBounds

        public java.awt.geom.Rectangle2D getBounds()
        Get the bounding box of this figure. This default implementation returns the bounding box of the figure's outline shape.
        Specified by:
        getBounds in interface Figure
        Returns:
        the bounding box of this figure.
      • getLayer

        public CanvasLayer getLayer()
        Get the most immediate layer containing this figure. Returns null if this figure is not in a layer, either directly or as one of its ancestors.
        Specified by:
        getLayer in interface Figure
        Returns:
        the most immediate layer containing this figure.
      • getOrigin

        public java.awt.geom.Point2D getOrigin()
        Return the origin of the figure in the enclosing transform context, which in this base class is the center of the bounds returned by getBounds().
        Specified by:
        getOrigin in interface Figure
        Returns:
        The origin of the figure.
        See Also:
        getBounds()
      • getParent

        public CanvasComponent getParent()
        Return the parent of this figure. Return null if the figure does not have a parent. (Note that a figure with no parent can exist, but it will not be displayed, as it must be in a layer for the figure canvas to ever call its paint method.)
        Specified by:
        getParent in interface CanvasComponent
        Specified by:
        getParent in interface Figure
        Returns:
        the parent of this figure.
        See Also:
        Figure.setParent(CanvasComponent)
      • getShape

        public abstract java.awt.Shape getShape()
        Get the outline shape of this figure. The outline shape is used for things like highlighting. This is an abstract method, provided here since a number of other concrete methods use it.
        Specified by:
        getShape in interface Figure
        Returns:
        the outline shape of this figure
      • getTransformContext

        public TransformContext getTransformContext()
        Return the transform context of the figure. This default implementation assumes that the figure does not implement a transform context, so just calls the same method on its parent. If it has no parent, return null.
        Specified by:
        getTransformContext in interface CanvasComponent
        Returns:
        The transform context of this component.
      • getToolTipText

        public java.lang.String getToolTipText()
        Return the tooltip string for this figure, or null if the figure does not have a tooltip.
        Specified by:
        getToolTipText in interface Figure
        Returns:
        the tooltip string for this figure.
        See Also:
        Figure.setToolTipText(String)
      • hit

        public boolean hit​(java.awt.geom.Rectangle2D r)
        Test if this figure intersects the given rectangle, and the interior of the figure is not transparent to hits. This is the same as intersects() if the interior of the figure is not transparent. If the figure is not visible, return false. This default implementation is the same as intersects if the figure is visible.
        Specified by:
        hit in interface Figure
        Parameters:
        r - The rectangle to be checked.
        Returns:
        true if the figure is hit by the given rectangle.
      • intersects

        public boolean intersects​(java.awt.geom.Rectangle2D r)
        Test if this figure intersects the given rectangle. This default implementation uses the figure's outline shape.
        Specified by:
        intersects in interface Figure
        Parameters:
        r - The rectangle to be checked.
        Returns:
        truen if the figure intersects the given rectangle.
      • isVisible

        public boolean isVisible()
        Test the visibility flag of this figure. Note that this flag does not indicate whether the figure is actually visible on the screen, as one if its ancestors may not be visible.
        Specified by:
        isVisible in interface VisibleComponent
        Returns:
        true if the object is visible.
      • paint

        public abstract void paint​(java.awt.Graphics2D g)
        Paint the figure. This is an abstract method. Implementing subclasses should note that the graphics context may already have a current transform, so if this figure needs to perform a transform, it must be cascaded with the current transform and the transform restored at the end of this method. The graphics context may also contain a clip region, so any clipping must be done with the intersection of the current clip and the clip desired by this method. and the clip restored. Other state in the graphics context, such as the stroke and fill, do not need to be preserved.
        Specified by:
        paint in interface VisibleComponent
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
      • paint

        public void paint​(java.awt.Graphics2D g,
                          java.awt.geom.Rectangle2D r)
        Repaint the figure in the given rectangle. This default implementation repaints the whole figure. Subclasses should consider overriding this method to optimize redraw. See the documentation of the one-argument version of this method.
        Specified by:
        paint in interface VisibleComponent
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
        r - The region.
      • repaint

        public void repaint()
        Schedule a repaint of the figure. This should be called after performing modifications on the figure, so that the figure is scheduled for redrawing. This default implementation creates a damage region that is the same size as this figure's bounding box, and forwards that to the parent. Subclasses only need to override this method if they need to damage a region that is different from the bounding box.
        Specified by:
        repaint in interface CanvasComponent
      • repaint

        public void repaint​(DamageRegion d)
        Schedule a repaint of the figure within the given damage region. This default implementation forwards the damage region to this figure's parent. See the nullary version of this method.
        Specified by:
        repaint in interface CanvasComponent
        Parameters:
        d - The region where a repaint has occurred.
      • setInteractor

        public void setInteractor​(Interactor interactor)
        Set the interactor of this figure. Once a figure has an interactor given to it, it will respond to events on the figure canvas.
        Specified by:
        setInteractor in interface Figure
        Parameters:
        interactor - The interactor.
        See Also:
        Figure.getInteractor()
      • setParent

        public void setParent​(CanvasComponent fc)
        Set the parent of this figure. A null argument means that the figure is being removed from its parent. No checks are performed to see if the figure already has a parent -- it is the responsibility of the caller to do this, and to change the layer reference of the figure if necessary. This method is intended only for use by classes that implement FigureContainer.
        Specified by:
        setParent in interface Figure
        Parameters:
        fc - The parent of the figure.
        See Also:
        Figure.getParent()
      • setToolTipText

        public void setToolTipText​(java.lang.String s)
        Set the tooltip string for this figure. If the string is null, then the figure will not have a tooltip.
        Specified by:
        setToolTipText in interface Figure
        Parameters:
        s - The tool tip text.
        See Also:
        Figure.getToolTipText()
      • setVisible

        public void setVisible​(boolean flag)
        Set the visibility flag of this figure. If the flag is false, then the figure will not be drawn on the screen and it will not respond to user input events.
        Specified by:
        setVisible in interface VisibleComponent
        Parameters:
        flag - True if this object is to be visible.
      • transform

        public abstract void transform​(java.awt.geom.AffineTransform at)
        Transform the figure with the supplied transform. This can be used to perform arbitrary translation, scaling, shearing, and rotation operations.
        Specified by:
        transform in interface Figure
        Parameters:
        at - The transform to be used.
      • translate

        public void translate​(double x,
                              double y)
        Move the figure the indicated distance. The default implementation uses the transform method, so most subclasses can probably implement this more efficiently.
        Specified by:
        translate in interface Figure
        Parameters:
        x - The x value to be moved.
        y - The y value to be moved.