/**
   * Obtains the deepest component below the glass pane at the specified point.
   *
   * @param pt The point.
   * @return The deepest component, or <code>null</code> if there is no component at the specified
   *     point.
   */
  protected Component getDeepestComponent(Point pt) {
    // Get hold of the content pane, since this contains the components
    // that we want to relay mouse events to
    SwingUtilities.getRoot(glassPane);

    Container contentPane = glassPane.getRootPane().getContentPane();

    // Convert the mouse point from the glass pane coordinate system
    // into the coordinate system of the content pane.
    Point contentPanePt = SwingUtilities.convertPoint(glassPane, pt, contentPane);

    // Find the deepest component - i.e. the one that should get the mouse
    // event.
    Component deepestComponent =
        SwingUtilities.getDeepestComponentAt(contentPane, contentPanePt.x, contentPanePt.y);

    return deepestComponent;
  }
  public void cancel(InputEvent e) {
    if (isDisposed()) return;

    if (myPopup != null) {
      if (!canClose()) {
        return;
      }
      storeDimensionSize(myContent.getSize());
      if (myUseDimServiceForXYLocation) {
        final JRootPane root = myComponent.getRootPane();
        if (root != null) {
          final Container popupWindow = root.getParent();
          if (popupWindow != null && popupWindow.isShowing()) {
            storeLocation(popupWindow.getLocationOnScreen());
          }
        }
      }

      if (e instanceof MouseEvent) {
        IdeEventQueue.getInstance().blockNextEvents(((MouseEvent) e));
      }

      myPopup.hide(false);

      if (ApplicationManagerEx.getApplicationEx() != null) {
        StackingPopupDispatcher.getInstance().onPopupHidden(this);
      }

      if (myInStack) {
        myFocusTrackback.setForcedRestore(!myOk && myFocusable);
        myFocusTrackback.restoreFocus();
      }

      disposePopup();

      if (myListeners != null) {
        for (JBPopupListener each : myListeners) {
          each.onClosed(new LightweightWindowEvent(this, myOk));
        }
      }
    }

    Disposer.dispose(this, false);
  }
  /**
   * Causes the popup to be displayed at the specified location.
   *
   * @param component The component whose cooredinate system is to be used.
   * @param x The horizontal location of the popup
   * @param y The vertical location of the popup.
   */
  public void showPopup(JComponent component, int x, int y) {
    // Get the root (JFrame probably)
    Component rootComp = SwingUtilities.getRoot(component);

    // Determine where to place the popup
    // (Left or right, top or bottom of the mouse cursor
    // We want to fit the popup within the top level frame

    int componentMaxX = (int) rootComp.getSize().width;

    int componentMaxY = (int) rootComp.getSize().height;

    int xPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).x;

    int yPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).y;

    // Display to the right of the mouse cursor, unless
    // there is not enough room
    int deltaX = xPosOnRoot + content.getWidth() - componentMaxX;

    if (deltaX > 0) {
      xPosOnRoot -= deltaX;

      if (xPosOnRoot < 0) {
        xPosOnRoot = 0;
      }
    }

    int deltaY = yPosOnRoot + content.getHeight() - componentMaxY;

    if (deltaY > 0) {
      yPosOnRoot -= deltaY;

      if (yPosOnRoot < 0) {
        yPosOnRoot = 0;
      }
    }

    // Convert root pos back to component pos

    int xPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).x;

    int yPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).y;

    JRootPane rootPane = component.getRootPane();

    rootPane.setGlassPane(glassPane);

    // Convert the mouse point from the invoking component coordinate
    // system to the glassPane coordinate system
    Point pt = SwingUtilities.convertPoint(component, xPos, yPos, glassPane);

    // Set the location of the popup in the glass pane
    content.setLocation(pt);

    // Show the glass pane.
    glassPane.setVisible(true);

    // If the popup is set to hide automatically after a specified
    // amount of time, then reset the timer.
    if (HIDE_ON_TIMER == true) {
      timer.stop();

      timer.start();
    }
  }