net.wotonomy.ui.swing.components
Class TreeChooser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by net.wotonomy.ui.swing.components.TreeChooser
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ListSelectionListener, javax.swing.event.TreeModelListener, javax.swing.event.TreeSelectionListener, javax.swing.ListCellRenderer

public class TreeChooser
extends javax.swing.JPanel
implements java.awt.event.ActionListener, javax.swing.event.ListSelectionListener, javax.swing.event.TreeSelectionListener, javax.swing.event.TreeModelListener, javax.swing.ListCellRenderer

TreeChooser is a FileChooser-like panel that uses a TreeModel as a data source. It basically provides an alternative to JTree for rendering and manipulating tree-like data.

Version:
$Revision: 904 $
Author:
michael@mpowers.net, $Author: cgruber $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String BACK
          The TreeChooser responds to this action command by calling displayPrevious().
protected  javax.swing.JList contents
           
protected  javax.swing.tree.TreePath displayPath
           
static java.lang.String HOME
          The TreeChooser responds to this action command by calling displayHome().
protected  javax.swing.tree.TreeModel model
           
protected  javax.swing.JComboBox pathCombo
           
protected  int pathIndent
           
protected  java.util.Stack pathStack
           
protected  javax.swing.tree.TreeCellRenderer renderer
           
static java.lang.String SELECT
          The TreeChooser responds to this action command by attempting to navigate to the first node in the current selection and display that node's children.
protected  javax.swing.tree.TreeSelectionModel selectionModel
           
protected  javax.swing.JToolBar toolBar
           
static java.lang.String UP
          The TreeChooser responds to this action command by calling displayParent().
 
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.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TreeChooser()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
           
 void displayHome()
          Displays the "home" directory.
 void displayParent()
          Displays the parent path of the currently displayed path.
 void displayPrevious()
          Displays the last displayed path before the current one, emulating the behavior of a "back" button.
 javax.swing.tree.TreePath getDisplayPath()
          Gets the currently displayed path.
 java.awt.Component getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
          This method returns the component returned by the tree cell renderer.
 javax.swing.tree.TreeModel getModel()
          Returns the TreeModel used by the TreeChooser.
 java.awt.Dimension getPreferredSize()
           
 javax.swing.tree.TreeCellRenderer getRenderer()
          Returns the TreeCellRenderer used by the TreeChooser.
 javax.swing.tree.TreeSelectionModel getSelectionModel()
          Returns the TreeSelectionModel used by the TreeChooser.
protected  void init()
           
protected  javax.swing.JComboBox initComboBox()
          Creates the JComboBox that is used to render the path leading to the displayed contents.
protected  javax.swing.JList initList()
          Creates the JList that is used to render the path leading to the displayed contents.
protected  java.awt.Component initPreviewPane()
          Creates the component that is used to display a preview of the selected item(s) in the content area.
protected  java.awt.Component initToolBar()
          Creates tool bar or return null if no tool bar is desired.
 void setDisplayPath(javax.swing.tree.TreePath aPath)
          Pushes the previous item onto the stack, sets the display path, and then updates the contents.
protected  void setDisplayPathDirect(javax.swing.tree.TreePath aPath)
          Sets the displayPath field and does not update the stack nor update the contents.
 void setModel(javax.swing.tree.TreeModel aTreeModel)
          Sets the TreeModel used by the TreeChooser.
 void setRenderer(javax.swing.tree.TreeCellRenderer aRenderer)
          Sets the TreeCellRenderer used by the TreeChooser.
 void setSelectionModel(javax.swing.tree.TreeSelectionModel aSelectionModel)
          Sets the TreeSelectionModel used by the TreeChooser.
protected  void startListening()
          Begins listening to the specified tree model and tree selection model.
protected  void stopListening()
          Stops listening to the specified tree model and tree selection model.
 void treeNodesChanged(javax.swing.event.TreeModelEvent evt)
           
 void treeNodesInserted(javax.swing.event.TreeModelEvent evt)
           
 void treeNodesRemoved(javax.swing.event.TreeModelEvent evt)
           
 void treeStructureChanged(javax.swing.event.TreeModelEvent evt)
           
protected  void updateContents()
          Called when selected path changes or when model indicates that the displayed path has changed.
 void updateSelection()
          Updates the selection in the list to reflect the selection in the tree selection model.
 void valueChanged(javax.swing.event.ListSelectionEvent evt)
          Called when user changes the selection in the list.
 void valueChanged(javax.swing.event.TreeSelectionEvent evt)
          Called when the tree selection model's value changes.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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

BACK

public static final java.lang.String BACK
The TreeChooser responds to this action command by calling displayPrevious().

See Also:
Constant Field Values

HOME

public static final java.lang.String HOME
The TreeChooser responds to this action command by calling displayHome().

See Also:
Constant Field Values

UP

public static final java.lang.String UP
The TreeChooser responds to this action command by calling displayParent().

See Also:
Constant Field Values

SELECT

public static final java.lang.String SELECT
The TreeChooser responds to this action command by attempting to navigate to the first node in the current selection and display that node's children.

See Also:
Constant Field Values

contents

protected javax.swing.JList contents

pathCombo

protected javax.swing.JComboBox pathCombo

toolBar

protected javax.swing.JToolBar toolBar

model

protected javax.swing.tree.TreeModel model

selectionModel

protected javax.swing.tree.TreeSelectionModel selectionModel

renderer

protected javax.swing.tree.TreeCellRenderer renderer

displayPath

protected javax.swing.tree.TreePath displayPath

pathStack

protected java.util.Stack pathStack

pathIndent

protected int pathIndent
Constructor Detail

TreeChooser

public TreeChooser()
Method Detail

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

init

protected void init()

initToolBar

protected java.awt.Component initToolBar()
Creates tool bar or return null if no tool bar is desired. This implementation returns a JToolBar containing buttons for BACK, UP, and HOME.


initPreviewPane

protected java.awt.Component initPreviewPane()
Creates the component that is used to display a preview of the selected item(s) in the content area. This component would listen to the selection model to update itself when the selected items change. Return null to omit this component. This implementation returns null.


initComboBox

protected javax.swing.JComboBox initComboBox()
Creates the JComboBox that is used to render the path leading to the displayed contents. Return null to omit this combo box. This implementation returns a stock JComboBox that uses this class as its cell renderer.


initList

protected javax.swing.JList initList()
Creates the JList that is used to render the path leading to the displayed contents. This method may not return null. This implementation returns a stock JList that uses this class as its cell renderer and fires a SELECT action event on double click.


startListening

protected void startListening()
Begins listening to the specified tree model and tree selection model.


stopListening

protected void stopListening()
Stops listening to the specified tree model and tree selection model.


getModel

public javax.swing.tree.TreeModel getModel()
Returns the TreeModel used by the TreeChooser.


setModel

public void setModel(javax.swing.tree.TreeModel aTreeModel)
Sets the TreeModel used by the TreeChooser.


getSelectionModel

public javax.swing.tree.TreeSelectionModel getSelectionModel()
Returns the TreeSelectionModel used by the TreeChooser.


setSelectionModel

public void setSelectionModel(javax.swing.tree.TreeSelectionModel aSelectionModel)
Sets the TreeSelectionModel used by the TreeChooser.


getRenderer

public javax.swing.tree.TreeCellRenderer getRenderer()
Returns the TreeCellRenderer used by the TreeChooser.


setRenderer

public void setRenderer(javax.swing.tree.TreeCellRenderer aRenderer)
Sets the TreeCellRenderer used by the TreeChooser.


displayHome

public void displayHome()
Displays the "home" directory. This implementation displays the root node's children.


displayParent

public void displayParent()
Displays the parent path of the currently displayed path.


displayPrevious

public void displayPrevious()
Displays the last displayed path before the current one, emulating the behavior of a "back" button.


setDisplayPath

public void setDisplayPath(javax.swing.tree.TreePath aPath)
Pushes the previous item onto the stack, sets the display path, and then updates the contents. If aPath is null, the root node's children are displayed.


setDisplayPathDirect

protected void setDisplayPathDirect(javax.swing.tree.TreePath aPath)
Sets the displayPath field and does not update the stack nor update the contents.


getDisplayPath

public javax.swing.tree.TreePath getDisplayPath()
Gets the currently displayed path.


updateContents

protected void updateContents()
Called when selected path changes or when model indicates that the displayed path has changed.


updateSelection

public void updateSelection()
Updates the selection in the list to reflect the selection in the tree selection model.


treeNodesChanged

public void treeNodesChanged(javax.swing.event.TreeModelEvent evt)
Specified by:
treeNodesChanged in interface javax.swing.event.TreeModelListener

treeNodesInserted

public void treeNodesInserted(javax.swing.event.TreeModelEvent evt)
Specified by:
treeNodesInserted in interface javax.swing.event.TreeModelListener

treeNodesRemoved

public void treeNodesRemoved(javax.swing.event.TreeModelEvent evt)
Specified by:
treeNodesRemoved in interface javax.swing.event.TreeModelListener

treeStructureChanged

public void treeStructureChanged(javax.swing.event.TreeModelEvent evt)
Specified by:
treeStructureChanged in interface javax.swing.event.TreeModelListener

valueChanged

public void valueChanged(javax.swing.event.TreeSelectionEvent evt)
Called when the tree selection model's value changes. This is presumably an external change, so this calls updateSelection.

Specified by:
valueChanged in interface javax.swing.event.TreeSelectionListener

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent evt)
Called when user changes the selection in the list. This implementation updates the tree selection model with the corresponding selection.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

getListCellRendererComponent

public java.awt.Component getListCellRendererComponent(javax.swing.JList list,
                                                       java.lang.Object value,
                                                       int index,
                                                       boolean isSelected,
                                                       boolean cellHasFocus)
This method returns the component returned by the tree cell renderer.

Specified by:
getListCellRendererComponent in interface javax.swing.ListCellRenderer

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Specified by:
actionPerformed in interface java.awt.event.ActionListener


Copyright © 2006 null. All Rights Reserved.