Class MenuPiece

java.lang.Object
bibliothek.gui.dock.support.menu.MenuPiece
Direct Known Subclasses:
BaseMenuPiece, NodeMenuPiece, SeparatingMenuPiece, SubmenuPiece

public abstract class MenuPiece extends Object
Describes a part of a JMenu, can add or remove JMenuItems or other JComponents at any time to the menu.
Author:
Benjamin Sigg
  • Constructor Details

    • MenuPiece

      public MenuPiece()
  • Method Details

    • addListener

      public void addListener(MenuPieceListener listener)
      Adds a listener to this piece, the listener will get informed when the children of this piece change.
      Parameters:
      listener - the new listener
    • removeListener

      public void removeListener(MenuPieceListener listener)
      Removes listener from this piece.
      Parameters:
      listener - the listener to remove
    • fireInsert

      protected void fireInsert(int index, Component... items)
      Informs all listeners that new items were inserted.
      Parameters:
      index - the index of the first new item
      items - the new items
    • fireRemove

      protected void fireRemove(int index, int length)
      Informs all listeners that items were deleted.
      Parameters:
      index - the index of the first deleted item
      length - the number of deleted items
    • getMenu

      public JMenu getMenu()
      Gets the menu into which this MenuPiece adds its items.
      Returns:
      the menu
    • getParent

      public MenuPiece getParent()
      Gets the parent of this piece.
      Returns:
      the parent, can be null for the root or for a piece which is not yet integrated.
    • setParent

      public void setParent(MenuPiece parent)
      Sets the parent of this piece. Note that clients normally do not need to invoke this method.
      Parameters:
      parent - the parent, might be null
    • bind

      public void bind()
      This method is called if there is a possibility for the user to see this menu. The menu should register listeners, update its text etc. to be ready for that event. This method must never be called twice in a row.
      See Also:
    • unbind

      public void unbind()
      This method is called if the user has no longer any possibility to see this menu. The menu should unregister its listeners. This method must never be called twice in a row.
      See Also:
    • isBound

      public boolean isBound()
      Whether bind() was called but unbind() not yet.
      Returns:
      whether this menu piece may be visible to the user
    • getItemCount

      public abstract int getItemCount()
      Gets the number of items this MenuPiece added to its menu.
      Returns:
      the number of items
    • fill

      public abstract void fill(List<Component> items)
      Inserts all items of this piece into items.
      Parameters:
      items - the list which has to be filled in the same order as the items will appear on the menu
    • items

      public Component[] items()
      Gets all items that are shown by this piece.
      Returns:
      all items