edu.wisc.ssec.mcidasv.util
Class TreePanel

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 edu.wisc.ssec.mcidasv.util.TreePanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TreeSelectionListener

public class TreePanel
extends JPanel
implements TreeSelectionListener

This class shows a tree on the left and a card panel on the right. Ripped right out of the IDV, for the time being.

See Also:
Serialized Form

Nested Class Summary
private static class TreePanel.MyTreeNode
          TreeNode extensions that allows us to associate an icon with this node.
 
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
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
           
private  boolean okToUpdateTree
          ok 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
 
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
TreePanel()
          ctor
TreePanel(boolean useSplitPane, int treeWidth)
          _more_
 
Method Summary
 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 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 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)
           
 void show(Component 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
 
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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

CATEGORY_DELIMITER

public static final String CATEGORY_DELIMITER
See Also:
Constant Field Values

root

private final DefaultMutableTreeNode root
The root


treeModel

private final DefaultTreeModel treeModel
the model


tree

private final JTree tree
the tree


treeView

private final JScrollPane treeView
The scroller


panel

private GuiUtils.CardLayoutPanel panel
The panel


emptyPanel

private final JPanel emptyPanel
_more_


catComponents

private final Map<String,Component> catComponents
_more_


catToNode

private final Map<String,DefaultMutableTreeNode> catToNode
Maps categories to tree node


compToNode

private final Map<Component,DefaultMutableTreeNode> compToNode
Maps components to tree node


okToUpdateTree

private boolean okToUpdateTree
ok to respond to selection changes


okToSave

private boolean okToSave
Constructor Detail

TreePanel

public TreePanel()
ctor


TreePanel

public TreePanel(boolean useSplitPane,
                 int treeWidth)
_more_

Parameters:
useSplitPane - _more_
treeWidth - _more_
Method Detail

getVisibleComponent

public Component getVisibleComponent()

valueChanged

public void valueChanged(TreeSelectionEvent e)
Handle tree selection changed

Specified by:
valueChanged in interface TreeSelectionListener
Parameters:
e - event

setIcon

public void setIcon(Component comp,
                    ImageIcon icon)

addComponent

public void addComponent(JComponent component,
                         String category,
                         String label,
                         ImageIcon icon)
Add the component to the panel

Parameters:
component - component
category - tree category. May be null.
label - Tree node label
icon - Node icon. May be null.

treeChanged

private void treeChanged()

addCategoryComponent

public void addCategoryComponent(String cat,
                                 JComponent comp)
_more_

Parameters:
cat - _more_
comp - _more_

removeComponent

public void removeComponent(JComponent component)
_more_

Parameters:
component - _more_

show

public void show(Component component)

showPath

public void showPath(Component component)
Show the tree node that corresponds to the component

Parameters:
component - comp

openAll

public void openAll()
Open all paths


closeAll

public void closeAll()
Close all paths


showPersistedSelection

public void showPersistedSelection()
Attempts to select the path from a previous McIDAS-V session. If no path was persisted, the method attempts to use the "first" non-leaf node.

This method also sets okToSave to true, so that user selections can be captured after this method quits.


saveCurrentPath

private void saveCurrentPath(DefaultMutableTreeNode node)

loadSavedPath

private String loadSavedPath()

tokenizePath

public static List<String> tokenizePath(String path)

getPath

public static String getPath(DefaultMutableTreeNode node)

findNodeByPath

public static DefaultMutableTreeNode findNodeByPath(JTree tree,
                                                    String path)

findByName

public static TreePath findByName(JTree tree,
                                  List<String> names)

searchTree

private static TreePath searchTree(TreePath parent,
                                   List<String> nodes,
                                   int depth)

getPathToFirstLeaf

private static TreePath getPathToFirstLeaf(TreePath searchPath)