diva.canvas
Class PaneWrapper

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by diva.canvas.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 EventAccepter. It forwards events to the internal pane.

Version:
$Id: PaneWrapper.java 48923 2008-03-25 21:19:29Z cxh $
Author:
John Reekie
Accepted Rating:
Red

Field Summary
private  Figure _background
          The background figure
private  boolean _clipEnabled
          The flag saying whether to clip.
private  CanvasPane _wrappedPane
          The contained pane.
 
Constructor Summary
PaneWrapper(CanvasPane pane)
          Create a new pane figure with the given pane.
 
Method Summary
 void dispatchEvent(java.awt.AWTEvent event)
          Dispatch an AWT event on this pane figure.
 Figure getBackground()
          Get the background figure.
 java.awt.Shape getShape()
          Get the shape of this figure.
 CanvasPane getWrappedPane()
          Get the wrapped pane
 boolean isClipEnabled()
          Get the clipping enabled flag.
 boolean isEnabled()
          Test the enabled flag of the wrapped pane.
 void paint(java.awt.Graphics2D g)
          Paint the pane figure.
 void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D region)
          Paint the pane figure within the given region.
protected  void processLayerEvent(LayerEvent event)
          Process a layer event.
 void repaint(DamageRegion d)
          Accept notification that a repaint has occurred in the wrapped pane.
 void setBackground(Figure background)
          Set the background figure.
 void setClipEnabled(boolean flag)
          Set the clipping enabled flag.
 void setEnabled(boolean flag)
          Set the enabled flag of the wrapped pane.
 void setTransform(java.awt.geom.AffineTransform at)
          Set the transform of the internal pane, relative to the external one.
 void transform(java.awt.geom.AffineTransform at)
          Transform the figure with the supplied transform.
 void translate(double x, double y)
          Translate this pane wrapper the given distance.
 
Methods inherited from class diva.canvas.AbstractFigure
contains, getBounds, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, hit, intersects, isVisible, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.canvas.CanvasComponent
getParent, getTransformContext, repaint
 

Field Detail

_clipEnabled

private boolean _clipEnabled
The flag saying whether to clip.


_wrappedPane

private CanvasPane _wrappedPane
The contained pane.


_background

private Figure _background
The background figure

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().

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

getBackground

public Figure getBackground()
Get the background 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

getWrappedPane

public CanvasPane getWrappedPane()
Get the wrapped pane


isClipEnabled

public boolean isClipEnabled()
Get the clipping enabled flag.


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

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

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

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.


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

setBackground

public void setBackground(Figure background)
Set the background figure.


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.


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

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.


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

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