Class TreeNodeChooser
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,TreeSelectionListener
- Direct Known Subclasses:
TableNodeChooser
The general visual appearance of this component should be mostly self-explanatory. Some buttons appear near the top:
- Up: Changes the root of the tree to the parent object of the current root. In the typical case in which the current root is a directory, this means the root of the tree becomes the parent directory of the current root.
- Down: This takes the currently selected node (if there is one) and makes it into the new root node
- Home: Sets the root as the user's home directory.
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:
-
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchooseDataNode
(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 thechooseDataNode(java.awt.Component, java.lang.String, java.lang.String)
method.Returns a panel into which extra buttons can be placed.Returns the action which indicated that the currently selected node is to be used.Returns the path of the currently chosen node.Returns the DataNodeFactory which is used for turning objects into data nodes.getRoot()
Returns the root of the tree displayed in this chooser.Returns the component which allows the user to select the current root of the tree.Returns an action which will search the entire tree for choosable nodes, starting from the root.Returns an action which will search the tree recursively for choosable nodes, starting from the selected node.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
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.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
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, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
TreeNodeChooser
public TreeNodeChooser()Constructs a new chooser widget with no content.
-
-
Method Details
-
setRootObject
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
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
Sets the root of the tree to a new node, possibly one not already in the tree.- Parameters:
node
- new root
-
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
Returns the action which indicated that the currently selected node is to be used.- Returns:
- choose action
-
getButtonPanel
Returns a panel into which extra buttons can be placed.- Returns:
- a box for buttons
-
selectNode
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 thechooseDataNode(java.awt.Component, java.lang.String, java.lang.String)
method. The default implementation does nothing.- Parameters:
node
- the selected node, or null
-
chooseDataNode
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 dialogbuttonText
- 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
Returns the path of the currently chosen node.- Returns:
- chosen node path, or null if none is chosen
-
getSelectedNode
Returns the datanode which is currently selected in the GUI.- Returns:
- selected node
-
createDialog
Constructs the dialog component used by thechooseDataNode(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
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
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
Implements the TreeSelectionListener interface; public as an implementation detail.- Specified by:
valueChanged
in interfaceTreeSelectionListener
-
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
Sets the DataNodeFactory which is used for turning objects into data nodes.- Parameters:
nodeMaker
- the new data node factory
-
showAllChoosable
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
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
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
-