gumbo.graphic.impl.swing
Class SwingSpaceNode

java.lang.Object
  |
  +--gumbo.util.AbstractDisposable
        |
        +--gumbo.util.relation.AbstractTreeNodeDelegator
              |
              +--gumbo.graphic.space.AbstractSpaceNode
                    |
                    +--gumbo.graphic.impl.swing.SwingSpaceNode
All Implemented Interfaces:
AxisBound3Boundable, BoundableGraphic, Disposable, Graphic, GraphicGeometry, GraphicPresence, GraphicResource, IntersectableGraphic, java.io.Serializable, SpaceNode, TransformNode, TranslationNode
Direct Known Subclasses:
SwingGraphView, SwingListView, SwingShape, SwingTreeView

public abstract class SwingSpaceNode
extends AbstractSpaceNode
implements GraphicPresence, TranslationNode, AxisBound3Boundable, IntersectableGraphic

An abstract SpaceNode adapter for an AWT/Swing Component. In AWT/Swing a Component is displayable and acts like a content transforming translation node with an integral geometry and bound. Also, the space origin is at the upper-left corner of its bound. This adpater redefines the origin to be the center of the bound, which is consistent with most other native graphic systems and graphics in general. TODO: Should GraphicPresence be left for a more concrete class?

Version:
$Revision: 1.1 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.
See Also:
Serialized Form

Constructor Summary
SwingSpaceNode()
          Creates an instance.
 
Method Summary
 boolean canIntersectGraphic(GraphicGeometry intersector)
          Default implementation: Returns true if the intersector is a Point3, the intersector graphic is a Component, and this and the intersector graphic have the same root Component.
 java.lang.Object getGraphic()
          Throws an exception if graphic not yet initialized.
 AxisBound3 getGraphicAxisBound3(AxisBound3 retVal)
          Default implementation: Calls graphic.getBounds() for the bounds.
 SpaceNode getGraphicLocalSpace()
          Returns the space node representing the local reference space for this geometry.
 Matrix4 getGraphicTransform(Matrix4 retVal)
          Returns a matrix describing the transform state of this node.
 Point3 getGraphicTranslation(Point3 retVal)
          Default implementation: Calls getGraphicAxisBound3() and returns its center point.
protected  void implDispose()
          Disposes space tree child nodes, then disposes the super.
protected  SwingSpaceNode initSwingSpaceNode(java.awt.Component graphic)
          Used by subclasses and serialization to initialize this object.
 boolean intersectGraphic(GraphicGeometry intersector)
          Default implementation: Transforms intersector to the local space using SwingSpaceMapper.INSTANCE, then calls this graphic's Component.contains(x, y) method for the intersection test.
 boolean isSpaceTransforming()
          Returns true if this is a space transforming node (transforms its local space, leaving its contents unchanged), and false if it is content transforming (transforms its contents, leaving its local space unchanged).
 void prepareGraphicPresence()
          Informs this graphic entity that, in anticipation of realization, it should update as needed those aspects of its graphic state (geometry, appearance) and that of any dependents (siblings, descendants) that can affect its presentation.
 void realizeGraphicPresence()
          Informs this graphic entity that external (sibling, ancestor) and internal (self, descendant) state changes that can affect its presentation are complete and assumed valid, and that it should update its presentation as needed to be consistent with its graphic state.
 void setGraphicTranslation(Point3 trans)
          Default implementation: Calls getGraphicTranslation(), computes the relative offset, and adds the offset to the current graphic position using graphic.getLocation() and graphic.setLocation().
 
Methods inherited from class gumbo.graphic.space.AbstractSpaceNode
getGraphicSpaceTree
 
Methods inherited from class gumbo.util.relation.AbstractTreeNodeDelegator
getTreeNodeDelegate, newTreeNodeDelegate
 
Methods inherited from class gumbo.util.AbstractDisposable
dispose, isDisposed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gumbo.util.Disposable
dispose, isDisposed
 
Methods inherited from interface gumbo.graphic.space.SpaceNode
getGraphicSpaceTree
 

Constructor Detail

SwingSpaceNode

public SwingSpaceNode()
Creates an instance. Must call initSwingSpaceNode() before using this object.

Method Detail

initSwingSpaceNode

protected final SwingSpaceNode initSwingSpaceNode(java.awt.Component graphic)
Used by subclasses and serialization to initialize this object. Should be called only after graphic initialization is complete. Throws an exception if the graphic is null or different from the initial one.

Parameters:
graphic - Reference to a native graphic. Possibly this proxy but never null.
Returns:
Reference to this object (which facilitates inline construction). Never null.

getGraphicTranslation

public Point3 getGraphicTranslation(Point3 retVal)
Default implementation: Calls getGraphicAxisBound3() and returns its center point.

Specified by:
getGraphicTranslation in interface TranslationNode
Parameters:
retVal - Return value object. The translation. Never null.
Returns:
Reference to retVal. Never null.

setGraphicTranslation

public void setGraphicTranslation(Point3 trans)
Default implementation: Calls getGraphicTranslation(), computes the relative offset, and adds the offset to the current graphic position using graphic.getLocation() and graphic.setLocation().

Specified by:
setGraphicTranslation in interface TranslationNode
Parameters:
trans - Value of the transformation. Never null.

getGraphicTransform

public final Matrix4 getGraphicTransform(Matrix4 retVal)
Description copied from interface: TransformNode
Returns a matrix describing the transform state of this node. If this is a space transforming node, pre-multiplying geometry in the local space by this matrix transforms it to the parent node's local space (or absolute space if this node is a root). If this is a contents transforming node, pre-multiply geometry in a child node's local space by this matrix transforms it to the local space.

Specified by:
getGraphicTransform in interface TransformNode
Parameters:
retVal - Return value object. The matrix. Never null.
Returns:
Reference to retVal. Never null.

isSpaceTransforming

public final boolean isSpaceTransforming()
Description copied from interface: TransformNode
Returns true if this is a space transforming node (transforms its local space, leaving its contents unchanged), and false if it is content transforming (transforms its contents, leaving its local space unchanged).

Specified by:
isSpaceTransforming in interface TransformNode
Returns:
The transform node type.

getGraphicAxisBound3

public AxisBound3 getGraphicAxisBound3(AxisBound3 retVal)
Default implementation: Calls graphic.getBounds() for the bounds.

Specified by:
getGraphicAxisBound3 in interface AxisBound3Boundable
Parameters:
retVal - Return value object. The bound. Never null.
Returns:
Reference to retVal. Never null.

canIntersectGraphic

public boolean canIntersectGraphic(GraphicGeometry intersector)
Default implementation: Returns true if the intersector is a Point3, the intersector graphic is a Component, and this and the intersector graphic have the same root Component.

Specified by:
canIntersectGraphic in interface IntersectableGraphic
Parameters:
intersector - Value of the intersector. Never null.
Returns:
True if the intersection is supported.

intersectGraphic

public boolean intersectGraphic(GraphicGeometry intersector)
Default implementation: Transforms intersector to the local space using SwingSpaceMapper.INSTANCE, then calls this graphic's Component.contains(x, y) method for the intersection test.

Specified by:
intersectGraphic in interface IntersectableGraphic
Parameters:
intersector - Value of the intersector. Never null.
Returns:
True if an intersection occurs.

getGraphicLocalSpace

public final SpaceNode getGraphicLocalSpace()
Description copied from interface: GraphicGeometry
Returns the space node representing the local reference space for this geometry.

Specified by:
getGraphicLocalSpace in interface GraphicGeometry
Returns:
Reference to the space. If null, absolute space.

prepareGraphicPresence

public void prepareGraphicPresence()
Description copied from interface: GraphicPresence
Informs this graphic entity that, in anticipation of realization, it should update as needed those aspects of its graphic state (geometry, appearance) and that of any dependents (siblings, descendants) that can affect its presentation. Does not actually affect the presentation (see realizeGraphicDisplay()). Allows for efficient batching of graphic state changes.

Specified by:
prepareGraphicPresence in interface GraphicPresence

realizeGraphicPresence

public void realizeGraphicPresence()
Description copied from interface: GraphicPresence
Informs this graphic entity that external (sibling, ancestor) and internal (self, descendant) state changes that can affect its presentation are complete and assumed valid, and that it should update its presentation as needed to be consistent with its graphic state. Allows for efficient batching of graphic state realizations.

Specified by:
realizeGraphicPresence in interface GraphicPresence

getGraphic

public final java.lang.Object getGraphic()
Throws an exception if graphic not yet initialized.

Specified by:
getGraphic in interface Graphic
Overrides:
getGraphic in class AbstractSpaceNode
Returns:
The target graphic object. Possibly this object (self-proxy, direct implementation), but never null.

implDispose

protected void implDispose()
Disposes space tree child nodes, then disposes the super.

Overrides:
implDispose in class AbstractTreeNodeDelegator