Package diva.canvas

Class SiteDecorator

  • All Implemented Interfaces:
    Site
    Direct Known Subclasses:
    FixedNormalSite

    public class SiteDecorator
    extends java.lang.Object
    implements Site
    This is an abstract decorator for sites. It can be used to add or change the functionality of an arbitrary site.
    Version:
    $Id$
    Author:
    Steve Neuendorffer
    Pt.AcceptedRating:
    Red
    • Constructor Summary

      Constructors 
      Constructor Description
      SiteDecorator​(Site site)
      Create a new decorator on the given site.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Figure getFigure()
      Get the figure to which this site is attached.
      int getID()
      Get the ID of this site.
      double getNormal()
      Get the angle of the normal to this site, in radians between zero and 2pi.
      java.awt.geom.Point2D getPoint()
      Get the point location of the site, in the enclosing transform context with default normal.
      java.awt.geom.Point2D getPoint​(double normal)
      Get the point location of the site, in the enclosing transform context with the given normal.
      java.awt.geom.Point2D getPoint​(TransformContext tc)
      Get the point location of the site, in the given transform context with the default normal.
      java.awt.geom.Point2D getPoint​(TransformContext tc, double normal)
      Get the point location of the site, in the given transform context with the given normal.
      TransformContext getTransformContext()
      Get the enclosing transform context of this site.
      double getX()
      Get the x-coordinate of the site, in the enclosing transform context.
      double getY()
      Get the y-coordinate of the site, in the enclosing transform context.
      boolean hasNormal()
      Test if this site has a "normal" to it.
      boolean isNormal​(int direction)
      Test if this site has a normal in the given direction.
      void setNormal​(double normal)
      Set the normal "out" of the site.
      void translate​(double x, double y)
      Translate the site by the indicated distance, where distances are in the local coordinates of the containing pane.
      • Methods inherited from class java.lang.Object

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

      • SiteDecorator

        public SiteDecorator​(Site site)
        Create a new decorator on the given site.
        Parameters:
        site - The site.
    • Method Detail

      • getFigure

        public Figure getFigure()
        Get the figure to which this site is attached. Usually, this will return a valid Figure, but clients must be aware that certain types of site may return null.
        Specified by:
        getFigure in interface Site
        Returns:
        The figure.
      • getID

        public int getID()
        Get the ID of this site. Within each figure, the IDs of the sites must be unique.
        Specified by:
        getID in interface Site
        Returns:
        The unique identifier.
      • getNormal

        public double getNormal()
        Get the angle of the normal to this site, in radians between zero and 2pi. The direction is "out" of the site. The result is meaningful only if hasNormal() returns true.
        Specified by:
        getNormal in interface Site
        Returns:
        The normal.
        See Also:
        setNormal(double)
      • getPoint

        public java.awt.geom.Point2D getPoint()
        Get the point location of the site, in the enclosing transform context with default normal.
        Specified by:
        getPoint in interface Site
        Returns:
        The point.
      • getPoint

        public java.awt.geom.Point2D getPoint​(TransformContext tc)
        Get the point location of the site, in the given transform context with the default normal. The given context must be an enclosing context of the site.
        Specified by:
        getPoint in interface Site
        Parameters:
        tc - The transformation context.
        Returns:
        The point.
      • getPoint

        public java.awt.geom.Point2D getPoint​(double normal)
        Get the point location of the site, in the enclosing transform context with the given normal.
        Specified by:
        getPoint in interface Site
        Parameters:
        normal - The normal
        Returns:
        The point.
      • getPoint

        public java.awt.geom.Point2D getPoint​(TransformContext tc,
                                              double normal)
        Get the point location of the site, in the given transform context with the given normal. The given context must be an enclosing context of the site.
        Specified by:
        getPoint in interface Site
        Parameters:
        tc - The Transform context
        normal - The normal
        Returns:
        The point.
      • getTransformContext

        public TransformContext getTransformContext()
        Get the enclosing transform context of this site.
        Specified by:
        getTransformContext in interface Site
        Returns:
        The transform context
      • getX

        public double getX()
        Get the x-coordinate of the site, in the enclosing transform context.
        Specified by:
        getX in interface Site
        Returns:
        The x-coordinate of the site.
      • getY

        public double getY()
        Get the y-coordinate of the site, in the enclosing transform context.
        Specified by:
        getY in interface Site
        Returns:
        The y-coordinate of the site.
      • hasNormal

        public boolean hasNormal()
        Test if this site has a "normal" to it. The normal is accessible by the methods getNormal() and isNormal(). Generally, sites on the boundary of a shape will return true to this method, and sites in the center of an object will return false.
        Specified by:
        hasNormal in interface Site
        Returns:
        true if the site has a normal.
      • isNormal

        public boolean isNormal​(int direction)
        Test if this site has a normal in the given direction. The direction is that given by one of the static constants NORTH, SOUTH, EAST, or WEST, defined in javax.swing.SwingConstants
        Specified by:
        isNormal in interface Site
        Parameters:
        direction - The direction
        Returns:
        true if the site is normal in the given direction.
      • setNormal

        public void setNormal​(double normal)
        Set the normal "out" of the site. If the site cannot change its normal, it can ignore this call, so clients that care should always check the normal after calling. If the site can change its normal, it can also change its position. For example, a site on the perimeter of a figure may move to a different position.
        Specified by:
        setNormal in interface Site
        Parameters:
        normal - The normal.
        See Also:
        getNormal()
      • translate

        public void translate​(double x,
                              double y)
        Translate the site by the indicated distance, where distances are in the local coordinates of the containing pane. Usually, this will mean that the figure is reshaped so that the site moves the given distance. If the site cannot be moved the given distance, then either do nothing, or move it part of the distance. Clients are expected to check the new location of the site.
        Specified by:
        translate in interface Site
        Parameters:
        x - The x distance to be translated.
        y - The y distance to be translated.