Class WatermarkDecorator

  • All Implemented Interfaces:
    Decorator

    public class WatermarkDecorator
    extends java.lang.Object
    implements Decorator
    Decorator that paints a watermark effect over a component.
    • Constructor Summary

      Constructors 
      Constructor Description
      WatermarkDecorator()
      Creates a new WatermarkDecorator with no text or image.
      WatermarkDecorator​(java.lang.String text)
      Creates a new WatermarkDecorator with the specified string as its text and no image.
      WatermarkDecorator​(java.lang.String text, Image image)
      Creates a new WatermarkDecorator with the specified text and image.
      WatermarkDecorator​(Image image)
      Creates a new WatermarkDecorator with no text and the specified image.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Font getFont()
      Gets the font that will be used when painting this decorator's text.
      Image getImage()
      Gets the image that will be painted over this decorator's component.
      float getOpacity()
      Gets the opacity of the watermark.
      java.lang.String getText()
      Gets the text that will be painted over this decorator's component.
      double getTheta()
      Gets the angle at the watermark will be painted, in radians.
      java.awt.Graphics2D prepare​(Component componentArgument, java.awt.Graphics2D graphicsArgument)
      Prepares the graphics context into which the component or prior decorator will paint.
      void setFont​(java.awt.Font font)
      Sets the font that will be used when painting this decorator's text.
      void setFont​(java.lang.String font)
      Sets the font that will be used when painting this decorator's text.
      void setImage​(java.lang.String imageName)
      Sets the image that will be painted over this decorator's component.
      void setImage​(java.net.URL imageURL)
      Sets the image that will be painted over this decorator's component by URL.
      void setImage​(Image image)
      Sets the image that will be painted over this decorator's component.
      void setOpacity​(float opacity)
      Sets the opacity of the watermark.
      void setText​(java.lang.String text)
      Sets the text that will be painted over this decorator's component.
      void setTheta​(double theta)
      Sets the angle at the watermark will be painted, in radians.
      void update()
      Updates the graphics context into which the component or prior decorator was painted.
      • Methods inherited from class java.lang.Object

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

      • WatermarkDecorator

        public WatermarkDecorator()
        Creates a new WatermarkDecorator with no text or image.
      • WatermarkDecorator

        public WatermarkDecorator​(java.lang.String text)
        Creates a new WatermarkDecorator with the specified string as its text and no image.
        Parameters:
        text - The text to paint over the decorated component
      • WatermarkDecorator

        public WatermarkDecorator​(Image image)
        Creates a new WatermarkDecorator with no text and the specified image.
        Parameters:
        image - The image to paint over the decorated component
      • WatermarkDecorator

        public WatermarkDecorator​(java.lang.String text,
                                  Image image)
        Creates a new WatermarkDecorator with the specified text and image.
        Parameters:
        text - The text to paint over the decorated component
        image - The image to paint over the decorated component
    • Method Detail

      • getText

        public java.lang.String getText()
        Gets the text that will be painted over this decorator's component.
        Returns:
        This decorator's text
      • setText

        public void setText​(java.lang.String text)
        Sets the text that will be painted over this decorator's component.
        Parameters:
        text - This decorator's text
      • getFont

        public java.awt.Font getFont()
        Gets the font that will be used when painting this decorator's text.
        Returns:
        This decorator's font
      • setFont

        public void setFont​(java.awt.Font font)
        Sets the font that will be used when painting this decorator's text.
        Parameters:
        font - This decorator's font
      • setFont

        public final void setFont​(java.lang.String font)
        Sets the font that will be used when painting this decorator's text.
        Parameters:
        font - This decorator's font
      • getImage

        public Image getImage()
        Gets the image that will be painted over this decorator's component.
        Returns:
        This decorator's image
      • setImage

        public void setImage​(Image image)
        Sets the image that will be painted over this decorator's component.
        Parameters:
        image - This decorator's image
      • setImage

        public void setImage​(java.net.URL imageURL)
        Sets the image that will be painted over this decorator's component by URL.

        If the icon already exists in the application context resource cache, the cached value will be used. Otherwise, the icon will be loaded synchronously and added to the cache.

        Parameters:
        imageURL - The location of the image to set.
      • setImage

        public void setImage​(java.lang.String imageName)
        Sets the image that will be painted over this decorator's component.
        Parameters:
        imageName - The resource name of the image to set.
        See Also:
        setImage(URL), ImageUtils.findByName(String,String)
      • getOpacity

        public float getOpacity()
        Gets the opacity of the watermark.
        Returns:
        This decorator's opacity
      • setOpacity

        public void setOpacity​(float opacity)
        Sets the opacity of the watermark.
        Parameters:
        opacity - This decorator's opacity
      • getTheta

        public double getTheta()
        Gets the angle at the watermark will be painted, in radians.
        Returns:
        This decorator's watermark angle
      • setTheta

        public void setTheta​(double theta)
        Sets the angle at the watermark will be painted, in radians. This value must lie between 0 and PI / 2 (inclusive).
        Parameters:
        theta - This decorator's watermark angle
      • prepare

        public java.awt.Graphics2D prepare​(Component componentArgument,
                                           java.awt.Graphics2D graphicsArgument)
        Description copied from interface: Decorator
        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.
        Specified by:
        prepare in interface Decorator
        Parameters:
        componentArgument - The component the decorator is attached to.
        graphicsArgument - The graphics context to draw into.
        Returns:
        The graphics context that should be used by the component or prior decorators.
      • update

        public void update()
        Description copied from interface: Decorator
        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).

        Specified by:
        update in interface Decorator