public SpeedSearchBase(Comp component) { myComponent = component; myComponent.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { manageSearchPopup(null); } }); myComponent.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { processKeyEvent(e); } public void keyPressed(KeyEvent e) { processKeyEvent(e); } }); installSupplyTo(component); }
public SpeedSearchBase(Comp component) { myComponent = component; myComponent.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { manageSearchPopup(null); } }); myComponent.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent e) { processKeyEvent(e); } public void keyPressed(KeyEvent e) { processKeyEvent(e); } }); component.putClientProperty(SPEED_SEARCH_COMPONENT_MARKER, this); }
protected Point getComponentLocationOnScreen() { return myComponent.getLocationOnScreen(); }
protected Rectangle getComponentVisibleRect() { return myComponent.getVisibleRect(); }
private void manageSearchPopup(@Nullable 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 = getComponentLocationOnScreen(); Rectangle r = getComponentVisibleRect(); 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(); }