public class TreeNodeChooser extends JPanel implements TreeSelectionListener
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.
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
TreeNodeChooser()
Constructs a new chooser widget with no content.
|
Modifier and Type | Method and Description |
---|---|
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.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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
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
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, 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, transferFocusBackward, transferFocusUpCycle
public TreeNodeChooser()
public void setRootObject(Object obj) throws NoSuchDataException
obj
by feeding it
to the DataNodeFactory.obj
- object from which to form new root node.NoSuchDataException
public NodeRootComboBox getRootSelector()
public void clear()
public void setRoot(DataNode node)
node
- new rootpublic DataNode getRoot()
public void setControlsVisible(boolean visible)
visible
- true iff OK and Cancel buttons should be seenpublic Action getChooseAction()
public JComponent getButtonPanel()
protected void selectNode(DataNode node)
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.node
- the selected node, or nullpublic DataNode chooseDataNode(Component parent, String buttonText, String title)
null
if no selection was made.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)null
if none was selectedpublic String getChosenPath()
null
if none is chosenpublic DataNode getSelectedNode()
protected JDialog createDialog(Component parent)
chooseDataNode(java.awt.Component, java.lang.String, java.lang.String)
method.
This can be overridden by subclasses to customise the dialog's
appearance.parent
- the owner of the returned dialogprotected void showNodeDetail(DataNode node)
node
- the node currently selectedprotected boolean isChoosable(DataNode node)
TreeNodeChooser
always returns true
.node
- the node to testtrue
iff node
can be chosen
by this chooserpublic void valueChanged(TreeSelectionEvent evt)
valueChanged
in interface TreeSelectionListener
public DataNodeFactory getNodeMaker()
public void setNodeMaker(DataNodeFactory nodeMaker)
nodeMaker
- the new data node factorypublic Thread showAllChoosable(DataNode startNode)
startNode
- the node from which to startpublic Action getSearchSelectedAction()
public Action getSearchAllAction()
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.