예제 #1
0
  /** Alter the bounds of the popup just before it is made visible. */
  @Override
  public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    JComboBox comboBox = (JComboBox) e.getSource();

    if (comboBox.getItemCount() == 0) return;

    final Object child = comboBox.getAccessibleContext().getAccessibleChild(0);

    if (child instanceof BasicComboPopup) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              customizePopup((BasicComboPopup) child);
            }
          });
    }
  }
예제 #2
0
  /**
   * Notify to all valid extensions that this menu Item is about to be displayed.
   *
   * @param event The associated event
   */
  @Override
  public void popupMenuWillBecomeVisible(PopupMenuEvent event) {
    int itemsCount = 0;

    JPopupMenu aPopup = (JPopupMenu) event.getSource();

    MenuElement[] elements = aPopup.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;
      }

      if (!aWrapper.isValid()) {
        popupMenu.remove(aComponent);

        continue;
      }

      aWrapper.safePostMenuItem(menuGenerator, (JMenuItem) aComponent);

      itemsCount++;
    }

    if (itemsCount <= 0) {
      popupMenu.remove(menuSeparator);
    }
  }