edu.umd.cs.jazz
Class ZSelectionGroup

java.lang.Object
  |
  +--edu.umd.cs.jazz.ZSceneGraphObject
        |
        +--edu.umd.cs.jazz.ZNode
              |
              +--edu.umd.cs.jazz.ZGroup
                    |
                    +--edu.umd.cs.jazz.ZVisualGroup
                          |
                          +--edu.umd.cs.jazz.ZSelectionGroup
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, ZSerializable

public class ZSelectionGroup
extends ZVisualGroup
implements ZSerializable, java.io.Serializable

ZSelectionGroup is a visual group node that provides functionality for specifying selection. Inserting a selection group in the scenegraph will visually select its subtree. It has utility methods for selecting and unselecting nodes, and for determining the selected nodes in a sub-tree. It manages a visual component that actually represents the selection, and shows a selected node by surrounding its children with a 1 pixel wide line. To give selection a new visual look, an application can set the SelectionComponentFactory setSelectionComponentFactory(edu.umd.cs.jazz.ZSelectionGroup.SelectionComponentFactory)

The primary visual component generation has changed to use a factory. This allows a developer to more easily change the look of all selected components. The following code demonstrates changing the default selection to be an ellipse, rather than a rectangle:

      ZSelectionGroup.setSelectionComponentFactory(new
                             ZSelectionGroup.SelectionComponentFactory() {
          public ZVisualComponent createSelectionComponent() {
              return new SelectionEllipse();
          }
      });
 
with the following example implementation of SelectionEllipse:
      public class SelectionEllipse extends ZVisualComponent {

          public SelectionEllipse() { }

          public boolean pick(Rectangle2D pickRect, ZSceneGraphPath path) {
              return false; // pick handled by SelectionGroup
          }

          public void render(ZRenderContext ctx) {
              Graphics2D g2 = ctx.getGraphics2D();
              double mag = ctx.getCompositeMagnification();
              double sz = 1.0 / mag;
              ZNode p = getParents()[0];
              if (p instanceof ZSelectionGroup) {
                  ZSelectionGroup g = (ZSelectionGroup)p;
                  Ellipse2D e = new Ellipse2D.Double();
                  e.setFrame(g.getBounds());
                  double x = e.getX();
                  double y = e.getY();
                  double w = e.getWidth();
                  double h = e.getHeight();

                  // don't draw very small selection objects
                  if (w * mag < 2 || h * mag < 2) return;

                  // shrink bounds by 1 pixel to ensure I am
                  // inside them
                  e.setFrame(x + sz, y + sz, w - sz*2, h - sz*2);

                  g2.setStroke(new BasicStroke((float)sz));
                  g2.setColor(g.getPenColor());
                  g2.draw(e);
              }
          }

          // SelectionEllipse's have no logical bounds.
          protected void computeBounds() {
      }
 

ZSceneGraphEditor provides a convenience mechanism to locate, create and manage nodes of this type.

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:
Ben Bederson
See Also:
Serialized Form

Inner Class Summary
static interface ZSelectionGroup.SelectionComponentFactory
           
 
Field Summary
static java.awt.Color penColor_DEFAULT
           
 
Fields inherited from class edu.umd.cs.jazz.ZVisualGroup
visualComponentPickable_DEFAULT
 
Fields inherited from class edu.umd.cs.jazz.ZGroup
children, childrenFindable_DEFAULT, childrenPickable_DEFAULT, hasOneChild_DEFAULT
 
Fields inherited from class edu.umd.cs.jazz.ZNode
findable_DEFAULT, pickable_DEFAULT, savable_DEFAULT, selectable_DEFAULT
 
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject
bounds, listenerList, volatileBounds, volatileBounds_DEFAULT
 
Constructor Summary
ZSelectionGroup()
          Constructs a new ZSelectionGroup.
ZSelectionGroup(ZNode child)
          Constructs a new select group node with the specified node as a child of the new group.
 
Method Summary
 void addAuxiliaryVisualComponent(ZVisualComponent visualComponent)
          Adds an auxiliary visual component to this selection group
 void clearAuxiliaryVisualComponents()
          Remove all auxiliary visual components from this selection group.
 ZVisualComponent[] getAuxiliaryVisualComponents()
          Return the auxiliary visual components associated with this selection group.
 java.awt.Color getPenColor()
          Get the pen color that is used to render the selection.
static java.util.ArrayList getSelectedNodes(ZCamera camera)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.getSelectedNodes(ZCamera)
static java.util.ArrayList getSelectedNodes(ZNode node)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.getSelectedNodes(ZNode)
static boolean isSelected(ZNode node)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.isSelected(ZNode)
 boolean pick(java.awt.geom.Rectangle2D rect, ZSceneGraphPath path)
          ZSelectionGroup overrides this method to check whether any of the auxiliary visual components have been picked.
 void removeAuxiliaryVisualComponent(ZVisualComponent visualComponent)
          Remove an auxiliary visual component from this selection group.
 void render(ZRenderContext renderContext)
          Renders this node which results in the node's visual component getting rendered, followed by its children getting rendered.
static ZSelectionGroup select(ZNode node)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.select(ZNode)
 void setAuxiliaryVisualComponent(ZVisualComponent visualComponent)
          Set the auxiliary visual component associated with this selection group.
 void setPenColor(java.awt.Color color)
          Set the pen color that is used to render the selection.
static void setSelectionComponentFactory(ZSelectionGroup.SelectionComponentFactory newFactory)
          Set the SelectionComponentFactory used to generate visual components for selected objects
 void trimToSize()
          Trims the capacity of the array that stores the parents list points to the actual number of points.
static void unselect(ZNode node)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.unselect(ZNode)
static void unselectAll(ZCamera camera)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.unselectAll(ZCamera)
static void unselectAll(ZNode node)
          Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.unselectAll(ZNode)
protected  void updateVolatility()
          Internal method to compute and cache the volatility of a node, to recursively call the parents to compute volatility.
 void writeObject(ZObjectOutputStream out)
          Write out all of this object's state.
 void writeObjectRecurse(ZObjectOutputStream out)
          Specify which objects this object references in order to write out the scenegraph properly
 
Methods inherited from class edu.umd.cs.jazz.ZVisualGroup
computeBounds, duplicateObject, getBackVisualComponent, getBackVisualComponentBounds, getBackVisualComponentGlobalBounds, getFrontVisualComponent, getFrontVisualComponentBounds, getFrontVisualComponentGlobalBounds, getShallowBounds, isBackVisualComponentPickable, isFrontVisualComponentPickable, setBackVisualComponent, setBackVisualComponentPickable, setFrontVisualComponent, setFrontVisualComponentPickable, setState
 
Methods inherited from class edu.umd.cs.jazz.ZGroup
addChild, addChildImpl, addChildren, addGroupListener, childAddedNotification, childRemovedNotification, dump, extract, findNodes, getChild, getChildren, getChildrenFindable, getChildrenIterator, getChildrenPickable, getChildrenReference, getNumChildren, getVolatileBounds, hasOneChild, indexOf, insertAbove, iterator, lower, lowerTo, raise, raiseTo, removeAllChildren, removeChild, removeChild, removeChild, removeChildImpl, removeGroupListener, removeNodeListener, setChildrenFindable, setChildrenPickable, setHasOneChild, updateHasNodeListener
 
Methods inherited from class edu.umd.cs.jazz.ZNode
addClientProperty, addNodeListener, editor, getClientProperty, getGlobalBounds, getGlobalToLocalTransform, getLocalToGlobalTransform, getParent, getRoot, globalToLocal, globalToLocal, hasNodeListener, isAncestorOf, isDescendentOf, isFindable, isPickable, isSavable, isSelectable, localToGlobal, localToGlobal, lower, lowerTo, percolateEventUpSceneGraph, putClientProperty, raise, raiseTo, remove, repaint, repaint, repaint, reparent, replaceWith, setEditorFactory, setFindable, setParent, setPickable, setSavable, setSelectable, updateBounds, updateObjectReferences, writeReplace
 
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject
addMouseListener, addMouseMotionListener, clone, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getListenerList, hasLisenerOfType, hasMouseListener, processMouseEvent, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.umd.cs.jazz.io.ZSerializable
setState
 

Field Detail

penColor_DEFAULT

public static final java.awt.Color penColor_DEFAULT
Constructor Detail

ZSelectionGroup

public ZSelectionGroup()
Constructs a new ZSelectionGroup. The node must be attached to a live scenegraph (a scenegraph that is currently visible) in order for it to be visible.

ZSelectionGroup

public ZSelectionGroup(ZNode child)
Constructs a new select group node with the specified node as a child of the new group.
Parameters:
child - Child of the new group node.
Method Detail

addAuxiliaryVisualComponent

public void addAuxiliaryVisualComponent(ZVisualComponent visualComponent)
Adds an auxiliary visual component to this selection group
Parameters:
visualComponent - The auxiliary visual component to be added

removeAuxiliaryVisualComponent

public void removeAuxiliaryVisualComponent(ZVisualComponent visualComponent)
Remove an auxiliary visual component from this selection group. If this group didn't already contains this component, then nothing happens.
Parameters:
visualComponent - The visual component to be removed.

setAuxiliaryVisualComponent

public void setAuxiliaryVisualComponent(ZVisualComponent visualComponent)
Set the auxiliary visual component associated with this selection group. If this node previously had any auxiliary visual components associated with it, then those components will be replaced with the new one.
Parameters:
visualComponent - The new visual component for this group.

getAuxiliaryVisualComponents

public final ZVisualComponent[] getAuxiliaryVisualComponents()
Return the auxiliary visual components associated with this selection group.
Returns:
The auxiliary visual components

clearAuxiliaryVisualComponents

public void clearAuxiliaryVisualComponents()
Remove all auxiliary visual components from this selection group.

updateVolatility

protected void updateVolatility()
Internal method to compute and cache the volatility of a node, to recursively call the parents to compute volatility. All parents of this node are also volatile when this is volatile. A leaf is volatile if either the node or any of its visual components are volatile.
Overrides:
updateVolatility in class ZVisualGroup
See Also:
ZSceneGraphObject.setVolatileBounds(boolean), ZGroup.getVolatileBounds()

getSelectedNodes

public static java.util.ArrayList getSelectedNodes(ZNode node)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.getSelectedNodes(ZNode)


getSelectedNodes

public static java.util.ArrayList getSelectedNodes(ZCamera camera)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.getSelectedNodes(ZCamera)


select

public static ZSelectionGroup select(ZNode node)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.select(ZNode)


unselect

public static void unselect(ZNode node)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.unselect(ZNode)


unselectAll

public static void unselectAll(ZNode node)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.unselectAll(ZNode)


unselectAll

public static void unselectAll(ZCamera camera)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.unselectAll(ZCamera)


isSelected

public static boolean isSelected(ZNode node)
Deprecated. as of Jazz 1.1, replaced by ZSelectionManager.isSelected(ZNode)


getPenColor

public java.awt.Color getPenColor()
Get the pen color that is used to render the selection.
Returns:
the pen color.

setPenColor

public void setPenColor(java.awt.Color color)
Set the pen color that is used to render the selection.
Parameters:
color - the pen color, or null if none.

render

public void render(ZRenderContext renderContext)
Renders this node which results in the node's visual component getting rendered, followed by its children getting rendered.

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 ZVisualGroup
Parameters:
renderContext - The graphics context to use for rendering.

pick

public boolean pick(java.awt.geom.Rectangle2D rect,
                    ZSceneGraphPath path)
ZSelectionGroup overrides this method to check whether any of the auxiliary visual components have been picked.
Overrides:
pick in class ZVisualGroup
Parameters:
rect - The picking rectangle
path - The picking path up to this node
Returns:
True if this node has been picked

setSelectionComponentFactory

public static void setSelectionComponentFactory(ZSelectionGroup.SelectionComponentFactory newFactory)
Set the SelectionComponentFactory used to generate visual components for selected objects
Parameters:
componentFactory - The new SelectionComponentFactory

writeObject

public void writeObject(ZObjectOutputStream out)
                 throws java.io.IOException
Write out all of this object's state.
Specified by:
writeObject in interface ZSerializable
Overrides:
writeObject in class ZVisualGroup
Parameters:
out - The stream that this object writes into

writeObjectRecurse

public void writeObjectRecurse(ZObjectOutputStream out)
                        throws java.io.IOException
Specify which objects this object references in order to write out the scenegraph properly
Specified by:
writeObjectRecurse in interface ZSerializable
Overrides:
writeObjectRecurse in class ZVisualGroup
Parameters:
out - The stream that this object writes into

trimToSize

public void trimToSize()
Trims the capacity of the array that stores the parents list points to the actual number of points. Normally, the parents list arrays can be slightly larger than the number of points in the parents list. An application can use this operation to minimize the storage of a parents list.
Overrides:
trimToSize in class ZGroup


Copyright © 2001 by University of Maryland, College Park, MD 20742, USA All rights reserved.