Class JideMenu

All Implemented Interfaces:
Alignable, ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
Direct Known Subclasses:
JideSplitButton

public class JideMenu extends JMenu implements Alignable
A special implementation of JMenu. It is used to replace JMenu in order to use with CommandBar.
It has two special features. First, it has a PopupMenuCustomizer for lazy menu creation. Instead of creating menu upfront which might be quite expensive, you can create it using PopupMenuCustomizer. PopupMenuCustomizer is called before the menu is set visible. Please note, when you use PopupMenuCustomizer, you need to remove the old menu items you added previously using PopupMenuCustomizer. Otherwise, you will see a menu which gets longer and longer when you show it. See below for an example.
 JideMenu jideMenu = new JideMenu("Dynamic");
 jideMenu.setPopupMenuCustomizer(new JideMenu.PopupMenuCustomizer(){
     public void customize(JPopupMenu menu) {
         menu.add("item 1");
         menu.add("item 2");
         menu.add("item 3");
         menu.add("item 4");
         menu.add("item 5");
     }
 });
 

Second feature is popup alignment. Usually menu and its popup align to the left side. In our case, we hope they align to right side. So we added a method call setPreferredPopupHorizontalAlignment(). You can set to RIGHT if you want to.

See Also:
  • Field Details

    • DELAY

      public static int DELAY
  • Constructor Details

    • JideMenu

      public JideMenu()
    • JideMenu

      public JideMenu(String s)
    • JideMenu

      public JideMenu(Action a)
    • JideMenu

      public JideMenu(String s, boolean b)
  • Method Details

    • initMenu

      protected void initMenu()
    • isTopLevelMenu

      public boolean isTopLevelMenu()
      Checks if the menu is added to a top level menu container. It will be consider as top level menu when
      1. getParent() equals null, or
      2. getParent() is not an instance of JPopupMenu
      Please note, the definition of topLevelMenu is different from that of JMenu.
      Overrides:
      isTopLevelMenu in class JMenu
      Returns:
      true if it's top level menu.
    • getOriginCalculator

      public JideMenu.PopupMenuOriginCalculator getOriginCalculator()
      Gets the PopupMenuOriginCalculator or null, if none has been specified.
      Returns:
      the calculator
    • setOriginCalculator

      public void setOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator)
      Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.
      Parameters:
      originCalculator - the calculator
    • getMenuCreator

      @Deprecated public JideMenu.MenuCreator getMenuCreator()
      Gets the MenuCreator.
      Returns:
      the MenuCreator.
    • setMenuCreator

      @Deprecated public void setMenuCreator(JideMenu.MenuCreator menuCreator)
      Sets the MenuCreator. MenuCreator can be used to do lazy menu creation. If you put code in the MenuCreator, it won't be called until before the menu is set visible.
      Parameters:
      menuCreator - he menu creator
    • getPopupMenuCustomizer

      public JideMenu.PopupMenuCustomizer getPopupMenuCustomizer()
      Gets the PopupMenuCustomizer.
      Returns:
      the PopupMenuCustomizer.
    • setPopupMenuCustomizer

      public void setPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer)
      Sets the PopupMenuCustomizer. PopupMenuCustomizer can be used to do lazy menu creation. If you put code in the MenuCreator, it won't be called until before the menu is set visible.

      PopupMenuCustomizer has a customize method. The popup menu of this menu will be passed in. You can add/remove/change the menu items in customize method. For example, instead of

       JideMenu menu = new JideMenu();
       menu.add(new JMenuItem("..."));
       menu.add(new JMenuItem("..."));
       
      You can do
       JideMenu menu = new JideMenu();
       menu.setPopupMenuCustomzier(new JideMenu.PopupMenuCustomizer() {
           void customize(JPopupMenu popupMenu) {
               poupMenu.removeAll();
               popupMenu.add(new JMenuItem("..."));
               popupMenu.add(new JMenuItem("..."));
           }
       }
       
      If the menu is never used, the two add methods will never be called thus improve the performance.
      Parameters:
      customizer - the popup menu customizer
    • getPopupMenuOrigin

      protected Point getPopupMenuOrigin()
      Overrides:
      getPopupMenuOrigin in class JMenu
    • isOpaque

      public boolean isOpaque()
      Checks if the
      Overrides:
      isOpaque in class JComponent
      Returns:
      false if it's top level menu. Otherwise, it will return what super.isOpaque().
    • originalIsOpaque

      public boolean originalIsOpaque()
    • hideMenu

      protected void hideMenu()
    • getPreferredPopupHorizontalAlignment

      public int getPreferredPopupHorizontalAlignment()
    • setPreferredPopupHorizontalAlignment

      public void setPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment)
    • getPreferredPopupVerticalAlignment

      public int getPreferredPopupVerticalAlignment()
    • setPreferredPopupVerticalAlignment

      public void setPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment)
    • supportVerticalOrientation

      public boolean supportVerticalOrientation()
      Description copied from interface: Alignable
      Checks if the component support vertical orientation. doesn't consider the component orientation, it should return false.
      Specified by:
      supportVerticalOrientation in interface Alignable
      Returns:
      true if it supports vertical orientation
    • supportHorizontalOrientation

      public boolean supportHorizontalOrientation()
      Description copied from interface: Alignable
      Checks if the component support horizontal orientation.
      Specified by:
      supportHorizontalOrientation in interface Alignable
      Returns:
      true if it supports horizontal orientation
    • setOrientation

      public void setOrientation(int orientation)
      Description copied from interface: Alignable
      Changes the orientation. If the component is a Swing component, the default implementation is this.
      JideSwingUtilities.setOrientationOf(this, orientation);
      Specified by:
      setOrientation in interface Alignable
      Parameters:
      orientation - the new orientation
    • getOrientation

      public int getOrientation()
      Description copied from interface: Alignable
      Gets the orientation. If the component is a Swing component, the default implementation is this.
      return JideSwingUtilities.getOrientationOf(this);
      Specified by:
      getOrientation in interface Alignable
      Returns:
      orientation
    • setPopupMenuVisible

      public void setPopupMenuVisible(boolean b)
      Overrides:
      setPopupMenuVisible in class JMenu
    • shouldHidePopupMenu

      protected boolean shouldHidePopupMenu()
      Check if the popup menu should stay hidden although setPopupMenuVisible(boolean) is invoked.

      The default implementation is to check if it contains any menu items. You could override this method to change the default behavior.

      Returns:
      true if the popup menu should stay invisible. Otherwise false.