uk.ac.starlink.datanode.tree
Class TreeNodeChooser

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 uk.ac.starlink.datanode.tree.TreeNodeChooser
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TreeSelectionListener
Direct Known Subclasses:
NdxNodeChooser, TableNodeChooser

public class TreeNodeChooser
extends JPanel
implements TreeSelectionListener

A component which presents a tree of nodes and allows navigation around it to locate a node of interest. One node can be selected. This is intended to be used in a similar way to the JFileChooser component.

The general visual appearance of this component should be mostly self-explanatory. Some buttons appear near the top:

The protected isChoosable(uk.ac.starlink.datanode.nodes.DataNode) method provides a way for subclasses to restrict which nodes can be chosen from the component or dialog. Subclasses may override this method to indicate which nodes are eligible, and node eligibility will be reflected visually by the component (node names written in bold for choosable nodes, that sort of thing), as well as controlling the enabled status of the selection button etc. The getSearch*Action methods provide actions which may be useful in this context; they will search through the tree recursively and expand it so that any choosable nodes are visible to the user. Note this may result in some non-choosable nodes being visible (parents and siblings of choosable ones) too, but branches which contain no choosable nodes will not be displayed expanded in the GUI.

The chooser initially contains a default set of root items, and a suitable default (the current directory) is selected.

Author:
Mark Taylor (Starlink)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
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
TreeNodeChooser()
          Constructs a new chooser widget with no content.
 
Method Summary
 DataNode chooseDataNode(Component parent, String buttonText, String title)
          Pops up a modal dialog which asks the user for a DataNode.
 void clear()
          Removes all roots from the root selector.
protected  JDialog createDialog(Component parent)
          Constructs the dialog component used by the chooseDataNode(java.awt.Component, java.lang.String, java.lang.String) method.
 JComponent getButtonPanel()
          Returns a panel into which extra buttons can be placed.
 Action getChooseAction()
          Returns the action which indicated that the currently selected node is to be used.
 String getChosenPath()
          Returns the path of the currently chosen node.
 DataNodeFactory getNodeMaker()
          Returns the DataNodeFactory which is used for turning objects into data nodes.
 DataNode getRoot()
          Returns the root of the tree displayed in this chooser.
 NodeRootComboBox getRootSelector()
          Returns the component which allows the user to select the current root of the tree.
 Action getSearchAllAction()
          Returns an action which will search the entire tree for choosable nodes, starting from the root.
 Action getSearchSelectedAction()
          Returns an action which will search the tree recursively for choosable nodes, starting from the selected node.
 DataNode getSelectedNode()
          Returns the datanode which is currently selected in the GUI.
protected  boolean isChoosable(DataNode node)
          Indicates whether a given node is eligable to be chosen with the Accept button.
protected  void selectNode(DataNode node)
          Called when the user has finished interacting with this chooser.
 void setControlsVisible(boolean visible)
          Sets whether the panel containing the OK and Cancel buttons is visible or not.
 void setNodeMaker(DataNodeFactory nodeMaker)
          Sets the DataNodeFactory which is used for turning objects into data nodes.
 void setRoot(DataNode node)
          Sets the root of the tree to a new node, possibly one not already in the tree.
 void setRootObject(Object obj)
          Sets the root of the displayed tree to one made from a given object.
 Thread showAllChoosable(DataNode startNode)
          Opens up the tree recursively from a given node to display all the choosable items at any level.
protected  void showNodeDetail(DataNode node)
          Invoked when the selection is changed to update the display according to the current selection.
 void valueChanged(TreeSelectionEvent evt)
          Implements the TreeSelectionListener interface; public as an implementation detail.
 
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, getPreferredSize, 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
 

Constructor Detail

TreeNodeChooser

public TreeNodeChooser()
Constructs a new chooser widget with no content.

Method Detail

setRootObject

public void setRootObject(Object obj)
                   throws NoSuchDataException
Sets the root of the displayed tree to one made from a given object. This attempts to create a DataNode from obj by feeding it to the DataNodeFactory.

Parameters:
obj - object from which to form new root node.
Throws:
NoSuchDataException

getRootSelector

public NodeRootComboBox getRootSelector()
Returns the component which allows the user to select the current root of the tree.

Returns:
root combo box;

clear

public void clear()
Removes all roots from the root selector.


setRoot

public void setRoot(DataNode node)
Sets the root of the tree to a new node, possibly one not already in the tree.

Parameters:
node - new root

getRoot

public DataNode getRoot()
Returns the root of the tree displayed in this chooser.

Returns:
root node

setControlsVisible

public void setControlsVisible(boolean visible)
Sets whether the panel containing the OK and Cancel buttons is visible or not.

Parameters:
visible - true iff OK and Cancel buttons should be seen

getChooseAction

public Action getChooseAction()
Returns the action which indicated that the currently selected node is to be used.

Returns:
choose action

getButtonPanel

public JComponent getButtonPanel()
Returns a panel into which extra buttons can be placed.

Returns:
a box for buttons

selectNode

protected void selectNode(DataNode node)
Called when the user has finished interacting with this chooser. The node argument will be the DataNode which the user has selected if s/he has selected one, or null if the user pushed the cancel button. This may be overridden to do something useful as an alternative to using the chooseDataNode(java.awt.Component, java.lang.String, java.lang.String) method. The default implementation does nothing.

Parameters:
node - the selected node, or null

chooseDataNode

public DataNode chooseDataNode(Component parent,
                               String buttonText,
                               String title)
Pops up a modal dialog which asks the user for a DataNode. The return value is a node which the user selected, or null if no selection was made.

Parameters:
parent - the parent of the dialog
buttonText - the text to appear on the 'choose' button (or null for default)
title - the title of the dialog window (or null for default)
Returns:
the selected DataNode, or null if none was selected

getChosenPath

public String getChosenPath()
Returns the path of the currently chosen node.

Returns:
chosen node path, or null if none is chosen

getSelectedNode

public DataNode getSelectedNode()
Returns the datanode which is currently selected in the GUI.

Returns:
selected node

createDialog

protected JDialog createDialog(Component parent)
Constructs the dialog component used by the chooseDataNode(java.awt.Component, java.lang.String, java.lang.String) method. This can be overridden by subclasses to customise the dialog's appearance.

Parameters:
parent - the owner of the returned dialog
Returns:
modal dialog containing this chooser

showNodeDetail

protected void showNodeDetail(DataNode node)
Invoked when the selection is changed to update the display according to the current selection. Subclasses may override this to customise the info panel.

Parameters:
node - the node currently selected

isChoosable

protected boolean isChoosable(DataNode node)
Indicates whether a given node is eligable to be chosen with the Accept button. The implementation in TreeNodeChooser always returns true.

Parameters:
node - the node to test
Returns:
true iff node can be chosen by this chooser

valueChanged

public void valueChanged(TreeSelectionEvent evt)
Implements the TreeSelectionListener interface; public as an implementation detail.

Specified by:
valueChanged in interface TreeSelectionListener

getNodeMaker

public DataNodeFactory getNodeMaker()
Returns the DataNodeFactory which is used for turning objects into data nodes. This method is used wherever a node factory is required, so subclasses may override it to change the node creation behaviour.

Returns:
the data node factory

setNodeMaker

public void setNodeMaker(DataNodeFactory nodeMaker)
Sets the DataNodeFactory which is used for turning objects into data nodes.

Parameters:
nodeMaker - the new data node factory

showAllChoosable

public Thread showAllChoosable(DataNode startNode)
Opens up the tree recursively from a given node to display all the choosable items at any level.

Parameters:
startNode - the node from which to start
Returns:
the thread in which the search is done

getSearchSelectedAction

public Action getSearchSelectedAction()
Returns an action which will search the tree recursively for choosable nodes, starting from the selected node. The tree is opened up so that all choosable nodes thus discovered are visible.

Returns:
action

getSearchAllAction

public Action getSearchAllAction()
Returns an action which will search the entire tree for choosable nodes, starting from the root. The tree is opened up so that all choosable nodes thus discovered are visible.

Returns:
action


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.