Package diva.canvas

Class TransformContext


  • public class TransformContext
    extends java.lang.Object
    A transform context defines a transformed coordinate system. Each transform context is associated with a component in the display tree. This class provides the support for most of the transform-related operations on the display tree.
    Version:
    $Id$
    Author:
    John Reekie
    Pt.AcceptedRating:
    Yellow
    • Constructor Summary

      Constructors 
      Constructor Description
      TransformContext​(CanvasComponent component)
      Create a transform context associated with the given display component.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkCacheValid​(TransformContext ancestor)
      Check transform cache validity.
      void concatenate​(java.awt.geom.AffineTransform at)
      Concatenate this transform context with the given transform.
      CanvasComponent getComponent()
      Get the component that this context is associated with.
      java.awt.geom.AffineTransform getInverseTransform()
      Get the transform from parent coordinates into local coordinates.
      TransformContext getParent()
      Get the parent transform context of this one, or null if this context is at the root of the transform tree.
      java.awt.geom.AffineTransform getScreenTransform()
      Get the transform from local coordinates into screen coordinates.
      java.awt.geom.AffineTransform getTransform()
      Get the transform of this context.
      java.awt.geom.AffineTransform getTransform​(TransformContext context)
      Get the transform of this context, relative to the given context.
      int getVersion()
      Get the version number of the transform context.
      void invalidateCache()
      Notify that cached data based on the transform is now invalid.
      boolean isCacheValid()
      Test if the cache is valid.
      void pop​(java.awt.Graphics2D g)
      Pop this transform off the graphics stack.
      void preConcatenate​(java.awt.geom.AffineTransform at)
      Pre-concatenate this transform context with the given transform.
      void push​(java.awt.Graphics2D g)
      Push this transform onto the graphics stack.
      void setTransform​(java.awt.geom.AffineTransform at)
      Set the transform that maps local coordinates into the parent's coordinates.
      void translate​(double x, double y)
      Translate this context the given distance.
      • Methods inherited from class java.lang.Object

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

      • TransformContext

        public TransformContext​(CanvasComponent component)
        Create a transform context associated with the given display component.
        Parameters:
        component - The given display component
    • Method Detail

      • checkCacheValid

        public void checkCacheValid​(TransformContext ancestor)
        Check transform cache validity. The argument is an ancestor context of this context. If the ancestor is not valid, then all of the contexts from this one up to the ancestor are marked invalid.
        Parameters:
        ancestor - The ancestor context
      • concatenate

        public void concatenate​(java.awt.geom.AffineTransform at)
        Concatenate this transform context with the given transform.
        Parameters:
        at - The transform
      • getComponent

        public CanvasComponent getComponent()
        Get the component that this context is associated with. The component is set in the constructor and cannot be changed.
        Returns:
        The component
      • getInverseTransform

        public java.awt.geom.AffineTransform getInverseTransform()
        Get the transform from parent coordinates into local coordinates.
        Returns:
        the transform
      • getParent

        public TransformContext getParent()
        Get the parent transform context of this one, or null if this context is at the root of the transform tree.
        Returns:
        The parent transform
      • getScreenTransform

        public java.awt.geom.AffineTransform getScreenTransform()
        Get the transform from local coordinates into screen coordinates.
        Returns:
        The transform
      • getTransform

        public java.awt.geom.AffineTransform getTransform​(TransformContext context)
        Get the transform of this context, relative to the given context. This is the transform from this context into the given context, which must enclose this one.
        Parameters:
        context - The context
        Returns:
        The transform
        See Also:
        setTransform(AffineTransform), getTransform()
      • getVersion

        public int getVersion()
        Get the version number of the transform context. The version number is incremented whenever the transform changes, so can be used by client components to figure out when to update cached data based upon the transform.
        Returns:
        The version number of the transform context.
      • invalidateCache

        public void invalidateCache()
        Notify that cached data based on the transform is now invalid. Increment the version number so that clients can use it to tell if they need to update data based on the transform.
      • isCacheValid

        public boolean isCacheValid()
        Test if the cache is valid.
        Returns:
        true if the cache is valid.
      • push

        public void push​(java.awt.Graphics2D g)
        Push this transform onto the graphics stack.
        Parameters:
        g - The graphics context
      • pop

        public void pop​(java.awt.Graphics2D g)
        Pop this transform off the graphics stack.
        Parameters:
        g - The graphics context
      • preConcatenate

        public void preConcatenate​(java.awt.geom.AffineTransform at)
        Pre-concatenate this transform context with the given transform.
        Parameters:
        at - The given transform
      • setTransform

        public void setTransform​(java.awt.geom.AffineTransform at)
        Set the transform that maps local coordinates into the parent's coordinates. If there is no parent, the "parent" is taken to be the screen. An exception will be thrown if the transform is null. This method invalidates any cached transforms. Note that the transform may be remembered by this context, so the caller must make sure that it will not be subsequently modified.
        Parameters:
        at - The AffineTransform
        See Also:
        getTransform()
      • translate

        public void translate​(double x,
                              double y)
        Translate this context the given distance.
        Parameters:
        x - The x distance to be translated
        y - The y distance to be translated