JIDE 3.5.15

com.jidesoft.navigation
Class BreadcrumbBar

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 com.jidesoft.navigation.BreadcrumbBar
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class BreadcrumbBar
extends JPanel

Breadcrumbs are navigation aids used in user interfaces. They allow users to keep track of their location within programs or documents. The term comes from the trail of breadcrumbs left by Hansel and Gretel in the popular fairytale. Both Windows 7 and Mac OS X introduced breadcrumb components in the file explorer and the finder respectively.

BreadcrumbBar implements the breadcrumb component using Swing. To leverage the existing Swing code, it uses the exactly the same TreeModel used in JTree as the model class. The path displayed in the breadcrumb is simply the current TreePath. If you know how to setup a TreeModel and are familiar with TreePaths, you will find it extremely easy to use the BreadcrumbBar component.

Since:
3.3.0
See Also:
Serialized Form

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
static String PROPERTY_DROPDOWN_ALLOWED
           
static String PROPERTY_MODEL
           
static String PROPERTY_SELECTED_PATH
           
 
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
BreadcrumbBar()
          Creates a BreadcrumbBar.
BreadcrumbBar(TreeModel model)
          Creates a BreadcrumbBar.
BreadcrumbBar(TreeModel model, TreePath selectedPath)
          Creates a BreadcrumbBar.
 
Method Summary
protected  String convertNodeToString(DefaultMutableTreeNode node)
          Converts the node to string.
protected  JMenuItem createMenuItem(TreePath parent, Object node)
          Creates the menu item on the drop down menu.
protected  Action createNodeAction(TreePath path, Object node)
          Creates the action to select the path.
protected  JComponent createNodeComponent(TreePath parent, Object node)
          Creates the node component.
protected  JComponent createNodeSeparator(JComponent nodeComponent, TreePath parent, Object node)
          Creates the node separator.
protected  void customizeDropDownMenu(JPopupMenu menu, TreeModel model, TreePath parent, Object node)
          Customizes the drop down menu.
protected static TreeModel getDefaultTreeModel()
          Creates and returns a sample TreeModel.
 Icon getDropDownIcon()
          Gets the drop down icon.
 TreeModel getModel()
          Gets the model.
 Icon getNextIcon()
          Gets the next icon.
protected  Icon getNodeIcon(Object node)
          Gets the icon representing the node.
protected  String getNodeString(Object node)
          Gets the string representation of the node.
 TreePath getSelectedPath()
          Gets the selected path.
protected  void initComponents()
           
 boolean isCascadeMenuAllowed()
          Gets the flag indicating if the cascade menu is allowed.
 boolean isDropDownAllowed()
          Returns the flag if the drop down is allowed.
 void setCascadeMenuAllowed(boolean cascadeMenuAllowed)
          Sets the flag indicating if the cascade menu is allowed.
 void setComponentOrientation(ComponentOrientation o)
           
 void setDropDownAllowed(boolean dropDownAllowed)
          Sets the flag whether the drop down menu will be enabled when the path separator is clicked.
 void setDropDownIcon(Icon dropDownIcon)
          Sets the drop down icon.
 void setModel(TreeModel model)
          Sets the model.
 void setNextIcon(Icon nextIcon)
          Sets the next icon.
 void setSelectedPath(TreePath selectedPath)
          Sets the selected path.
protected  void showDropDownMenu(JComponent pathComponent, JComponent pathSeparator, TreePath parent, Object node)
          Shows the drop down menu.
protected  void synchronizeRolloverEffect(JComponent c, JComponent separator)
           
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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, 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_DROPDOWN_ALLOWED

public static final String PROPERTY_DROPDOWN_ALLOWED
See Also:
Constant Field Values

PROPERTY_MODEL

public static final String PROPERTY_MODEL
See Also:
Constant Field Values

PROPERTY_SELECTED_PATH

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

BreadcrumbBar

public BreadcrumbBar()
Creates a BreadcrumbBar.


BreadcrumbBar

public BreadcrumbBar(TreeModel model)
Creates a BreadcrumbBar.

Parameters:
model - the model

BreadcrumbBar

public BreadcrumbBar(TreeModel model,
                     TreePath selectedPath)
Creates a BreadcrumbBar.

Parameters:
model - the model
selectedPath - the tree path
Method Detail

getDefaultTreeModel

protected static TreeModel getDefaultTreeModel()
Creates and returns a sample TreeModel. This model is used when you didn't pass a tree model to the constructor as the breadcrumb bar requires a model.

Returns:
the default TreeModel

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel

initComponents

protected void initComponents()

synchronizeRolloverEffect

protected void synchronizeRolloverEffect(JComponent c,
                                         JComponent separator)

getModel

public TreeModel getModel()
Gets the model.

Returns:
the model

setModel

public void setModel(TreeModel model)
Sets the model.

Parameters:
model - a new tree model

getSelectedPath

public TreePath getSelectedPath()
Gets the selected path.

Returns:
the selected path.

setSelectedPath

public void setSelectedPath(TreePath selectedPath)
Sets the selected path. This method will trigger the initComponents() method which will recreate all the children components.

Parameters:
selectedPath - the selected path.

isDropDownAllowed

public boolean isDropDownAllowed()
Returns the flag if the drop down is allowed. By default, clicking on the path separator will show a drop down menu including all the nodes at the same level. You can set this flag to false to disable this behavior.

Returns:
true or false.

setDropDownAllowed

public void setDropDownAllowed(boolean dropDownAllowed)
Sets the flag whether the drop down menu will be enabled when the path separator is clicked.

Parameters:
dropDownAllowed - true or false.

createNodeComponent

protected JComponent createNodeComponent(TreePath parent,
                                         Object node)
Creates the node component.

Parameters:
parent - the parent path
node - the node representing by this node component.
Returns:
the node component.

createNodeSeparator

protected JComponent createNodeSeparator(JComponent nodeComponent,
                                         TreePath parent,
                                         Object node)
Creates the node separator.

Parameters:
nodeComponent - the node component
parent - the parent path
node - the node representing by this node separator.
Returns:
the node separator.

getNextIcon

public Icon getNextIcon()
Gets the next icon. The next icon is used by the path separator.

Returns:
the next icon.

setNextIcon

public void setNextIcon(Icon nextIcon)
Sets the next icon. The next icon is used by the path separator.

Parameters:
nextIcon - the next icon

getDropDownIcon

public Icon getDropDownIcon()
Gets the drop down icon. The drop down icon is used by the path separator when it is clicked as it will show the drop down menu.

Returns:
the drop down icon.

setComponentOrientation

public void setComponentOrientation(ComponentOrientation o)
Overrides:
setComponentOrientation in class Component

setDropDownIcon

public void setDropDownIcon(Icon dropDownIcon)
Sets the drop down icon. The drop down icon is used by the path separator when it is clicked as it will show the drop down menu.

Parameters:
dropDownIcon - a new drop down icon.

getNodeString

protected String getNodeString(Object node)
Gets the string representation of the node.

Parameters:
node - the node.
Returns:
the String.

getNodeIcon

protected Icon getNodeIcon(Object node)
Gets the icon representing the node.

Parameters:
node - the node
Returns:
the icon.

customizeDropDownMenu

protected void customizeDropDownMenu(JPopupMenu menu,
                                     TreeModel model,
                                     TreePath parent,
                                     Object node)
Customizes the drop down menu.

Parameters:
menu - the menu to show up
model - the tree model
parent - the parent tree path
node - the node
Since:
3.5.3

showDropDownMenu

protected void showDropDownMenu(JComponent pathComponent,
                                JComponent pathSeparator,
                                TreePath parent,
                                Object node)
Shows the drop down menu.

Parameters:
pathComponent - the path component
pathSeparator - the path separator component.
parent - the parent path
node - the node

createMenuItem

protected JMenuItem createMenuItem(TreePath parent,
                                   Object node)
Creates the menu item on the drop down menu.

Parameters:
parent - the parent path
node - the node.
Returns:
the menu item.

convertNodeToString

protected String convertNodeToString(DefaultMutableTreeNode node)
Converts the node to string.

By default, it returns node.getUserObject().toString().

Parameters:
node - the node
Returns:
the string representing the node.
Since:
3.5.7

createNodeAction

protected Action createNodeAction(TreePath path,
                                  Object node)
Creates the action to select the path. It will be used when clicked on the path component as well as the menu items on the drop down menu.

Parameters:
path - the path.
node - the node.
Returns:
the action.

isCascadeMenuAllowed

public boolean isCascadeMenuAllowed()
Gets the flag indicating if the cascade menu is allowed.

Returns:
true if the cascade menu is allowed.
Since:
3.4.4
See Also:
setCascadeMenuAllowed(boolean)

setCascadeMenuAllowed

public void setCascadeMenuAllowed(boolean cascadeMenuAllowed)
Sets the flag indicating if the cascade menu is allowed.

This flag would only take effect if isDropDownAllowed() returns true. By default, the value is false to keep backward compatibility.

If you have a definite tree and the performance is not a concern, you could set this flag to true to enable your customer to have a quick selection with the help of cascade menu.

Parameters:
cascadeMenuAllowed - the flag
Since:
3.4.4

JIDE 3.5.15