Interface Decorator

  • All Known Implementing Classes:
    BaselineDecorator, BlurDecorator, ClipDecorator, DropShadowDecorator, FadeDecorator, GrayscaleDecorator, OverlayDecorator, ReflectionDecorator, RotationDecorator, SaturationDecorator, ScaleDecorator, ShadeDecorator, TagDecorator, TranslationDecorator, WatermarkDecorator

    public interface Decorator
    Interface defining a component "decorator". Decorators allow a caller to attach additional visual effects to a component.

    Decorators use a chained prepare/update model to modify the graphics in which a component is painted. The prepare() method of each decorator in a component's decorator sequence is called in reverse order before the component's paint() method is called. prepare() returns an instance of Graphics2D that is passed to prior decorators, and ultimately to the component itself. This allows decorators to modify the graphics context before it reaches the component. After the component has been painted, each decorator's update() method is then called in order to allow the decorator to further modify the resulting output.

    Decorators are not restricted to painting within the component's bounds. However, they are clipped to the bounds of the component's parent. They are not clipped to their own bounds because, due to the chained painting model, it is not safe assume that a clip applied to a given decorator during the prepare phase will be valid for subsequent updates, or even for painting the component itself; though a component paints into a copy of the final prepared graphics, it must still be clipped to the intersection of its own bounds and the current clip (not the intersections of all preceding decorator prepare() calls).

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default Bounds getBounds​(Component component)
      Returns the bounding area of the decorator.
      default java.awt.geom.AffineTransform getTransform​(Component component)
      Returns the transformation the decorator applies to the component's coordinate space.
      java.awt.Graphics2D prepare​(Component component, java.awt.Graphics2D graphics)
      Prepares the graphics context into which the component or prior decorator will paint.
      default void update()
      Updates the graphics context into which the component or prior decorator was painted.
    • Method Detail

      • prepare

        java.awt.Graphics2D prepare​(Component component,
                                    java.awt.Graphics2D graphics)
        Prepares the graphics context into which the component or prior decorator will paint. This method is called immediately prior to Component.paint(Graphics2D); decorators are called in descending order.
        Parameters:
        component - The component the decorator is attached to.
        graphics - The graphics context to draw into.
        Returns:
        The graphics context that should be used by the component or prior decorators.
      • update

        default void update()
        Updates the graphics context into which the component or prior decorator was painted. This method is called immediately after Component.paint(Graphics2D); decorators are called in ascending order.

        This default version simply returns, without doing anything (often the appropriate thing to do).

      • getBounds

        default Bounds getBounds​(Component component)
        Returns the bounding area of the decorator.

        This default simply returns the bounds of the component's size.

        Parameters:
        component - The component that the decorator is attached to.
        Returns:
        The decorator's bounds, relative to the component's origin.
      • getTransform

        default java.awt.geom.AffineTransform getTransform​(Component component)
        Returns the transformation the decorator applies to the component's coordinate space.

        This default simply returns a new AffineTransform.

        Parameters:
        component - The component the decorator is attached to.
        Returns:
        The decorator's transform.