コード例 #1
0
 protected Rectangle getComponentVisibleRect() {
   return myComponent.getVisibleRect();
 }
コード例 #2
0
  private void manageSearchPopup(SearchPopup searchPopup) {
    final Project project;
    if (ApplicationManager.getApplication() != null
        && !ApplicationManager.getApplication().isDisposed()) {
      project =
          PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent));
    } else {
      project = null;
    }

    if (mySearchPopup != null) {
      myPopupLayeredPane.remove(mySearchPopup);
      myPopupLayeredPane.validate();
      myPopupLayeredPane.repaint();
      myPopupLayeredPane = null;

      if (project != null) {
        ((ToolWindowManagerEx) ToolWindowManager.getInstance(project))
            .removeToolWindowManagerListener(myWindowManagerListener);
      }
    } else if (searchPopup != null) {
      FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.tree.speedsearch");
    }

    if (!myComponent.isShowing()) {
      mySearchPopup = null;
    } else {
      mySearchPopup = searchPopup;
    }

    fireStateChanged();

    if (mySearchPopup == null || !myComponent.isDisplayable()) return;

    if (project != null) {
      ((ToolWindowManagerEx) ToolWindowManager.getInstance(project))
          .addToolWindowManagerListener(myWindowManagerListener);
    }
    JRootPane rootPane = myComponent.getRootPane();
    if (rootPane != null) {
      myPopupLayeredPane = rootPane.getLayeredPane();
    } else {
      myPopupLayeredPane = null;
    }
    if (myPopupLayeredPane == null) {
      LOG.error(toString() + " in " + String.valueOf(myComponent));
      return;
    }
    myPopupLayeredPane.add(mySearchPopup, JLayeredPane.POPUP_LAYER);
    if (myPopupLayeredPane == null) return; // See # 27482. Somewho it does happen...
    Point lPaneP = myPopupLayeredPane.getLocationOnScreen();
    Point componentP = myComponent.getLocationOnScreen();
    Rectangle r = myComponent.getVisibleRect();
    Dimension prefSize = mySearchPopup.getPreferredSize();
    Window window = (Window) SwingUtilities.getAncestorOfClass(Window.class, myComponent);
    Point windowP;
    if (window instanceof JDialog) {
      windowP = ((JDialog) window).getContentPane().getLocationOnScreen();
    } else if (window instanceof JFrame) {
      windowP = ((JFrame) window).getContentPane().getLocationOnScreen();
    } else {
      windowP = window.getLocationOnScreen();
    }
    int y = r.y + componentP.y - lPaneP.y - prefSize.height;
    y = Math.max(y, windowP.y - lPaneP.y);
    mySearchPopup.setLocation(componentP.x - lPaneP.x + r.x, y);
    mySearchPopup.setSize(prefSize);
    mySearchPopup.setVisible(true);
    mySearchPopup.validate();
  }