Class PBreadCrumbs

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class PBreadCrumbs extends JPanel implements ActionListener
This component provides a visual trail (in the form of selectable links) reflecting the pages viewed by the user. In a GUI where a user can "drill down" from one screen to another, this component provides a visual cue as to where you are, where you came from, and a mechanism to get back.
Each time the user drills down, another breadcrumb (link) is added to the trail. The user can then pop back up by clicking on any of those breadcrumbs. Selecting the initial (first) link in the trail will take the user back to the initial screen and cause all links to be removed from the breadcrumb trail.
When a link is selected indicating the user wishes to "pop back", a vetoable property change event is sent out to any registered listeners. If the event is vetoed the selection is ignored and you will remain on the current link.
Author:
kapono
See Also:
  • Field Details

  • Constructor Details

    • PBreadCrumbs

      public PBreadCrumbs()
      Instantiates the breadcrumb component
  • Method Details

    • setRoot

      public void setRoot(String tag)
      Establishes the base tag for the breadcrumb trail. This should be the tag for the screen that appears initially. The user will not see this tag/link until they drill down since they are not able to use this link for navigation until they have switched to another component.
      Parameters:
      tag - The tag for the root link in the trail.
    • getRoot

      public String getRoot()
      Retrieves the base tag for the breadcrumb trail.
      Returns:
      The base tag for the breadcrumb trail.
    • getCurrentLink

      public String getCurrentLink()
      Retrieves the current link tag
      Returns:
      The tag for the current link; null if there is no link
    • setCurrentLink

      public boolean setCurrentLink(String tag)
      A mechanism to navigate backwards to the given link (breadcrumb). An attempt will be made to locate the given link by traversing backwards up the trail. If the given link is located all links between the current link and the given link will be removed.
      Parameters:
      tag - The name/text of the link to locate
      Returns:
      true if the move was successful; false otherwise
    • getLinks

      public Enumeration getLinks()
      Retrieves the current links in the trail. Note that the Enumeration will contain the original text for each link - the separator will be removed.
      Returns:
      An Enumeration containing all the links currently in the trail.
    • establishLinks

      public void establishLinks(Enumeration elementsEnum) throws IllegalArgumentException
      Takes the Strings contained in the Enumeration and creates a brand new breadcrumb trail from it. Any existing trail is cleared prior to the new trail being created.
      This method will verify that the first link in the Enumeration matches the breadcrumb root. If it does not match, this method will throw an IllegalArgumentException.
      Throws:
      IllegalArgumentException
    • addLink

      public void addLink(String tag)
      Adds a link (breadcrumb) to the trail and establishes this link as the current location. The current location is non-selectable and will be presented non-underlined in a different color than the links.
      Parameters:
      tag - The text to display in the link
    • addActionListener

      public void addActionListener(ActionListener l)
      Used to notify the ActionListener that a link was selected in the trail
      Parameters:
      l - The ActionListener
    • removeActionListener

      public void removeActionListener(ActionListener l)
      Remove the listener from link selection notification
      Parameters:
      l - The ActionListener
    • moveToPreviousLink

      public void moveToPreviousLink()
      A mechanism to navigate back to the previous link (breadcrumb). If you move back to the root, everything in the breadcrumb trail will be removed. An ActionEvent will be delivered to all listeners indicating the new current link (replicating user selection).
    • clear

      public void clear()
      Removes all links from the trail
    • contains

      public boolean contains(String tag)
      Used to determine if the given link name is contained in the breadcrumb trail
      Parameters:
      tag - The link to search for
      Returns:
      true if the trail contains the given link; false otherwise
    • actionPerformed

      public void actionPerformed(ActionEvent ae)
      Internal listener for link selection events
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      ae - The action event