Package diva.canvas

Class FigureDecorator

    • Constructor Detail

      • FigureDecorator

        public FigureDecorator()
    • Method Detail

      • add

        public void add​(Figure f)
        Add a figure. This method does not make too much sense for Decorators, but has to be here anyway. This method is set same as calling setChild(f).
        Parameters:
        f - The figure to be added.
      • getBounds

        public java.awt.geom.Rectangle2D getBounds()
        Get the bounds of this figure, which is by default the same as the child figure, if there is one, or a very small rectangle if there isn't.
        Specified by:
        getBounds in interface Figure
        Overrides:
        getBounds in class AbstractFigure
        Returns:
        the bounding box of this figure.
      • getChild

        public Figure getChild()
        Get the child figure, or null if there isn't one.
        Returns:
        The child figure
      • getContainer

        public FigureContainer getContainer()
        Get the container, which is defined as the lowest ancestor that is not a FigureDecorator.
        Returns:
        the container
      • getDecoratedFigure

        public Figure getDecoratedFigure()
        Get the decorated figure, which is defined as the highest descendent that is not a decorator.
        Returns:
        The decorated figure.
      • getShape

        public java.awt.Shape getShape()
        Get the outline shape of this figure, which is by default the same as the child figure, if there is one, or a very small rectangle if there isn't.
        Specified by:
        getShape in interface Figure
        Specified by:
        getShape in class AbstractFigure
        Returns:
        the outline shape of this figure
      • hit

        public boolean hit​(java.awt.geom.Rectangle2D r)
        Test if the child is hit.
        Specified by:
        hit in interface Figure
        Overrides:
        hit in class AbstractFigure
        Parameters:
        r - The rectangle to be checked.
        Returns:
        true if the figure is hit by the given rectangle.
      • newInstance

        public abstract FigureDecorator newInstance​(Figure f)
        Create a new instance of this figure decorator, modeled on this one. This is used by interaction code that needs to dynamically create new manipulators. The figure argument can be used by this method to initialize the new instance; however, the new instance must not be wrapped around the figure, since that should be done by the caller.
        Parameters:
        f - The figure
        Returns:
        The new instance of the figure decorator.
      • paint

        public void paint​(java.awt.Graphics2D g)
        Paint the figure. By default, this method simply forwards the paint request to the contained figure.
        Specified by:
        paint in interface VisibleComponent
        Overrides:
        paint in class AbstractFigureContainer
        Parameters:
        g - The Graphics context
      • setChild

        public void setChild​(Figure f)
        Set the child figure. If there is already a child figure, remove it from this container.
        Parameters:
        f - The child figure.
      • remove

        public void remove​(Figure f)
        Remove a figure. This method does not make too much sense for Decorators, but has to be here anyway. If the passed figure is the same as the child figure, then this method is the same as calling setChild(null). Otherwise, it does nothing.
        Parameters:
        f - The figure to be removed
      • replaceChild

        protected void replaceChild​(Figure child,
                                    Figure replacement)
        Replace the first figure, which must be a child, with the second, which must not be a child.
        Specified by:
        replaceChild in class AbstractFigureContainer
        Parameters:
        child - The figure to be replaced.
        replacement - The replacement figure.
      • transform

        public void transform​(java.awt.geom.AffineTransform at)
        Transform the figure with the supplied transform. By default, this method simply forwards the paint request to the child figure.
        Specified by:
        transform in interface Figure
        Overrides:
        transform in class AbstractFigureContainer
        Parameters:
        at - The transform to be used.
      • translate

        public void translate​(double x,
                              double y)
        Translate the figure by the given distance. By default, this method simply forwards the paint request to the child figure.
        Specified by:
        translate in interface Figure
        Overrides:
        translate in class AbstractFigureContainer
        Parameters:
        x - The x value to be moved.
        y - The y value to be moved.