Class TransformedFigureTutorial.CloudFigure

    • Constructor Detail

      • CloudFigure

        public CloudFigure​(double x,
                           double y,
                           double width,
                           double height)
        Create a new instance of this figure. The cloud is initially created at coordinates (0,0) and then transformed to the requested coordinates. To create the cloud shape, use the Area class in Java2D, which implements constructive area geometry, and join a bunch of circles into a single shape.
    • Method Detail

      • getBounds

        public java.awt.geom.Rectangle2D getBounds()
        Get the bounds of this figure. Because this figure has its own transform, we need to transform the internal bounds into the enclosing context. To make this more efficient, we use a previously-cached copy of the transformed bounds if there is one.
        Specified by:
        getBounds in interface Figure
        Overrides:
        getBounds in class AbstractFigure
        Returns:
        the bounding box of this figure.
      • getShape

        public java.awt.Shape getShape()
        Get the shape of this figure. Because this figure has its own transform, we need to transform the internal shape into the enclosing context. To make this more efficient, we use a previously-cached copy of the transformed shape if there is one.
        Specified by:
        getShape in interface Figure
        Specified by:
        getShape in class AbstractFigure
        Returns:
        the outline shape of this figure
      • paint

        public void paint​(java.awt.Graphics2D g)
        Paint this figure onto the given graphics context. First we "push" the transform context onto the transform stack, so that the graphics port has the correct transform. Then we paint the cloud a translucent magenta (yum!), and then we make a couple of little clouds and paint them opaque. (The way this is done in this example is horrendously inefficient.) Finally, we "pop" the transform context off the stack.
        Specified by:
        paint in interface VisibleComponent
        Specified by:
        paint in class AbstractFigure
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
      • transform

        public void transform​(java.awt.geom.AffineTransform at)
        Transform the object. In this example, we pre-concatenate the given transform with the transform in the transform context. When the figure is repainted, it will be redrawn in the right place. We also must be sure to invalidate the cached geometry objects that depend on the transform.
        Specified by:
        transform in interface Figure
        Specified by:
        transform in class AbstractFigure
        Parameters:
        at - The transform to be used.