edu.neu.ccs.gui
Class Zoo

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byedu.neu.ccs.gui.DisplayPanel
                      extended byedu.neu.ccs.gui.ZooContainer
                          extended byedu.neu.ccs.gui.Zoo
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants

public class Zoo
extends ZooContainer

ZooContainer allowing selection and direct manipulation of components.

A zoo is a container used to contain components that can be moved and resized through direct manipulation. In this way, a Zoo is like a desktop for components.

An individual component, or a collection of components, can be selected through direct manipulation or through method calls. A selected component is painted with a box surrounding its bounds. Selected components can be retrieved using various methods described below. A component is selected if it is clicked with the mouse. To select multiple components, hold the Shift key when selecting the components.

Components in a zoo are called child items. All child items are contained at the top level of the zoo. Components can be grouped into a ZooGroup, which is treated as a single entity in the zoo. Components in a zoo that are contained within a group are called items. Since a group can be recursively contained within a group, there can be any number of levels to the containment hierarchy for items in a zoo. Only the top level items are considered to be child items. A zoo could have only one child item, but many items, if the single child item is a group of components.

If a zoo is restricting the bounds of its components, it will not allow a component to be moved or resized so that the component is not completely contained within the bounds of the zoo. If a zoo is not restricting the bounds of its components, a component can be moved or resized to any extent. A zoo restricts bounds by default.

If a zoo is in design mode, a child item can be moved and resized by clicking and dragging a side or corner of the component as noted by a rectangular anchor. An anchor is not shown if the component can not be resized. A component can not be resized to a width or height out of the limits of its minimum and maximum sizes. If a zoo is not in design mode, all of its items behave normally. A zoo is in design mode by default.

A 3rd dimension -- z-order -- is applied to the child items in a zoo. This z-order determines the order in which components are painted and will cause one of two overlapping components to appear to be on top of the other. Several methods described below can modify the z-order of child items contained in a zoo. Items in a group reside at the z-order of the group itself. The z-order within a group determines the order in which the components of the group are painted.

Technical details:

This panel assumes an AbsoluteLayout. Behavior is undefined if this panel is set to have a layout other than an AbsoluteLayout.

A grouped component resized through direct manipulation will appear to scale in size as the group is resized, whether or not the component will actually scale in size when the resize is completed. If the parent container for the grouped component does not scale its contents, the grouped component will snap back to its original size when the resize is completed.

Since:
1.1
Version:
2.2
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 Action BRING_TO_FRONT_ACTION
          Action to bring the first selected component in this zoo to the front of the z-order.
private  Stroke dashedStroke
          Stroke used to paint the lasso.
 Action DESELECT_ALL_ACTION
          Action to deselect all components in this zoo.
protected  boolean designMode
          Whether or not this zoo is in design mode.
protected  Color focusedHighlightColor
          Highlight color of selected components for when this zoo has the keyboard focus.
 Action GROUP_SELECTED_COMPONENTS_ACTION
          Action to group all selected components in this zoo.
protected  Hashtable laminateTable
          Table mapping components to laminates.
protected  Point lassoLast
          Last point used to calculate the current lasso.
protected  Point lassoStart
          Point at which the current lasso originated.
protected  MouseActionAdapter mouseAdapter
          Mouse action adapter for this zoo.
 Action MOVE_DOWN_ACTION
          Action to move the first selected component in this zoo to the next deeper z-order position.
 Action MOVE_UP_ACTION
          Action to move the first selected component in this zoo to the next higher z-order position.
protected  boolean moveable
          Whether or not the child items in this zoo can be moved.
protected  boolean resizeable
          Whether or not the child items in this zoo can be resized.
protected  boolean restrictingBounds
          Whether or not this zoo is restricting its child components' bounds.
 Action SELECT_ALL_ACTION
          Action to select all components in this zoo.
protected  ListSelectionModel selectionModel
          Selection model for this zoo.
 Action SEND_TO_BACK_ACTION
          Action to send the first selected component in this zoo to the back of the z-order.
 Action SET_DESIGN_MODE_OFF_ACTION
          Action to turn off design mode for this zoo.
 Action SET_DESIGN_MODE_ON_ACTION
          Action to turn on design mode for this zoo.
 Action TOGGLE_DESIGN_MODE_ACTION
          Action to toggle design mode for this zoo.
protected  Color unfocusedHighlightColor
          Highlight color of selected components for when this zoo does not have the keyboard focus.
 Action UNGROUP_SELECTED_COMPONENT_ACTION
          Action to ungroup the first selected component in this zoo, as long as it is an instance of ZooGroup.
 Action UNGROUP_SELECTED_COMPONENTS_ACTION
          Action to ungroup all selected components in this zoo.
 
Fields inherited from class edu.neu.ccs.gui.DisplayPanel
background, codec, CODEC
 
Fields inherited from class javax.swing.JPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface edu.neu.ccs.gui.Displayable
DEFAULT_VIEW_STATE, VIEW_STATE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Zoo()
          Constructs a new zoo that restricts its child components' bounds to be contained within the bounds of this zoo.
Zoo(boolean isRestricting)
          Constructs a new zoo that either restricts its child components' bounds or does not restrict its child components' bounds.
 
Method Summary
 Component addChildItem(Component c)
          Adds the given component to this zoo at the highest z-order position and prepares the component for direct manipulation, grouping, and selection.
 Component addChildItem(Component c, int z)
          Adds the given component to this zoo at the given z-order position and prepares the component for direct manipulation, grouping, and selection.
private  Component addChildItemImpl(Component c, int z)
          Adds the given component at the given z-order position.
 void addToSelection(Component c)
          Adds the given top-level component to the list of selected components in this zoo.
 boolean allowsMove()
          Returns whether or not the child items in this zoo can be moved using direct manipulation.
 boolean allowsResize()
          Returns whether or not the child items in this zoo can be resized using direct manipulation.
protected  Color computeUnfocusedHighlightColor(Color c)
          Computes a suitable color of the highlight of selected components for when this zoo does not have focus, from the given color.
protected  Laminate createLaminateFor(Component c)
          Returns a new laminate for the given component.
 void deselectAll()
          Deselects all top-level components in this zoo.
protected  void endLasso(MouseEvent evt)
          Ends the current lasso given the mouse event that prompted its destruction.
 Component getChildItem(int z)
          Returns the top-level component in this zoo at the given z-order.
 int getChildItemCount()
          Returns the number of top-level components in this container.
 Component[] getChildItems()
          Returns an array containing all of the top-level components in this zoo.
 Color getFocusedHighlightColor()
          Returns the color used to highlight a selected component when this zoo has the keyboard focus.
 Component[] getItems()
          Returns an array containing all of the components contained in this zoo, including components that are nested within groups.
 Laminate getLaminateFor(Component c)
          Returns the laminate for the given component, or null if the given component is not a child item of this zoo.
protected  Rectangle getLassoBounds()
          Returns the bounds of the current lasso, or null if there is no current lasso.
 Component getSelectedComponent()
          Returns the selected component in this zoo at the highest z-order position, or null if the selection is empty.
 Component getSelectedComponent(int index)
          Returns the selected component in this zoo at the given index into the list of selected components, or null if the selection is empty.
 int getSelectedComponentCount()
          Returns the number of selected components in this zoo.
 Component[] getSelectedComponents()
          Returns an array containing the selected components in this zoo in the order of their z-order positions, or a zero-length array if the selection is empty.
 ListSelectionModel getSelectionModel()
          Returns the selection model for this zoo.
 Color getUnfocusedHighlightColor()
          Returns the color used to highlight a selected component when this zoo does not have the keyboard focus.
 ZooGroup group(Component[] components)
          Groups the given top-level components of this zoo.
 ZooGroup groupSelection()
          Groups the currently selected components.
protected  void installFocusAdapter()
          Installs the focus adapter for this zoo.
protected  void installMouseAdapter()
          Installs the mouse adapter for this zoo.
protected  void installSelectionModel()
          installs the selection model for this zoo.
 boolean isFocusTraversable()
          Returns true if this zoo is in design mode, or false otherwise.
 boolean isInDesignMode()
          Returns whether or not this zoo is in design mode.
 boolean isManagingFocus()
          Returns true if this zoo is in design mode, or false otherwise.
 boolean isRestrictingBounds()
          Returns whether or not this zoo is restricting its child components' bounds to be contained within the bounds of this zoo.
 boolean isSelectionEmpty()
          Returns whether or not the selection is empty.
 int moveToZOrder(Component c, int newZ)
          Moves the given component to the given z-order position.
protected  void paintComponent(Graphics g)
          Paints this component to the given graphics context.
 void removeAllItems()
          Removes all of the components from this container.
 Component removeChildItem(Component c)
          Removes the given top-level component from this zoo.
 Component removeChildItem(int z)
          Removes the top-level component at the given z-order position from this zoo.
private  Component removeChildItemImpl(Component c)
          Removes the given component from this zoo.
private  void removeComponentImpl(Component c, int z)
          Removes the given component and its laminate.
 void removeFromSelection(Component c)
          Removes the given top-level component from the list of selected components in this zoo.
protected  void resizeLasso(MouseEvent evt)
          Resizes the current lasso given the mouse event that prompted its resize.
 void selectAll()
          Selects all top-level components in this zoo.
 void selectOnly(Component c)
          Sets the selection for this zoo to only the the given component.
 void setAllowsMove(boolean allowsMove)
          Sets whether or not the child items of this zoo can be moved using direct manipulation.
 void setAllowsResize(boolean allowsResize)
          Sets whether or not the child items of this zoo can be resized using direct manipulation.
 void setFocusedHighlightColor(Color c)
          Sets the color used to highlight a selected component when this zoo has the keyboard focus.
 void setInDesignMode(boolean designing)
          Sets whether or not this zoo is in design mode.
 void setRestrictingBounds(boolean isRestricting)
          Sets whether or not this zoo is restricting its child components' bounds to be contained within the bounds of this zoo.
 void setSelectedComponents(Component[] c)
          Sets the selection for this zoo to exactly the components in the given array that are not-null and are contained at top-level in this zoo.
 void setUnfocusedHighlightColor(Color c)
          Sets the color used to highlight a selected component when this zoo does not have the keyboard focus.
protected  void startLasso(MouseEvent evt)
          Starts a new lasso given the mouse event that prompted its origination.
 Component[] ungroup(ZooGroup group)
          Disassociates the components in the given group.
 void ungroupSelection()
          Ungroups the currently selected components.
protected  void updateDesignModeActions()
          Enables or disables design mode actions based on the current design mode.
protected  void updateSelection()
          Selects or deselects the appropriate components based on the state of the selection model.
protected  void updateSelectionActions()
          Enables or disables selection actions based on the current selection.
private  int zOrderToIndex(int z)
          Returns the Java container index of the component at the given z-order.
 
Methods inherited from class edu.neu.ccs.gui.ZooContainer
bringToFront, findChildItemAt, findChildItemAt, findItemAt, findItemAt, getAncestorZoo, getItem, getItemCount, getParentContainer, getRootZoo, inverseGetChildItem, inverseGetItem, moveDown, moveUp, nextDeeperInZOrder, nextHigherInZOrder, sendToBack
 
Methods inherited from class edu.neu.ccs.gui.DisplayPanel
add, add, add, add, add, addBorder, addObject, addObject, addObject, addObject, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, compoundBorder, compoundBorder, dataMalformed, emptyBorder, emptyBorder, emptyBorder, endAlert, etchBorderLowered, etchBorderLowered, etchBorderLowered, etchBorderRaised, etchBorderRaised, etchBorderRaised, frame, frame, frame, frame, frame, frame, generalDialog, generalDialog, generalDialog, generalDialog, getCodec, getDefaultViewState, getDefaultViewStates, getDisplayables, getViewState, getViewStates, lineBorder, lineBorder, lineBorder, lineBorder, makeComponent, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, remove, remove, removeAll, removeBorder, reset, sandwichBorder, setCodec, setDeepBackground, setDeepBackground, setDefaultViewState, setDefaultViewStates, setEnabled, setViewState, setViewStates, startAlert, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, uniformizeHeight, uniformizeSize, uniformizeWidth, YesNoCancelDialog, YesNoCancelDialog
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mouseAdapter

protected MouseActionAdapter mouseAdapter
Mouse action adapter for this zoo.


laminateTable

protected Hashtable laminateTable
Table mapping components to laminates.


selectionModel

protected ListSelectionModel selectionModel
Selection model for this zoo.


restrictingBounds

protected boolean restrictingBounds
Whether or not this zoo is restricting its child components' bounds.


moveable

protected boolean moveable
Whether or not the child items in this zoo can be moved.

Since:
2.0

resizeable

protected boolean resizeable
Whether or not the child items in this zoo can be resized.

Since:
2.0

designMode

protected boolean designMode
Whether or not this zoo is in design mode.


dashedStroke

private Stroke dashedStroke
Stroke used to paint the lasso.


lassoStart

protected Point lassoStart
Point at which the current lasso originated.


lassoLast

protected Point lassoLast
Last point used to calculate the current lasso.


focusedHighlightColor

protected Color focusedHighlightColor
Highlight color of selected components for when this zoo has the keyboard focus. The default value for this color is SystemColor.textHighlight.

Since:
2.1
See Also:
setFocusedHighlightColor(Color), getFocusedHighlightColor()

unfocusedHighlightColor

protected Color unfocusedHighlightColor
Highlight color of selected components for when this zoo does not have the keyboard focus. The default value for this color is null, which means that it is computed from the highlight color for when this zoo has focus.

Since:
2.1
See Also:
setUnfocusedHighlightColor(Color), getUnfocusedHighlightColor()

SELECT_ALL_ACTION

public final Action SELECT_ALL_ACTION
Action to select all components in this zoo.

Since:
2.1
See Also:
selectAll()

DESELECT_ALL_ACTION

public final Action DESELECT_ALL_ACTION
Action to deselect all components in this zoo.

Since:
2.1
See Also:
deselectAll()

GROUP_SELECTED_COMPONENTS_ACTION

public final Action GROUP_SELECTED_COMPONENTS_ACTION
Action to group all selected components in this zoo.

Since:
2.1
See Also:
groupSelection()

UNGROUP_SELECTED_COMPONENT_ACTION

public final Action UNGROUP_SELECTED_COMPONENT_ACTION
Action to ungroup the first selected component in this zoo, as long as it is an instance of ZooGroup.

Since:
2.1
See Also:
ungroup(ZooGroup), getSelectedComponent()

UNGROUP_SELECTED_COMPONENTS_ACTION

public final Action UNGROUP_SELECTED_COMPONENTS_ACTION
Action to ungroup all selected components in this zoo.

Since:
2.1
See Also:
ungroupSelection()

TOGGLE_DESIGN_MODE_ACTION

public final Action TOGGLE_DESIGN_MODE_ACTION
Action to toggle design mode for this zoo.

Since:
2.1

SET_DESIGN_MODE_ON_ACTION

public final Action SET_DESIGN_MODE_ON_ACTION
Action to turn on design mode for this zoo.

Since:
2.1

SET_DESIGN_MODE_OFF_ACTION

public final Action SET_DESIGN_MODE_OFF_ACTION
Action to turn off design mode for this zoo.

Since:
2.1

SEND_TO_BACK_ACTION

public final Action SEND_TO_BACK_ACTION
Action to send the first selected component in this zoo to the back of the z-order.

Since:
2.1

BRING_TO_FRONT_ACTION

public final Action BRING_TO_FRONT_ACTION
Action to bring the first selected component in this zoo to the front of the z-order.

Since:
2.1

MOVE_UP_ACTION

public final Action MOVE_UP_ACTION
Action to move the first selected component in this zoo to the next higher z-order position.

Since:
2.1

MOVE_DOWN_ACTION

public final Action MOVE_DOWN_ACTION
Action to move the first selected component in this zoo to the next deeper z-order position.

Since:
2.1
Constructor Detail

Zoo

public Zoo()
Constructs a new zoo that restricts its child components' bounds to be contained within the bounds of this zoo.


Zoo

public Zoo(boolean isRestricting)
Constructs a new zoo that either restricts its child components' bounds or does not restrict its child components' bounds.

Parameters:
isRestricting - whether or not the zoo will restrict its child components' bounds
Method Detail

addChildItem

public Component addChildItem(Component c)
Adds the given component to this zoo at the highest z-order position and prepares the component for direct manipulation, grouping, and selection.

Overrides:
addChildItem in class ZooContainer
Parameters:
c - a component to be added to this zoo
Returns:
the added component
See Also:
addChildItem(Component, int)

addChildItem

public Component addChildItem(Component c,
                              int z)
Adds the given component to this zoo at the given z-order position and prepares the component for direct manipulation, grouping, and selection.

Overrides:
addChildItem in class ZooContainer
Parameters:
c - a component to be added to this zoo
z - the z-order position at which to add the component, or -1 if the component is to be added at the deepest z-order position
Returns:
the added component
See Also:
addChildItem(Component)

getItems

public Component[] getItems()
Returns an array containing all of the components contained in this zoo, including components that are nested within groups. Components in the returned array are provided in the order of their z-order positions. Since components in top-level groups exist at the same z-order position, such components appear in the returned array in the order of their z-order positions within the nested group.

Overrides:
getItems in class ZooContainer
See Also:
getChildItems(), ZooContainer.getItem(int), ZooContainer.getItemCount()

getChildItem

public Component getChildItem(int z)
Returns the top-level component in this zoo at the given z-order.

Overrides:
getChildItem in class ZooContainer
Parameters:
z - the z-order of the desired component
Throws:
ArrayIndexOutOfBoundsException - if the given z-order position is invalid
See Also:
ZooContainer.getItem(int), getChildItems(), ZooContainer.getChildItemCount()

getChildItems

public Component[] getChildItems()
Returns an array containing all of the top-level components in this zoo. Components in the returned array are provided in order of their z-order positions. Since a group may be at the top-level, the array may contain groups as well as single components.

Overrides:
getChildItems in class ZooContainer
See Also:
getItems(), getChildItem(int), getChildItemCount()

getChildItemCount

public int getChildItemCount()
Returns the number of top-level components in this container. The returned value is one greater than the z-order position of the component at the deepest z-order position.

Overrides:
getChildItemCount in class ZooContainer
See Also:
ZooContainer.getItemCount(), getChildItem(int), getChildItems()

removeChildItem

public Component removeChildItem(Component c)
Removes the given top-level component from this zoo. If the given component is not at the top level of this zoo, this zoo is not changed. If the given component is a group, the group and its contents are removed.

Overrides:
removeChildItem in class ZooContainer
Parameters:
c - a component to remove from this zoo
Returns:
the removed component, or null if the given component is not at the top level of this zoo
See Also:
removeChildItem(int), removeAllItems()

removeChildItem

public Component removeChildItem(int z)
Removes the top-level component at the given z-order position from this zoo. If the top-level component at the given z-order position is a group, the group and its contents are removed.

Overrides:
removeChildItem in class ZooContainer
Parameters:
z - the z-order position of a component to be removed from this container
Returns:
the removed component
Throws:
ArrayIndexOutOfBoundsException - if the given z-order position is invalid
See Also:
removeChildItem(Component), removeAllItems()

removeAllItems

public void removeAllItems()
Removes all of the components from this container.

Overrides:
removeAllItems in class ZooContainer
See Also:
removeChildItem(Component), removeChildItem(int)

moveToZOrder

public int moveToZOrder(Component c,
                        int newZ)
Moves the given component to the given z-order position. The given z-order position is to be expressed in terms of the z-order of this zoo before the move. The resulting z-order position of the moved component may not be equal to the given z-order position after the component is moved. If the given component is not in this zoo, this zoo is not changed.

Overrides:
moveToZOrder in class ZooContainer
Parameters:
c - the component to move
newZ - the z-order position to which to move the component
Returns:
the z-order position of the component after the move is completed, or -1 if the component is not in this zoo
Throws:
ArrayIndexOutOfBoundsException - if the given z-order is invalid
See Also:
ZooContainer.bringToFront(Component), ZooContainer.sendToBack(Component), ZooContainer.moveUp(Component), ZooContainer.moveDown(Component), ZooContainer.nextHigherInZOrder(int), ZooContainer.nextDeeperInZOrder(int)

group

public ZooGroup group(Component[] components)
Groups the given top-level components of this zoo. The group will exist at the relative z-order position of the highest z-order position among the components it contains. The resulting z-order position for the group may not be equal to the actual z-order position of the highest z-order position among the components the group contains.

Overrides:
group in class ZooContainer
Parameters:
components - the components to be grouped
Returns:
the resulting group of components, or null if there were less than two components to be grouped
Throws:
NullPointerException - if the given array is null
See Also:
ungroup(ZooGroup)

ungroup

public Component[] ungroup(ZooGroup group)
Disassociates the components in the given group. If the given group is not at the top level of this zoo, this zoo is not changed. The individual components will exist at the relative z-order position of the disassociated group. The resulting z-order positions for the individual components may not be equal to the actual z-order position of the group prior to disassociation.

Overrides:
ungroup in class ZooContainer
Parameters:
group - the group of components to disassociate
Returns:
an array containing the disassociated components or a zero-length array if the given group is not at the top level of this zoo
See Also:
group(Component[])

selectAll

public void selectAll()
Selects all top-level components in this zoo. If this zoo contains no components, or all the top-level components in this zoo are selected, this method does nothing.

See Also:
deselectAll(), addToSelection(Component), removeFromSelection(Component)

deselectAll

public void deselectAll()
Deselects all top-level components in this zoo. If this zoo contains no components, or no top-level components in this zoo are selected, this method does nothing.

See Also:
selectAll(), removeFromSelection(Component), addToSelection(Component)

addToSelection

public void addToSelection(Component c)
Adds the given top-level component to the list of selected components in this zoo. If the given component is not at the top level of this zoo, this method does nothing.

Parameters:
c - the component to be selected
See Also:
removeFromSelection(Component), selectAll(), deselectAll()

removeFromSelection

public void removeFromSelection(Component c)
Removes the given top-level component from the list of selected components in this zoo. If the given component is not at the top level of this zoo, this method does nothing

Parameters:
c - the component to be deselected
See Also:
addToSelection(Component), deselectAll(), selectAll()

selectOnly

public void selectOnly(Component c)
Sets the selection for this zoo to only the the given component. If the given component is null, or is not in this zoo, this method does nothing.

Parameters:
c - component to select
Since:
2.1
See Also:
addToSelection(Component)

setSelectedComponents

public void setSelectedComponents(Component[] c)

Sets the selection for this zoo to exactly the components in the given array that are not-null and are contained at top-level in this zoo.

If the given array is null, or no changes to the selection for this zoo are to be made as a result of this operation, this method does nothing.

For this method, changes to the selection model are made in exactly the following order: First, the selection is cleared. Next, each discrete interval of components in the given array are selected, by z-order. In this way, the number of changes to the selection model will be at least 2, and at most the length of the given array.

Parameters:
c - components to be selected
Since:
2.1
See Also:
getSelectedComponents()

getSelectedComponent

public Component getSelectedComponent()
Returns the selected component in this zoo at the highest z-order position, or null if the selection is empty.

See Also:
getSelectedComponent(int), getSelectedComponents(), getSelectedComponentCount(), isSelectionEmpty()

getSelectedComponent

public Component getSelectedComponent(int index)
Returns the selected component in this zoo at the given index into the list of selected components, or null if the selection is empty.

Throws:
ArrayIndexOutOfBoundsException - if the given index is out of bounds
See Also:
getSelectedComponent(), getSelectedComponents(), getSelectedComponentCount(), isSelectionEmpty()

getSelectedComponents

public Component[] getSelectedComponents()
Returns an array containing the selected components in this zoo in the order of their z-order positions, or a zero-length array if the selection is empty.

See Also:
getSelectedComponent(), getSelectedComponent(int), getSelectedComponentCount(), isSelectionEmpty()

getSelectedComponentCount

public int getSelectedComponentCount()
Returns the number of selected components in this zoo.

See Also:
getSelectedComponent(), getSelectedComponent(int), getSelectedComponents(), isSelectionEmpty()

isSelectionEmpty

public boolean isSelectionEmpty()
Returns whether or not the selection is empty.

See Also:
getSelectedComponent(), getSelectedComponent(int), getSelectedComponents(), getSelectedComponentCount()

getSelectionModel

public ListSelectionModel getSelectionModel()
Returns the selection model for this zoo.


groupSelection

public ZooGroup groupSelection()
Groups the currently selected components. If fewer than two components are selected, no association is performed.

Returns:
the resulting group, or null if the selection is too few to be grouped
See Also:
ungroupSelection()

ungroupSelection

public void ungroupSelection()
Ungroups the currently selected components. Selected components that are not groups are unaffected by this operation.

See Also:
groupSelection()

setInDesignMode

public void setInDesignMode(boolean designing)
Sets whether or not this zoo is in design mode.

Parameters:
designing - whether or not this zoo is in design mode
See Also:
isInDesignMode()

isInDesignMode

public boolean isInDesignMode()
Returns whether or not this zoo is in design mode.

See Also:
setInDesignMode(boolean)

setRestrictingBounds

public void setRestrictingBounds(boolean isRestricting)
Sets whether or not this zoo is restricting its child components' bounds to be contained within the bounds of this zoo.

Parameters:
isRestricting - whether or not this zoo is restricting its child components' bounds
See Also:
isRestrictingBounds()

isRestrictingBounds

public boolean isRestrictingBounds()
Returns whether or not this zoo is restricting its child components' bounds to be contained within the bounds of this zoo.

See Also:
setRestrictingBounds(boolean)

setAllowsMove

public void setAllowsMove(boolean allowsMove)
Sets whether or not the child items of this zoo can be moved using direct manipulation. Methods such as setLocation are not affected by the value of this property.

Parameters:
allowsMove - whether or not this zoo allows child items to be moved using direct manipulation
Since:
2.0
See Also:
allowsMove()

allowsMove

public boolean allowsMove()
Returns whether or not the child items in this zoo can be moved using direct manipulation. Methods such as setLocation are not affected by the value of this property.

Since:
2.0
See Also:
setAllowsMove(boolean)

setAllowsResize

public void setAllowsResize(boolean allowsResize)
Sets whether or not the child items of this zoo can be resized using direct manipulation. Methods such as setSize are not affected by the value of this property.

Parameters:
allowsResize - whether or not this zoo allows child items to be resized using direct manipulation
Since:
2.0
See Also:
allowsResize()

allowsResize

public boolean allowsResize()
Returns whether or not the child items in this zoo can be resized using direct manipulation. Methods such as setSize are not affected by the value of this property.

Since:
2.0
See Also:
setAllowsResize(boolean)

setFocusedHighlightColor

public void setFocusedHighlightColor(Color c)
Sets the color used to highlight a selected component when this zoo has the keyboard focus. If the given color is null, the highlight color is not changed.

Parameters:
c - highlight color for when this zoo has focus
Since:
2.1
See Also:
getFocusedHighlightColor(), setUnfocusedHighlightColor(Color)

getFocusedHighlightColor

public Color getFocusedHighlightColor()
Returns the color used to highlight a selected component when this zoo has the keyboard focus.

Since:
2.1
See Also:
getUnfocusedHighlightColor(), setFocusedHighlightColor(Color)

setUnfocusedHighlightColor

public void setUnfocusedHighlightColor(Color c)
Sets the color used to highlight a selected component when this zoo does not have the keyboard focus. If the given color is null, the highlight color is computed from the highlight color for when this zoo has focus.

Parameters:
c - highlight color for when this zoo does not have focus
Since:
2.1
See Also:
setFocusedHighlightColor(Color), getUnfocusedHighlightColor()

getUnfocusedHighlightColor

public Color getUnfocusedHighlightColor()
Returns the color used to highlight a selected component when this zoo does not have the keyboard focus. If this property is set to null, the color returned is a color computed from the highlight color for when this zoo has focus.

Since:
2.1
See Also:
setUnfocusedHighlightColor(Color), getFocusedHighlightColor()

getLaminateFor

public Laminate getLaminateFor(Component c)
Returns the laminate for the given component, or null if the given component is not a child item of this zoo.

Parameters:
c - the component whose laminate is to be returned
Since:
2.0

isFocusTraversable

public boolean isFocusTraversable()
Returns true if this zoo is in design mode, or false otherwise.

Overrides:
isFocusTraversable in class ZooContainer
See Also:
Component.isFocusTraversable()

isManagingFocus

public boolean isManagingFocus()
Returns true if this zoo is in design mode, or false otherwise.

Overrides:
isManagingFocus in class ZooContainer
See Also:
JComponent.isManagingFocus()

paintComponent

protected void paintComponent(Graphics g)
Paints this component to the given graphics context.

Parameters:
g - the graphics context to which to paint

createLaminateFor

protected Laminate createLaminateFor(Component c)
Returns a new laminate for the given component.

Parameters:
c - the component to be laminated

installMouseAdapter

protected void installMouseAdapter()
Installs the mouse adapter for this zoo.


installSelectionModel

protected void installSelectionModel()
installs the selection model for this zoo.


installFocusAdapter

protected void installFocusAdapter()
Installs the focus adapter for this zoo.


updateSelection

protected void updateSelection()
Selects or deselects the appropriate components based on the state of the selection model.


getLassoBounds

protected Rectangle getLassoBounds()
Returns the bounds of the current lasso, or null if there is no current lasso.


startLasso

protected void startLasso(MouseEvent evt)
Starts a new lasso given the mouse event that prompted its origination.

Parameters:
evt - the mouse event that prompted a lasso

resizeLasso

protected void resizeLasso(MouseEvent evt)
Resizes the current lasso given the mouse event that prompted its resize.

Parameters:
evt - the mouse event that prompted a lasso resize

endLasso

protected void endLasso(MouseEvent evt)
Ends the current lasso given the mouse event that prompted its destruction.

Parameters:
evt - the mouse event that prompted the end of the current lasso

updateSelectionActions

protected void updateSelectionActions()
Enables or disables selection actions based on the current selection.

SELECT_ALL_ACTION is enabled if there is at least one top-level component not selected, and is disabled otherwise.

DESELECT_ALL_ACTION is enabled if there is at least one top-level component selected, and is disabled otherwise.

GROUP_SELECTED_COMPONENTS_ACTION is enabled if there are at least two top-level components selected, and is disabled otherwise.

UNGROUP_SELECTED_COMPONENT_ACTION is enabled if there is at least one top-level component selected and the first selected component is an instance of ZooGroup, and is disabled otherwise.

UNGROUP_SELECTED_COMPONENTS_ACTION is enabled if there is at least one top-level component selected and all of those components are instances of ZooGroup, and is disabled otherwise.

SEND_TO_BACK_ACTION is enabled if there is only one top-level component selected and the selected component is not at the deepest z-order, and is disabled otherwise.

BRING_TO_FRONT_ACTION is enabled if there is only one top-level component selected and the selected component is not at the highest z-order, and is disabled otherwise.

MOVE_UP_ACTION is enabled if there is only one top-level component selected and the selected component is not at the highest z-order, and is disabled otherwise.

MOVE_DOWN_ACTION is enabled if there is only one top-level component selected and the selected component is not at the deepest z-order, and is disabled otherwise.

Since:
2.1
See Also:
SELECT_ALL_ACTION, DESELECT_ALL_ACTION, GROUP_SELECTED_COMPONENTS_ACTION, UNGROUP_SELECTED_COMPONENT_ACTION, UNGROUP_SELECTED_COMPONENTS_ACTION, SEND_TO_BACK_ACTION, BRING_TO_FRONT_ACTION, MOVE_UP_ACTION, MOVE_DOWN_ACTION

updateDesignModeActions

protected void updateDesignModeActions()
Enables or disables design mode actions based on the current design mode. SET_DESIGN_MODE_ON_ACTION is enabled if this zoo is not in design mode, and is disabled otherwise. SET_DESIGN_MODE_OFF_ACTION is enabled if this zoo is in design mode, and is disabled otherwise.

See Also:
SET_DESIGN_MODE_ON_ACTION, SET_DESIGN_MODE_OFF_ACTION

computeUnfocusedHighlightColor

protected Color computeUnfocusedHighlightColor(Color c)
Computes a suitable color of the highlight of selected components for when this zoo does not have focus, from the given color. If the given color is null, this method returns the color black.

Parameters:
c - color used to compute the suitable color
Since:
2.1

addChildItemImpl

private Component addChildItemImpl(Component c,
                                   int z)
Adds the given component at the given z-order position.

Parameters:
c - a component to be added
z - the desired z-order position of the component
Throws:
ArrayIndexOutOfBoundsException - if the given z-order position is invalid

removeChildItemImpl

private Component removeChildItemImpl(Component c)
Removes the given component from this zoo.

Parameters:
c - a component to be removed

removeComponentImpl

private void removeComponentImpl(Component c,
                                 int z)
Removes the given component and its laminate.

Parameters:
c - a component to be removed
z - the z-order position of the component, or -1 if the z-order position is not known

zOrderToIndex

private int zOrderToIndex(int z)
Returns the Java container index of the component at the given z-order.

Parameters:
z - the z-order position of the component whose Java container index is desired