Ejemplo n.º 1
0
  /**
   * Add all the menu currently available to the menu. This may be called any time BlueJ feels that
   * the menu needs to be updated.
   *
   * @param onThisProject a specific project to look for, or null for all projects.
   */
  public void addExtensionMenu(Project onThisProject) {
    // Get all menus that can be possibly be generated now.
    List<JMenuItem> menuItems = extMgr.getMenuItems(menuGenerator, onThisProject);

    // Retrieve all the items from the current menu
    MenuElement[] elements = popupMenu.getSubElements();

    for (int index = 0; index < elements.length; index++) {
      JComponent aComponent = (JComponent) elements[index].getComponent();

      if (aComponent == null) {
        continue;
      }

      if (!(aComponent instanceof JMenuItem)) {
        continue;
      }

      ExtensionWrapper aWrapper =
          (ExtensionWrapper) aComponent.getClientProperty("bluej.extmgr.ExtensionWrapper");

      if (aWrapper == null) {
        continue;
      }

      popupMenu.remove(aComponent);
    }

    popupMenu.remove(menuSeparator);

    // If the provided menu is empty we are done here.
    if (menuItems.isEmpty()) {
      return;
    }

    popupMenu.add(menuSeparator);

    for (JMenuItem menuItem : menuItems) {
      popupMenu.add(menuItem);
    }
  }
Ejemplo n.º 2
0
 /**
  * Constructor for the MenuManager object.
  *
  * @param aPopupMenu The menu that extensions are attaching to.
  */
 public MenuManager(JPopupMenu aPopupMenu) {
   extMgr = ExtensionsManager.getInstance();
   popupMenu = aPopupMenu;
   popupMenu.addPopupMenuListener(this);
   menuSeparator = new JPopupMenu.Separator();
 }