コード例 #1
0
    /** Returns either a new or recycled <code>Popup</code> containing the specified children. */
    static Popup getHeavyWeightPopup(Component owner, Component contents, int ownerX, int ownerY) {
      Window window = (owner != null) ? SwingUtilities.getWindowAncestor(owner) : null;
      HeavyWeightPopup popup = null;

      if (window != null) {
        popup = getRecycledHeavyWeightPopup(window);
      }

      boolean focusPopup = false;
      if (contents != null && contents.isFocusable()) {
        if (contents instanceof JPopupMenu) {
          JPopupMenu jpm = (JPopupMenu) contents;
          Component popComps[] = jpm.getComponents();
          for (Component popComp : popComps) {
            if (!(popComp instanceof MenuElement) && !(popComp instanceof JSeparator)) {
              focusPopup = true;
              break;
            }
          }
        }
      }

      if (popup == null
          || ((JWindow) popup.getComponent()).getFocusableWindowState() != focusPopup) {

        if (popup != null) {
          // The recycled popup can't serve us well
          // dispose it and create new one
          popup._dispose();
        }

        popup = new HeavyWeightPopup();
      }

      popup.reset(owner, contents, ownerX, ownerY);

      if (focusPopup) {
        JWindow wnd = (JWindow) popup.getComponent();
        wnd.setFocusableWindowState(true);
        // Set window name. We need this in BasicPopupMenuUI
        // to identify focusable popup window.
        wnd.setName("###focusableSwingPopup###");
      }

      return popup;
    }