Class CachingPainter<T>

  • All Implemented Interfaces:
    javax.swing.Painter<T>

    public class CachingPainter<T>
    extends java.lang.Object
    implements javax.swing.Painter<T>
    This painter wraps another painter, buffering the wrapped painter so that it only needs to be called when the width or height changes. This can significantly increase painting speed if the wrapped painter is computationally expensive. To use this class, simply pass the painter that you wish to wrap to the constructor.
    • Constructor Summary

      Constructors 
      Constructor Description
      CachingPainter​(javax.swing.Painter<T> painter)
      Cache painting calls for the specified painter, only using the wrapped painter when the size of the paint area changes.
      CachingPainter​(javax.swing.Painter<T> painter, int standardWidth, int standardHeight)
      Using this constructor will create a cache image at a single standard size, after which only that image will be used (resizing if necessary).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.swing.Painter<T> getWrappedPainter()
      Returns the wrapped painter that will be delegated to.
      void invalidate()
      Invalidates any cached version of the paint area, so that the next call to paint will have to be passed through to the wrapped painter.
      void paint​(java.awt.Graphics2D g, T c, int width, int height)
      • Methods inherited from class java.lang.Object

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

      • CachingPainter

        public CachingPainter​(javax.swing.Painter<T> painter)
        Cache painting calls for the specified painter, only using the wrapped painter when the size of the paint area changes.
        Parameters:
        painter - the painter to wrap
      • CachingPainter

        public CachingPainter​(javax.swing.Painter<T> painter,
                              int standardWidth,
                              int standardHeight)
        Using this constructor will create a cache image at a single standard size, after which only that image will be used (resizing if necessary). The wrapped painter will never be called again.
        Parameters:
        painter - the painter to wrap
        standardWidth - the width of the fixed image to create
        standardHeight - the height of the fixed image to create
    • Method Detail

      • paint

        public void paint​(java.awt.Graphics2D g,
                          T c,
                          int width,
                          int height)
        Specified by:
        paint in interface javax.swing.Painter<T>
        Parameters:
        g - a graphics context for painting
        width - the width of the visible console area
        height - the height of the visible console area
      • invalidate

        public void invalidate()
        Invalidates any cached version of the paint area, so that the next call to paint will have to be passed through to the wrapped painter. This has no effect if the "paint once" constructor was used.
      • getWrappedPainter

        public javax.swing.Painter<T> getWrappedPainter()
        Returns the wrapped painter that will be delegated to.
        Returns:
        the wrapped painter