edu.umd.cs.jazz.component
Class ZSwing

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZVisualComponent
              |
              +--edu.umd.cs.jazz.component.ZSwing
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, java.beans.PropertyChangeListener, java.io.Serializable, ZSerializable

public class ZSwing
extends ZVisualComponent
implements java.io.Serializable, java.beans.PropertyChangeListener

ZSwing is a Visual Component wrapper used to add Swing Components to a Jazz ZCanvas.

Example: adding a swing JButton to a ZCanvas:

     ZCanvas canvas = new ZCanvas();
     JButton button = new JButton("Button");
     swing = new ZSwing(canvas, button);
     leaf = new ZVisualLeaf(swing);
     canvas.getLayer().addChild(leaf);
 

 NOTE: ZSwing has the current limitation that it does not listen for
       Container events.  This is only an issue if you create a ZSwing
       and later add Swing components to the ZSwing's component hierarchy
       that do not have double buffering turned off or have a smaller font
       size than the minimum font size of the original ZSwing's component
       hierarchy.

       For instance, the following bit of code will give unexpected
       results:
       

  
            JPanel panel = new JPanel();
            ZSwing swing = new ZSwing(panel);
            JPanel newChild = new JPanel();
            newChild.setDoubleBuffered(true);
            panel.add(newChild);
       
 
NOTE: ZSwing is not properly ZSerializable, but it is java.io.Serializable.
Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.

Author:
Benjamin B. Bederson
, Lance E. Good
See Also:
Serialized Form

  


Field Summary
protected  javax.swing.JComponent component
          The Swing component that this Visual Component wraps
protected  java.awt.Font defaultFont
          The default font
protected  java.awt.Stroke defaultStroke
          The default stroke
protected  double minFontSize
          The minimum font size in the Swing hierarchy rooted at the component
protected  double renderCutoff
          The cutoff at which the Swing component is rendered greek
static java.lang.String VISUAL_COMPONENT_KEY
          Used as a hashtable key for this object in the Swing component's client properties.
 
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, inTransaction, invalidBounds, invalidVolatileBounds, listenerList, volatileBounds, volatileBounds_DEFAULT
 
Constructor Summary
ZSwing(ZCanvas zbc, javax.swing.JComponent component)
          Constructs a new visual component wrapper for the Swing component and adds the Swing component to the SwingWrapper component of the ZCanvas
 
Method Summary
 void computeBounds()
          Sets the Swing component's bounds to its preferred bounds unless it already is set to its preferred size.
 javax.swing.JComponent getComponent()
          Returns the Swing component that this visual component wraps
 void paint(java.awt.Graphics2D g2)
          Forwards the paint request to the Swing component to paint normally
 void paintAsGreek(java.awt.Graphics2D g2)
          Paints the Swing component as greek.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Listens for changes in font on components rooted at this ZSwing
 void render(ZRenderContext renderContext)
          Determines if the Swing component should be rendered normally or as a filled rectangle.
 void repaint(ZBounds repaintBounds)
          Repaint's the specified portion of this visual component Note that the input parameter may be modified as a result of this call.
 
Methods inherited from class edu.umd.cs.jazz.ZVisualComponent
addParent, duplicateObject, getNumParents, getParents, getParentsReference, getRoot, pick, pickBounds, removeParent, repaint, setState, trimToSize, updateBounds, updateObjectReferences, updateVolatility, writeObject, writeObjectRecurse
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
addClientProperty, addMouseListener, addMouseMotionListener, clone, computeVolatileBounds, dump, endTransaction, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getClientProperty, getHandles, getListenerList, getVolatileBounds, hasLisenerOfType, hasListenerOfType, hasMouseListener, markInTransaction, markNotInTransaction, processMouseEvent, putClientProperty, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds, startTransaction
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

renderCutoff

protected double renderCutoff
The cutoff at which the Swing component is rendered greek


component

protected javax.swing.JComponent component
The Swing component that this Visual Component wraps


minFontSize

protected double minFontSize
The minimum font size in the Swing hierarchy rooted at the component


defaultStroke

protected transient java.awt.Stroke defaultStroke
The default stroke


defaultFont

protected java.awt.Font defaultFont
The default font


VISUAL_COMPONENT_KEY

public static final java.lang.String VISUAL_COMPONENT_KEY
Used as a hashtable key for this object in the Swing component's client properties.

See Also:
Constant Field Values
Constructor Detail

ZSwing

public ZSwing(ZCanvas zbc,
              javax.swing.JComponent component)
Constructs a new visual component wrapper for the Swing component and adds the Swing component to the SwingWrapper component of the ZCanvas

Parameters:
zbc - The ZCanvas to which the Swing component will be added
component - The swing component to be wrapped
Method Detail

render

public void render(ZRenderContext renderContext)
Determines if the Swing component should be rendered normally or as a filled rectangle.

The transform, clip, and composite will be set appropriately when this object is rendered. It is up to this object to restore the transform, clip, and composite of the Graphics2D if this node changes any of them. However, the color, font, and stroke are unspecified by Jazz. This object should set those things if they are used, but they do not need to be restored.

Overrides:
render in class ZVisualComponent
Parameters:
renderContext - Contains information about current render.
See Also:
ZVisualComponent.paint(Graphics2D)

paintAsGreek

public void paintAsGreek(java.awt.Graphics2D g2)
Paints the Swing component as greek.

Parameters:
g2 - The graphics used to render the filled rectangle

paint

public void paint(java.awt.Graphics2D g2)
Forwards the paint request to the Swing component to paint normally

Overrides:
paint in class ZVisualComponent
Parameters:
g2 - The graphics this visual component should pass to the Swing component
See Also:
ZVisualComponent.render(ZRenderContext)

repaint

public void repaint(ZBounds repaintBounds)
Repaint's the specified portion of this visual component Note that the input parameter may be modified as a result of this call.

Overrides:
repaint in class ZVisualComponent
Parameters:
repaintBounds - The bounding box to repaint within this component
See Also:
ZVisualComponent.repaint()

computeBounds

public void computeBounds()
Sets the Swing component's bounds to its preferred bounds unless it already is set to its preferred size. Also updates the visual components copy of these bounds

Overrides:
computeBounds in class ZSceneGraphObject

getComponent

public javax.swing.JComponent getComponent()
Returns the Swing component that this visual component wraps

Returns:
The Swing component that this visual component wraps

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Listens for changes in font on components rooted at this ZSwing

Specified by:
propertyChange in interface java.beans.PropertyChangeListener


Copyright � 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.