예제 #1
0
  /**
   * Returns a <code>Popup</code> instance from the <code>PopupMenuUI</code> that has had <code>show
   * </code> invoked on it. If the current <code>popup</code> is non-null, this will invoke <code>
   * dispose</code> of it, and then <code>show</code> the new one.
   *
   * <p>This does NOT fire any events, it is up the caller to dispatch the necessary events.
   */
  private Popup getPopup() {
    Popup oldPopup = popup;

    if (oldPopup != null) {
      oldPopup.hide();
    }
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    if (isLightWeightPopupEnabled()) {
      popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
    } else {
      popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP);
    }

    // adjust the location of the popup
    Point p = adjustPopupLocationToFitScreen(desiredLocationX, desiredLocationY);
    desiredLocationX = p.x;
    desiredLocationY = p.y;

    Popup newPopup = getUI().getPopup(this, desiredLocationX, desiredLocationY);

    popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
    newPopup.show();
    return newPopup;
  }
예제 #2
0
  /**
   * Sets the visibility of the popup menu.
   *
   * @param b true to make the popup visible, or false to hide it
   * @beaninfo bound: true description: Makes the popup visible
   */
  public void setVisible(boolean b) {
    if (DEBUG) {
      System.out.println("JPopupMenu.setVisible " + b);
    }

    // Is it a no-op?
    if (b == isVisible()) return;

    // if closing, first close all Submenus
    if (b == false) {

      // 4234793: This is a workaround because JPopupMenu.firePopupMenuCanceled is
      // a protected method and cannot be called from BasicPopupMenuUI directly
      // The real solution could be to make
      // firePopupMenuCanceled public and call it directly.
      Boolean doCanceled = (Boolean) getClientProperty("JPopupMenu.firePopupMenuCanceled");
      if (doCanceled != null && doCanceled == Boolean.TRUE) {
        putClientProperty("JPopupMenu.firePopupMenuCanceled", Boolean.FALSE);
        firePopupMenuCanceled();
      }
      getSelectionModel().clearSelection();

    } else {
      // This is a popup menu with MenuElement children,
      // set selection path before popping up!
      if (isPopupMenu()) {
        MenuElement me[] = new MenuElement[1];
        me[0] = this;
        MenuSelectionManager.defaultManager().setSelectedPath(me);
      }
    }

    if (b) {
      firePopupMenuWillBecomeVisible();
      popup = getPopup();
      firePropertyChange("visible", Boolean.FALSE, Boolean.TRUE);

    } else if (popup != null) {
      firePopupMenuWillBecomeInvisible();
      popup.hide();
      popup = null;
      firePropertyChange("visible", Boolean.TRUE, Boolean.FALSE);
      // 4694797: When popup menu is made invisible, selected path
      // should be cleared
      if (isPopupMenu()) {
        MenuSelectionManager.defaultManager().clearSelectedPath();
      }
    }
  }