public class TreePanel extends JPanel implements TreeSelectionListener
Modifier and Type | Class and Description |
---|---|
private static class |
TreePanel.MyTreeNode
TreeNode extensions that allows us to associate an icon with this node.
|
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private Map<String,Component> |
catComponents
_more_
|
static String |
CATEGORY_DELIMITER |
private Map<String,DefaultMutableTreeNode> |
catToNode
Maps categories to tree node.
|
private Map<Component,DefaultMutableTreeNode> |
compToNode
Maps components to tree node.
|
private JPanel |
emptyPanel
_more_
|
private boolean |
okToSave
Whether or not it is okay to save.
|
private boolean |
okToUpdateTree
Okay to respond to selection changes.
|
private GuiUtils.CardLayoutPanel |
panel
The panel.
|
private DefaultMutableTreeNode |
root
The root.
|
private JTree |
tree
The tree.
|
private DefaultTreeModel |
treeModel
The model.
|
private JScrollPane |
treeView
The scroller.
|
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 |
---|
TreePanel()
Default constructor.
|
TreePanel(boolean useSplitPane,
int treeWidth)
Constructor that actually does the work.
|
Modifier and Type | Method and Description |
---|---|
void |
addCategoryComponent(String cat,
JComponent comp)
_more_
|
void |
addComponent(JComponent component,
String category,
String label,
ImageIcon icon)
Add the component to the panel.
|
void |
closeAll()
Close all tree paths.
|
static TreePath |
findByName(JTree tree,
List<String> names) |
static DefaultMutableTreeNode |
findNodeByPath(JTree tree,
String path) |
static String |
getPath(DefaultMutableTreeNode node) |
private static TreePath |
getPathToFirstLeaf(TreePath searchPath) |
Component |
getVisibleComponent() |
private String |
loadSavedPath() |
void |
openAll()
Open all tree paths.
|
void |
removeComponent(JComponent component)
_more_
|
private void |
saveCurrentPath(DefaultMutableTreeNode node) |
private static TreePath |
searchTree(TreePath parent,
List<String> nodes,
int depth) |
void |
setIcon(Component comp,
ImageIcon icon)
Associate an icon with a component.
|
void |
show(Component component)
Show the given
component . |
void |
showPath(Component component)
Show the tree node that corresponds to the component.
|
void |
showPersistedSelection()
Attempts to select the path from a previous McIDAS-V session.
|
static List<String> |
tokenizePath(String path) |
private void |
treeChanged() |
void |
valueChanged(TreeSelectionEvent e)
Handle tree selection changed.
|
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 static final String CATEGORY_DELIMITER
private final DefaultMutableTreeNode root
private final DefaultTreeModel treeModel
private final JScrollPane treeView
private GuiUtils.CardLayoutPanel panel
private final JPanel emptyPanel
private final Map<String,Component> catComponents
private final Map<String,DefaultMutableTreeNode> catToNode
private final Map<Component,DefaultMutableTreeNode> compToNode
private boolean okToUpdateTree
private boolean okToSave
public TreePanel()
TreePanel(boolean, int)
with
useSplitPane
set to true
and treeWidth
set to
-1
.public TreePanel(boolean useSplitPane, int treeWidth)
useSplitPane
- Whether or not to use a split pane.treeWidth
- Width of the component containing the tree.public Component getVisibleComponent()
public void valueChanged(TreeSelectionEvent e)
valueChanged
in interface TreeSelectionListener
e
- Event to handle. Cannot be null
.public void setIcon(Component comp, ImageIcon icon)
comp
- Component to associate with icon
.icon
- Icon to associate with comp
. Should not be
null
.public void addComponent(JComponent component, String category, String label, ImageIcon icon)
component
- componentcategory
- tree category. May be null.label
- Tree node labelicon
- Node icon. May be null.private void treeChanged()
public void addCategoryComponent(String cat, JComponent comp)
cat
- _more_comp
- _more_public void removeComponent(JComponent component)
component
- _more_public void show(Component component)
component
.component
- Component to show. Should not be null
.public void showPath(Component component)
component
- Component whose corresponding tree node to show. Should not be null
.public void openAll()
public void closeAll()
public void showPersistedSelection()
This method also sets okToSave
to true
, so that
user selections can be captured after this method quits.
private void saveCurrentPath(DefaultMutableTreeNode node)
private String loadSavedPath()
public static List<String> tokenizePath(String path)
public static String getPath(DefaultMutableTreeNode node)
public static DefaultMutableTreeNode findNodeByPath(JTree tree, String path)
public static TreePath findByName(JTree tree, List<String> names)
private static TreePath searchTree(TreePath parent, List<String> nodes, int depth)
private static TreePath getPathToFirstLeaf(TreePath searchPath)