JIDE 3.5.15

com.jidesoft.navigation
Class NavigationTree

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTree
                  extended by com.jidesoft.navigation.NavigationTree
All Implemented Interfaces:
RolloverIcon.IconRolloverSupport, NavigationComponent, ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class NavigationTree
extends JTree
implements NavigationComponent, RolloverIcon.IconRolloverSupport

NavigationTree is a special tree that is designed for the navigation purpose. It has the following features.

 
 
The selection and rollover effect is painted inside the paintComponent methods of the NavigationTree after the original tree content is painted. We can't use the cell renderer to paint the effect as it is beyond the bounds of the cell renderers. So in order to prevent the cell renderer from painting the default selection effect, we override isRowSelected(int) method to always return false. If your code depends on this method to find out if a row is selected, you can use isRowSelectedOriginal(int) method.

Since:
3.3.0
See Also:
Serialized Form

Nested Class Summary
 class NavigationTree.NavigationTreeHelper
          The navigation tree helper class.
 
Nested classes/interfaces inherited from class javax.swing.JTree
JTree.AccessibleJTree, JTree.DropLocation, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeModelHandler, JTree.TreeSelectionRedirector
 
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
static String PROPERTY_EXPANDED_TIP
           
static String PROPERTY_FADE_ICON
           
static String PROPERTY_SHOW_TREE_LINES
           
static String PROPERTY_WIDE_SELECTION
           
 
Fields inherited from class javax.swing.JTree
ANCHOR_SELECTION_PATH_PROPERTY, CELL_EDITOR_PROPERTY, CELL_RENDERER_PROPERTY, cellEditor, cellRenderer, editable, EDITABLE_PROPERTY, EXPANDS_SELECTED_PATHS_PROPERTY, INVOKES_STOP_CELL_EDITING_PROPERTY, invokesStopCellEditing, LARGE_MODEL_PROPERTY, largeModel, LEAD_SELECTION_PATH_PROPERTY, ROOT_VISIBLE_PROPERTY, rootVisible, ROW_HEIGHT_PROPERTY, rowHeight, SCROLLS_ON_EXPAND_PROPERTY, scrollsOnExpand, SELECTION_MODEL_PROPERTY, selectionModel, selectionRedirector, SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles, TOGGLE_CLICK_COUNT_PROPERTY, toggleClickCount, TREE_MODEL_PROPERTY, treeModel, treeModelListener, VISIBLE_ROW_COUNT_PROPERTY, visibleRowCount
 
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
NavigationTree()
           
NavigationTree(Hashtable<?,?> value)
           
NavigationTree(Object[] value)
           
NavigationTree(TreeModel newModel)
           
NavigationTree(TreeNode root)
           
NavigationTree(TreeNode root, boolean asksAllowsChildren)
           
NavigationTree(Vector<?> value)
           
 
Method Summary
protected  NavigationComponentHelper createNavigationHelper()
          Creates the NavigationHelper which is a helper class that paints the rollover and the selection effect.
 float getIconAlpha()
          Gets the icon alpha value.
 int getNavigationRolloverRow()
          Gets the rollover row that currently has rollover effect.
 boolean isExpandedTip()
          Checks if the ExpandedTip feature is enabled.
 boolean isIconFade()
          Checks if the tree icons will fade when the mouse is not over the tree and the tree doesn't have keyboard focus.
 boolean isIconRollover(int x, int y, int width, int height)
          Checks if the mouse is over an icon.
 boolean isRowSelected(int row)
          Overrides and always return false so that the cell renderer will not paint the selection effect.
 boolean isRowSelectedOriginal(int row)
          Delegates to super.isRowSelected(row).
 boolean isShowTreeLines()
          Checks if the tree lines are visible.
 boolean isWideSelection()
          Checks if the selection and the rollover highlight covers the whole tree width.
protected  void paintComponent(Graphics g)
           
 void setExpandedTip(boolean expandedTip)
          Sets the ExpandedTip flag.
 void setFadeIcon(boolean fadeIcon)
          Sets the flag to fade the tree icons when the mouse is not over the tree and the tree doesn't have keyboard focus.
 void setIconAlpha(float iconAlpha)
           
 void setNavigationRolloverRow(int navigationRolloverRow)
          Sets the rollover row.
 void setShowTreeLines(boolean showTreeLines)
          Set the tree lines visible or invisible.
 void setWideSelection(boolean wideSelection)
          Sets the flag if the selection and the rollover highlight covers the whole tree width.
 void updateUI()
           
 
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearSelection, clearToggledPaths, collapsePath, collapseRow, convertValueToText, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAccessibleContext, getAnchorSelectionPath, getCellEditor, getCellRenderer, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getDropLocation, getDropMode, getEditingPath, getExpandedDescendants, getExpandsSelectedPaths, getInvokesStopCellEditing, getLastSelectedPathComponent, getLeadSelectionPath, getLeadSelectionRow, getMaxSelectionRow, getMinSelectionRow, getModel, getNextMatch, getPathBetweenRows, getPathBounds, getPathForLocation, getPathForRow, getPreferredScrollableViewportSize, getRowBounds, getRowCount, getRowForLocation, getRowForPath, getRowHeight, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollsOnExpand, getSelectionCount, getSelectionModel, getSelectionPath, getSelectionPaths, getSelectionRows, getShowsRootHandles, getToggleClickCount, getToolTipText, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, isEditing, isExpanded, isExpanded, isFixedRowHeight, isLargeModel, isPathEditable, isPathSelected, isRootVisible, isSelectionEmpty, isVisible, makeVisible, paramString, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setCellRenderer, setDragEnabled, setDropMode, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setModel, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, startEditingAtPath, stopEditing, treeDidChange
 
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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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

PROPERTY_SHOW_TREE_LINES

public static final String PROPERTY_SHOW_TREE_LINES
See Also:
Constant Field Values

PROPERTY_WIDE_SELECTION

public static final String PROPERTY_WIDE_SELECTION
See Also:
Constant Field Values

PROPERTY_FADE_ICON

public static final String PROPERTY_FADE_ICON
See Also:
Constant Field Values

PROPERTY_EXPANDED_TIP

public static final String PROPERTY_EXPANDED_TIP
See Also:
Constant Field Values
Constructor Detail

NavigationTree

public NavigationTree()

NavigationTree

public NavigationTree(Object[] value)

NavigationTree

public NavigationTree(Vector<?> value)

NavigationTree

public NavigationTree(Hashtable<?,?> value)

NavigationTree

public NavigationTree(TreeNode root)

NavigationTree

public NavigationTree(TreeNode root,
                      boolean asksAllowsChildren)

NavigationTree

public NavigationTree(TreeModel newModel)
Method Detail

updateUI

public void updateUI()
Overrides:
updateUI in class JTree

createNavigationHelper

protected NavigationComponentHelper createNavigationHelper()
Creates the NavigationHelper which is a helper class that paints the rollover and the selection effect.

By default, it creates a NavigationTreeHelper instance.

Returns:
a new NavigationHelper.

isIconRollover

public boolean isIconRollover(int x,
                              int y,
                              int width,
                              int height)
Description copied from interface: RolloverIcon.IconRolloverSupport
Checks if the mouse is over an icon. In the implementation, you can use a MouseMotionListener to detect the mouse position and see if it is over the icon.

Specified by:
isIconRollover in interface RolloverIcon.IconRolloverSupport
Parameters:
x - x of the icon
y - y of the icon
width - icon width
height - icon height
Returns:
true if the mouse is over the icon. False if not.

paintComponent

protected void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

isRowSelected

public boolean isRowSelected(int row)
Overrides and always return false so that the cell renderer will not paint the selection effect. If you are using this method before, please switch to isRowSelectedOriginal(int).

Overrides:
isRowSelected in class JTree
Parameters:
row - the row index.
Returns:
false.

isRowSelectedOriginal

public boolean isRowSelectedOriginal(int row)
Delegates to super.isRowSelected(row).

Parameters:
row - the row index.
Returns:
if the row is selected.

getIconAlpha

public float getIconAlpha()
Description copied from interface: RolloverIcon.IconRolloverSupport
Gets the icon alpha value. We will paint the icon using the provided alpha value to create the fade effect.

Specified by:
getIconAlpha in interface RolloverIcon.IconRolloverSupport
Returns:
the icon alpha value.

setIconAlpha

public void setIconAlpha(float iconAlpha)

isShowTreeLines

public boolean isShowTreeLines()
Checks if the tree lines are visible. Tree lines help align the node levels. However it will clutter the user interface. Since the NavigationTree is for the navigation purpose, the node level is not so important. That's why by default, it is invisible in NavigationTree.

Returns:
true or false. False by default.

setShowTreeLines

public void setShowTreeLines(boolean showTreeLines)
Set the tree lines visible or invisible. By default, it is invisible in NavigationTree.

Calling this method will trigger updateUI() being called.

Parameters:
showTreeLines - true to set the tree line visible and false to set it invisible. False by default.

isWideSelection

public boolean isWideSelection()
Checks if the selection and the rollover highlight covers the whole tree width. In a normal JTree, the selection only covers the node width. When the node is very narrow, the selection is hard to notice. For the navigation purpose, it is important that the selection row is noticeable. That's why we added this flag so that the selection always cover the whole row.

Returns:
true or false. True by default.

setWideSelection

public void setWideSelection(boolean wideSelection)
Sets the flag if the selection and the rollover highlight covers the whole tree width. It is true by default as we want to the selection to be easily noticeable in a NavigationTree.

Parameters:
wideSelection - true to make the selection and the rollover highlight covers the whole tree width, false to only cover the tree node width. It is true by default for NavigationTree.

isIconFade

public boolean isIconFade()
Checks if the tree icons will fade when the mouse is not over the tree and the tree doesn't have keyboard focus. In a regular tree, the tree icons are always visible. But if the tree is used for the navigation purpose, the tree icons are not important to show when the tree is not active as users just want to know which row is selected and don't care whether the node is expanded or collapsed. That's why we introduced this flag to hide the tree icons when the tree is no focused and mouse not over.

Specified by:
isIconFade in interface RolloverIcon.IconRolloverSupport
Returns:
true or false. True by default for the NavigationTree.

setFadeIcon

public void setFadeIcon(boolean fadeIcon)
Sets the flag to fade the tree icons when the mouse is not over the tree and the tree doesn't have keyboard focus.

Parameters:
fadeIcon - true to fade the tree icons. False to always show the tree icons.

isExpandedTip

public boolean isExpandedTip()
Checks if the ExpandedTip feature is enabled.

Returns:
true or false.
See Also:
ExpandedTipUtils

setExpandedTip

public void setExpandedTip(boolean expandedTip)
Sets the ExpandedTip flag.

Parameters:
expandedTip - true to enable the ExpandedTip feature and false to disable it. It is true by default.

getNavigationRolloverRow

public int getNavigationRolloverRow()
Gets the rollover row that currently has rollover effect.

Returns:
the row that has the rollover effect.

setNavigationRolloverRow

public void setNavigationRolloverRow(int navigationRolloverRow)
Sets the rollover row.

Parameters:
navigationRolloverRow - the row to show the rollover effect.

JIDE 3.5.15