Package diva.canvas

Class PaneWrapper

  • All Implemented Interfaces:
    CanvasComponent, EventAcceptor, Figure, VisibleComponent, UserObjectContainer

    public class PaneWrapper
    extends AbstractFigure
    implements EventAcceptor
    A figure that wraps a whole canvas pane. This class is thus one of the ways in which a canvas pane can be nested within other canvas panes. It can be given a figure that is drawn as the background or outline of the pane. Once an instance of this class has been created, the wrapped pane cannot be changed.

    In order to pass events down into the contained pane, the PaneWrapper implements EventAcceptor. It forwards events to the internal pane.

    Version:
    $Id$
    Author:
    John Reekie
    Pt.AcceptedRating:
    Red
    • Constructor Detail

      • PaneWrapper

        public PaneWrapper​(CanvasPane pane)
        Create a new pane figure with the given pane. The coordinate transform will be unity. After creating, the coordinate transform can be changed with setTransform(), and a background figure added if desired with setBackground().
        Parameters:
        pane - The given pane
    • Method Detail

      • dispatchEvent

        public void dispatchEvent​(java.awt.AWTEvent event)
        Dispatch an AWT event on this pane figure. Currently only layer events are handled.
        Specified by:
        dispatchEvent in interface EventAcceptor
        Parameters:
        event - the event.
      • getBackground

        public Figure getBackground()
        Get the background figure.
        Returns:
        The background figure.
        See Also:
        setBackground(Figure)
      • getShape

        public java.awt.Shape getShape()
        Get the shape of this figure. This will be the shape of the background if there is one, otherwise a rectangle formed by taking the size of the contained pane and converting it with its transform.
        Specified by:
        getShape in interface Figure
        Specified by:
        getShape in class AbstractFigure
        Returns:
        the outline shape of this figure
      • getWrappedPane

        public CanvasPane getWrappedPane()
        Get the wrapped pane.
        Returns:
        The wrapped pane.
      • isClipEnabled

        public boolean isClipEnabled()
        Get the clipping enabled flag.
        Returns:
        True if clipping is enabled.
        See Also:
        setClipEnabled(boolean)
      • isEnabled

        public boolean isEnabled()
        Test the enabled flag of the wrapped pane. If true, then events on this figure will be passed to the wrapped pane; otherwise, the whole pane will be treated as though it were a single figure, and events passed to its event dispatcher, if it has one.
        Specified by:
        isEnabled in interface EventAcceptor
        Returns:
        the value of the enabled flag
        See Also:
        setClipEnabled(boolean)
      • paint

        public void paint​(java.awt.Graphics2D g)
        Paint the pane figure. The background (if any) is drawn first, then the wrapped pane. The contents of the pane are clipped to the background or to the size of the pane. (Note: the clip algorithm appears to change the way that lines are rendered in the presence of scaling. Don't know why...)
        Specified by:
        paint in interface VisibleComponent
        Specified by:
        paint in class AbstractFigure
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
      • paint

        public void paint​(java.awt.Graphics2D g,
                          java.awt.geom.Rectangle2D region)
        Paint the pane figure within the given region. The background (if any) is drawn first, then the wrapped pane. The contents of the pane are clipped to the background or to the size of the pane. (Note: the clip algorithm appears to change the way that lines are rendered in the presence of scaling. Don't know why...)
        Specified by:
        paint in interface VisibleComponent
        Overrides:
        paint in class AbstractFigure
        Parameters:
        g - The 2D graphics object that this object it to be painted upon.
        region - The region.
      • processLayerEvent

        protected void processLayerEvent​(LayerEvent event)
        Process a layer event. If the wrapped pane is not enabled, just return. Otherwise, generate a new layer event with coordinates in transform context of the wrapped pane and pass the new event to the pane.

        Currently, this methods also implements a simple technique to manage event-handling between the "inner" and "outer" panes. If this PaneWrapper has a selection interactor, and it is in the selection, then don't process the event. This means that the outer pane gets to handle all events if the wrapper has already been selected.

        Parameters:
        event - The layer event to be processed.
      • repaint

        public void repaint​(DamageRegion d)
        Accept notification that a repaint has occurred in the wrapped pane. This implementation forwards the notification to its parent.
        Specified by:
        repaint in interface CanvasComponent
        Overrides:
        repaint in class AbstractFigure
        Parameters:
        d - The region where a repaint has occurred.
      • setBackground

        public void setBackground​(Figure background)
        Set the background figure.
        Parameters:
        background - The background figure
        See Also:
        getBackground()
      • setClipEnabled

        public void setClipEnabled​(boolean flag)
        Set the clipping enabled flag. If true, the clip region will be set to the outline of the figure before painting the contents. This is on by default, but if the pane is well-behaved, this should be turned off as it seems to slow things down.
        Parameters:
        flag - The clipping enabled flag
        See Also:
        isClipEnabled()
      • setEnabled

        public void setEnabled​(boolean flag)
        Set the enabled flag of the wrapped pane. If true, then events on this figure will be passed to the wrapped pane; otherwise, the whole pane will be treated as though it were a single figure, and events passed to its event dispatcher, if it has one.
        Specified by:
        setEnabled in interface EventAcceptor
        Parameters:
        flag - True if the object is prepared to handle events with processEvent();
        See Also:
        isEnabled()
      • setTransform

        public void setTransform​(java.awt.geom.AffineTransform at)
        Set the transform of the internal pane, relative to the external one. This call will not affect the background figure.
        Parameters:
        at - The affine transform
      • transform

        public void transform​(java.awt.geom.AffineTransform at)
        Transform the figure with the supplied transform. The background, if any, will also be transformed.
        Specified by:
        transform in interface Figure
        Specified by:
        transform in class AbstractFigure
        Parameters:
        at - The transform to be used.
      • translate

        public void translate​(double x,
                              double y)
        Translate this pane wrapper the given distance.
        Specified by:
        translate in interface Figure
        Overrides:
        translate in class AbstractFigure
        Parameters:
        x - The x value to be moved.
        y - The y value to be moved.