Class ScaleDecorator

  • All Implemented Interfaces:
    Decorator

    public class ScaleDecorator
    extends java.lang.Object
    implements Decorator
    Decorator that scales the painting of a component along the X and/or Y axes.

    Generally speaking, decorators don't force a repaint of the component(s) they are attached to when their parameters are changed. So, if this decorator is changed after being applied to a particular component (e.g., to do a dynamic resize) then either the component.repaint() method must be called or the decorator should be removed and added again to force a repaint with the new scale.

    • Constructor Summary

      Constructors 
      Constructor Description
      ScaleDecorator()
      Creates a new ScaleDecorator with the default scaleX scaleY values of 1.0f.
      ScaleDecorator​(float scale)
      Creates a new ScaleDecorator with a "square" scaling of the given value in both directions.
      ScaleDecorator​(float scaleX, float scaleY)
      Creates a new ScaleDecorator with the specified scaleX and scaleY values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Bounds getBounds​(Component component)
      Returns the bounding area of the decorator.
      HorizontalAlignment getHorizontalAlignment()
      Gets the horizontal alignment of the decorator.
      float getScaleX()
      Gets the amount by which drawing operations will be scaled along the x-axis.
      float getScaleY()
      Gets the amount by which drawing operations will be scaled along the y-axis.
      java.awt.geom.AffineTransform getTransform​(Component component)
      Returns the transformation the decorator applies to the component's coordinate space.
      VerticalAlignment getVerticalAlignment()
      Gets the vertical alignment of the decorator.
      java.awt.Graphics2D prepare​(Component component, java.awt.Graphics2D graphics)
      Prepares the graphics context into which the component or prior decorator will paint.
      void repaint​(Component component, int x, int y, int width, int height)  
      void setHorizontalAlignment​(HorizontalAlignment horizontalAlignment)
      Sets the horizontal alignment of the decorator.
      void setScale​(float scale)
      Sets the amount by which drawing operations will be scaled along both the x and y axes.
      void setScale​(float scaleX, float scaleY)
      Sets the amount by which drawing operations will be scaled along the x and y axes.
      void setScaleX​(float scaleX)
      Sets the amount by which drawing operations will be scaled along the x-axis.
      void setScaleX​(java.lang.Number scaleX)
      Sets the amount by which drawing operations will be scaled along the x-axis.
      void setScaleY​(float scaleY)
      Sets the amount by which drawing operations will be scaled along the y-axis.
      void setScaleY​(java.lang.Number scaleY)
      Sets the amount by which drawing operations will be scaled along the y-axis.
      void setVerticalAlignment​(VerticalAlignment verticalAlignment)
      Sets the vertical alignment of the decorator.
      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

      • ScaleDecorator

        public ScaleDecorator()
        Creates a new ScaleDecorator with the default scaleX scaleY values of 1.0f.
      • ScaleDecorator

        public ScaleDecorator​(float scale)
        Creates a new ScaleDecorator with a "square" scaling of the given value in both directions.
        Parameters:
        scale - The scale to use for both X and Y directions.
      • ScaleDecorator

        public ScaleDecorator​(float scaleX,
                              float scaleY)
        Creates a new ScaleDecorator with the specified scaleX and scaleY values.
        Parameters:
        scaleX - The amount to scale the component's x-axis
        scaleY - The amount to scale the component's y-axis
    • Method Detail

      • getScaleX

        public float getScaleX()
        Gets the amount by which drawing operations will be scaled along the x-axis.
        Returns:
        The amount to scale the component's x-axis
      • setScaleX

        public void setScaleX​(float scaleX)
        Sets the amount by which drawing operations will be scaled along the x-axis.
        Parameters:
        scaleX - The amount to scale the component's x-axis
      • setScaleX

        public void setScaleX​(java.lang.Number scaleX)
        Sets the amount by which drawing operations will be scaled along the x-axis.
        Parameters:
        scaleX - The amount to scale the component's x-axis
      • getScaleY

        public float getScaleY()
        Gets the amount by which drawing operations will be scaled along the y-axis.
        Returns:
        The amount to scale the component's y-axis
      • setScaleY

        public void setScaleY​(float scaleY)
        Sets the amount by which drawing operations will be scaled along the y-axis.
        Parameters:
        scaleY - The amount to scale the component's y-axis
      • setScaleY

        public void setScaleY​(java.lang.Number scaleY)
        Sets the amount by which drawing operations will be scaled along the y-axis.
        Parameters:
        scaleY - The amount to scale the component's y-axis
      • setScale

        public void setScale​(float scaleX,
                             float scaleY)
        Sets the amount by which drawing operations will be scaled along the x and y axes.
        Parameters:
        scaleX - The amount to scale the component's x-axis.
        scaleY - The amount to scale the component's y-axis.
      • setScale

        public void setScale​(float scale)
        Sets the amount by which drawing operations will be scaled along both the x and y axes.
        Parameters:
        scale - The amount to scale the component's x and y axes.
      • getHorizontalAlignment

        public HorizontalAlignment getHorizontalAlignment()
        Gets the horizontal alignment of the decorator. A left alignment will paint the component's left edge at the component's x-coordinate. A right alignment will paint the component's right edge along the right side of the component's bounding box. A center or justified alignment will paint the scaled component centered with respect to the component's bounding box.
        Returns:
        The horizontal alignment
      • setHorizontalAlignment

        public void setHorizontalAlignment​(HorizontalAlignment horizontalAlignment)
        Sets the horizontal alignment of the decorator. A left alignment will paint the component's left edge at the component's x-coordinate. A right alignment will paint the component's right edge along the right side of the component's bounding box. A center or justified alignment will paint the scaled component centered with respect to the component's bounding box.
        Parameters:
        horizontalAlignment - The horizontal alignment
      • getVerticalAlignment

        public VerticalAlignment getVerticalAlignment()
        Gets the vertical alignment of the decorator. A top alignment will paint the component's top edge at the component's y-coordinate. A bottom alignment will paint the component's bottom edge along the bottom side of the component's bounding box. A center or justified alignment will paint the scaled component centered with respect to the component's bounding box.
        Returns:
        The vertical alignment
      • setVerticalAlignment

        public void setVerticalAlignment​(VerticalAlignment verticalAlignment)
        Sets the vertical alignment of the decorator. A top alignment will paint the component's top edge at the component's y-coordinate. A bottom alignment will paint the component's bottom edge along the bottom side of the component's bounding box. A center or justified alignment will paint the scaled component centered with respect to the component's bounding box.
        Parameters:
        verticalAlignment - The vertical alignment
      • prepare

        public java.awt.Graphics2D prepare​(Component component,
                                           java.awt.Graphics2D graphics)
        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:
        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

        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
      • repaint

        public void repaint​(Component component,
                            int x,
                            int y,
                            int width,
                            int height)
      • getBounds

        public Bounds getBounds​(Component component)
        Description copied from interface: Decorator
        Returns the bounding area of the decorator.

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

        Specified by:
        getBounds in interface Decorator
        Parameters:
        component - The component that the decorator is attached to.
        Returns:
        The decorator's bounds, relative to the component's origin.
      • getTransform

        public java.awt.geom.AffineTransform getTransform​(Component component)
        Description copied from interface: Decorator
        Returns the transformation the decorator applies to the component's coordinate space.

        This default simply returns a new AffineTransform.

        Specified by:
        getTransform in interface Decorator
        Parameters:
        component - The component the decorator is attached to.
        Returns:
        The decorator's transform.