arlut.csd.JTree
Class treeControl

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--arlut.csd.JTree.treeControl
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.awt.event.AdjustmentListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class treeControl
extends javax.swing.JPanel
implements java.awt.event.AdjustmentListener, java.awt.event.ActionListener

This component allows the display of a tree structured graph of nodes, each node being a small image and a line of text. Nodes with children can be opened or closed, allowing the child nodes to be made visible or hidden. Each node can be selected and can have a pop-up menu attached. Nodes can be dragged, with both 'drag-tween' and 'drag on' drag supported.

See Also:
treeCallback, treeNode, Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent, javax.swing.JComponent.ActionStandin, javax.swing.JComponent.IntVector, javax.swing.JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
(package private) static int borderSpace
           
(package private)  java.awt.Rectangle bounding_rect
           
(package private)  treeCallback callback
           
(package private)  treeCanvas canvas
           
(package private)  treeDragDropCallback dCallback
           
(package private) static boolean debug
           
static int DRAG_ICON
           
static int DRAG_LINE
           
static int DRAG_NONE
           
(package private)  treeNode dragAboveNode
           
(package private)  treeNode dragBelowNode
           
(package private)  int dragMode
           
(package private)  treeNode dragNode
           
(package private)  treeNode dragOverNode
           
(package private)  javax.swing.JScrollBar hbar
           
(package private)  boolean hbar_visible
           
(package private)  int maxWidth
           
(package private)  treeMenu menu
           
(package private)  treeNode menuedNode
           
(package private)  int minWidth
           
(package private)  treeNode oldNode
           
(package private)  treeNode root
           
(package private)  int row_height
           
(package private)  java.util.Vector rows
           
(package private)  javax.swing.JScrollBar vbar
           
(package private)  boolean vbar_visible
           
 
Fields inherited from class javax.swing.JPanel
defaultLayout, uiClassID
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, actionMap, ACTIONMAP_CREATED, alignmentX, alignmentY, ANCESTOR_INPUTMAP_CREATED, ANCESTOR_USING_BUFFER, ancestorInputMap, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, CREATED_DOUBLE_BUFFER, flags, FOCUS_INPUTMAP_CREATED, focusInputMap, HAS_FOCUS, htmlKey, htmlView, inputVerifier, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, IS_PRINTING, IS_PRINTING_ALL, KEY_EVENTS_ENABLED, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, paintingChild, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, verifyInputWhenFocusTarget, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, WHEN_IN_FOCUSED_WINDOW_BINDINGS, WIF_INPUTMAP_CREATED, windowInputMap
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
treeControl(java.awt.Font font, java.awt.Color fgColor, java.awt.Color bgColor, treeCallback callback, java.awt.Image[] images)
           
treeControl(java.awt.Font font, java.awt.Color fgColor, java.awt.Color bgColor, treeCallback callback, java.awt.Image[] images, treeMenu menu)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Handle notification from popupmenus
 void adjustmentValueChanged(java.awt.event.AdjustmentEvent e)
          Handles scrollbar events.
(package private)  void adjustScrollbars()
          Check to see whether we need scrollbars in our current component size, set the min/max/visible parameters

This method is intended to be called from reShape().
(package private)  void breakdownTree(treeNode node)
          Helper function to break down links in a tree to speed GC.
(package private)  void clearStacks(treeNode node)
          Helper method to force recalculation of childStacks.
 void clearTree()
          Clear out the tree.
 void contractNode(treeNode node, boolean repaint)
          close the given node
 void contractNode(treeNode node, boolean repaint, boolean doCallback)
          close the given node
 void deleteNode(treeNode node, boolean repaint)
          Removes a node from the tree, along with all its children.
(package private)  void doubleClickNode(treeNode node)
           
 void dumpRows()
           
 void expandNode(treeNode node, boolean repaint)
          open the given node
 void expandNode(treeNode node, boolean repaint, boolean doCallback)
          open the given node
 treeNode getRoot()
          Get access to the root of the treeCanvas's tree of nodes.
(package private)  void getVisibleDescendantRange(treeNode node, Range range)
          calculates the rows that are visible at and below node, so that contractNode() can remove all nodes in that range from visibility
 void insertNode(treeNode newNode, boolean repaint)
          Inserts a new node into the tree.
(package private)  int makeDescendantsVisible(treeNode node, int row)
          recursive routine to make descendant nodes visible.
 treeNode moveNode(treeNode node, treeNode parent, treeNode insertAfter, boolean repaint)
          Moves a node (possibly the root of an extensive subtree) from one location in the tree to another.

Note that this method is currently implemented in a fairly simplistic manner, using the deleteNode and insertNode primitives, cloning nodes as they are copied into the new location in the tree.
 void refresh()
          Recalculate and redraw the tree.
(package private)  void refreshTree()
           
 void removeChildren(treeNode node, boolean repaint)
          Removes all children of the specified node from the tree.
(package private)  void reShape()
          This method recalculates the general parameters of our tree's display.
 void resize(int x, int y, int width, int height)
           
(package private)  void selectNode(treeNode node)
          Mark a node as selected, issuing a callback to the client reporting the selection.

This method does not deselect other nodes.
 void setBounds(int x, int y, int width, int height)
           
 void setDrag(treeDragDropCallback dCallback, int mode)
          This method is used to set the drag behavior of the tree.
 void setMinimumWidth(int minWidth)
           
 void setRoot(treeNode root)
          Clear the tree and establish a new root node.
(package private)  void transientSelectNode(treeNode node)
          Select a node without issuing a callback to the client.

Used to implement highlighting during drag-and-drop.
(package private)  void transientUnselectNode(treeNode node)
          Deselect a node without issuing a callback to the client.

Used to implement highlighting during drag-and-drop.
(package private)  void unselectAllNodes(boolean anySelected)
          Deselect all nodes, issuing a callback to the client reporting the deselection.

(package private)  void unselectNode(treeNode node, boolean anySelected)
          Deselect a node, issuing a callback to the client reporting the deselection.

 
Methods inherited from class javax.swing.JPanel
, getAccessibleContext, getUIClassID, paramString, updateUI, writeObject
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, checkIfChildObscuredBySibling, clearFocusOwners, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paintWithBuffer, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, rectangleIsObscuredBySibling, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, unregisterWithKeyboardManager, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resetGC, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

debug

static final boolean debug

borderSpace

static final int borderSpace

DRAG_NONE

public static final int DRAG_NONE

DRAG_ICON

public static final int DRAG_ICON

DRAG_LINE

public static final int DRAG_LINE

root

treeNode root

callback

treeCallback callback

canvas

treeCanvas canvas

dCallback

treeDragDropCallback dCallback

dragMode

int dragMode

oldNode

treeNode oldNode

dragNode

treeNode dragNode

dragOverNode

treeNode dragOverNode

dragBelowNode

treeNode dragBelowNode

dragAboveNode

treeNode dragAboveNode

menu

treeMenu menu

hbar

javax.swing.JScrollBar hbar

vbar

javax.swing.JScrollBar vbar

bounding_rect

java.awt.Rectangle bounding_rect

hbar_visible

boolean hbar_visible

vbar_visible

boolean vbar_visible

minWidth

int minWidth

maxWidth

int maxWidth

row_height

int row_height

rows

java.util.Vector rows

menuedNode

treeNode menuedNode
Constructor Detail

treeControl

public treeControl(java.awt.Font font,
                   java.awt.Color fgColor,
                   java.awt.Color bgColor,
                   treeCallback callback,
                   java.awt.Image[] images,
                   treeMenu menu)
Parameters:
font - Font for text in the Tree Canvas
fgColor - Foreground color for text in the treeCanvas
bg - Background color for text in the treeCanvas
callback - Object to receive notification of events
images - Array of images to be used in the canvas; nodes refer to images by index
menu - Popup menu to attach to the treeControl

treeControl

public treeControl(java.awt.Font font,
                   java.awt.Color fgColor,
                   java.awt.Color bgColor,
                   treeCallback callback,
                   java.awt.Image[] images)
Parameters:
font - Font for text in the Tree Canvas
fgColor - Foreground color for text in the treeCanvas
bg - Background color for text in the treeCanvas
callback - Object to receive notification of events
images - Array of images to be used in the canvas; nodes refer to images by index
Method Detail

setDrag

public void setDrag(treeDragDropCallback dCallback,
                    int mode)
This method is used to set the drag behavior of the tree.
Parameters:
dCallback - DragDrop manager object
mode - A binary or'ing of of treeControl.DRAG_NONE, treeControl.DRAG_ICON, and treeControl.DRAG_LINE.
See Also:
treeDragDropCallback

clearTree

public void clearTree()
Clear out the tree.

setRoot

public void setRoot(treeNode root)
Clear the tree and establish a new root node.

setMinimumWidth

public void setMinimumWidth(int minWidth)

insertNode

public void insertNode(treeNode newNode,
                       boolean repaint)

Inserts a new node into the tree. newNode's prevSibling is checked first. If it is non-null, newNode is inserted after newNode.prevSibling, regardless of what newNode.parent says. If prevSibling is null, newNode is made the first child of its requested parent.

Parameters:
newNode - The node to be inserted. Properties of the node determine where the node is inserted.
repaint - If true, immediately re-render and refresh the treeCanvas.

deleteNode

public void deleteNode(treeNode node,
                       boolean repaint)

Removes a node from the tree, along with all its children. Any child nodes attached to the node to be deleted will be unlinked from one another. If you want to be able to re-insert the deleted node elsewhere in the tree, you probably should use moveNode() instead.

Parameters:
node - The node to be removed.
repaint - If true, immediately re-render and refresh the treeCanvas.

moveNode

public treeNode moveNode(treeNode node,
                         treeNode parent,
                         treeNode insertAfter,
                         boolean repaint)
Moves a node (possibly the root of an extensive subtree) from one location in the tree to another.

Note that this method is currently implemented in a fairly simplistic manner, using the deleteNode and insertNode primitives, cloning nodes as they are copied into the new location in the tree. This works reliably, but this might not be the best implementation for moving large sub-trees.
Parameters:
node - The node to be moved.
parent - Parent node to insert this node under, null if this is a top-level node
insertAfter - sibling to insert this node after
repaint - If true, immediately re-render and refresh the treeCanvas after moving the node.
Returns:
a reference to a copy of the node in its new location

removeChildren

public void removeChildren(treeNode node,
                           boolean repaint)

Removes all children of the specified node from the tree.

Parameters:
node - The node whose children should be removed
repaint - If true, immediately re-render and refresh the treeCanvas.

breakdownTree

void breakdownTree(treeNode node)
Helper function to break down links in a tree to speed GC. breakdownTree will disassociate all nodes in an unlinked tree, so new nodes will need to be assembled in order to be resubmitted to the tree.

clearStacks

void clearStacks(treeNode node)
Helper method to force recalculation of childStacks. This method should be called on the child of a node, not on the node itself, lest clearStacks recurse along the node's siblings.. not that that will cause any great hardship, but it would slow things down a very little bit.

getRoot

public treeNode getRoot()
Get access to the root of the treeCanvas's tree of nodes.

refresh

public void refresh()
Recalculate and redraw the tree.

dumpRows

public void dumpRows()

expandNode

public void expandNode(treeNode node,
                       boolean repaint)
open the given node

expandNode

public void expandNode(treeNode node,
                       boolean repaint,
                       boolean doCallback)
open the given node

makeDescendantsVisible

int makeDescendantsVisible(treeNode node,
                           int row)
recursive routine to make descendant nodes visible. will not expand any contracted nodes, but will add any nodes reachable without passing below a contracted node to the visibility
Parameters:
row - the row to match the node to.
Returns:
the row number of the last descendant made visible

contractNode

public void contractNode(treeNode node,
                         boolean repaint)
close the given node

contractNode

public void contractNode(treeNode node,
                         boolean repaint,
                         boolean doCallback)
close the given node

getVisibleDescendantRange

void getVisibleDescendantRange(treeNode node,
                               Range range)
calculates the rows that are visible at and below node, so that contractNode() can remove all nodes in that range from visibility

transientSelectNode

void transientSelectNode(treeNode node)
Select a node without issuing a callback to the client.

Used to implement highlighting during drag-and-drop.

doubleClickNode

void doubleClickNode(treeNode node)

selectNode

void selectNode(treeNode node)
Mark a node as selected, issuing a callback to the client reporting the selection.

This method does not deselect other nodes.

transientUnselectNode

void transientUnselectNode(treeNode node)
Deselect a node without issuing a callback to the client.

Used to implement highlighting during drag-and-drop.

unselectNode

void unselectNode(treeNode node,
                  boolean anySelected)
Deselect a node, issuing a callback to the client reporting the deselection.

Parameters:
anySelected - If true, the client will be told that some node will remain selected after this operation is completed

unselectAllNodes

void unselectAllNodes(boolean anySelected)
Deselect all nodes, issuing a callback to the client reporting the deselection.

Parameters:
anySelected - If true, the client will be told that some node will remain selected after this operation is completed.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Handle notification from popupmenus
Specified by:
actionPerformed in interface java.awt.event.ActionListener

adjustmentValueChanged

public void adjustmentValueChanged(java.awt.event.AdjustmentEvent e)
Handles scrollbar events.
Specified by:
adjustmentValueChanged in interface java.awt.event.AdjustmentListener

resize

public void resize(int x,
                   int y,
                   int width,
                   int height)

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Overrides:
setBounds in class java.awt.Component

reShape

void reShape()
This method recalculates the general parameters of our tree's display. That is, it calculates whether or not we need scroll bars, adds or deletes the scroll bars, and scales the column positions to match the general rendering parameters.

adjustScrollbars

void adjustScrollbars()
Check to see whether we need scrollbars in our current component size, set the min/max/visible parameters

This method is intended to be called from reShape().

refreshTree

void refreshTree()