List of usage examples for com.intellij.openapi.ui.popup ComponentPopupBuilder setCancelCallback
@NotNull ComponentPopupBuilder setCancelCallback(@NotNull Computable<Boolean> shouldProceed);
From source file:com.intellij.ide.util.gotoByName.ChooseByNameBase.java
License:Apache License
protected void showTextFieldPanel() { final JLayeredPane layeredPane = getLayeredPane(); final Dimension preferredTextFieldPanelSize = myTextFieldPanel.getPreferredSize(); final int x = (layeredPane.getWidth() - preferredTextFieldPanelSize.width) / 2; final int paneHeight = layeredPane.getHeight(); final int y = paneHeight / 3 - preferredTextFieldPanelSize.height / 2; VISIBLE_LIST_SIZE_LIMIT = Math.max(10, (paneHeight - (y + preferredTextFieldPanelSize.height)) / (preferredTextFieldPanelSize.height / 2) - 1);/* w w w.ja v a 2 s . com*/ ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextFieldPanel, myTextField); builder.setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { myTextPopup = null; close(false); return Boolean.TRUE; } }).setFocusable(true).setRequestFocus(true).setModalContext(false).setCancelOnClickOutside(false); Point point = new Point(x, y); SwingUtilities.convertPointToScreen(point, layeredPane); Rectangle bounds = new Rectangle(point, new Dimension(preferredTextFieldPanelSize.width + 20, preferredTextFieldPanelSize.height)); myTextPopup = builder.createPopup(); myTextPopup.setSize(bounds.getSize()); myTextPopup.setLocation(bounds.getLocation()); new MnemonicHelper().register(myTextFieldPanel); if (myProject != null && !myProject.isDefault()) { DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup); } Disposer.register(myTextPopup, new Disposable() { @Override public void dispose() { cancelListUpdater(); } }); myTextPopup.show(layeredPane); if (myTextPopup instanceof AbstractPopup) { Window window = ((AbstractPopup) myTextPopup).getPopupWindow(); if (window instanceof JDialog) { ((JDialog) window).getRootPane().putClientProperty(WindowAction.NO_WINDOW_ACTIONS, Boolean.TRUE); } } }
From source file:com.intellij.ide.util.gotoByName.ChooseByNamePopup.java
License:Apache License
@Override protected void showList() { final JLayeredPane layeredPane = myTextField.getRootPane().getLayeredPane(); Rectangle bounds = new Rectangle(myTextFieldPanel.getLocationOnScreen(), myTextField.getSize()); bounds.y += myTextFieldPanel.getHeight() + (SystemInfo.isMac ? 3 : 1); final Dimension preferredScrollPaneSize = myListScrollPane.getPreferredSize(); if (myList.getModel().getSize() == 0) { preferredScrollPaneSize.height = UIManager.getFont("Label.font").getSize(); }//from ww w.j av a 2 s . co m preferredScrollPaneSize.width = Math.max(myTextFieldPanel.getWidth(), preferredScrollPaneSize.width); Rectangle preferredBounds = new Rectangle(bounds.x, bounds.y, preferredScrollPaneSize.width, preferredScrollPaneSize.height); Rectangle original = new Rectangle(preferredBounds); ScreenUtil.fitToScreen(preferredBounds); if (original.width > preferredBounds.width) { int height = myListScrollPane.getHorizontalScrollBar().getPreferredSize().height; preferredBounds.height += height; } myListScrollPane.setVisible(true); myListScrollPane.setBorder(null); String adText = getAdText(); if (myDropdownPopup == null) { ComponentPopupBuilder builder = JBPopupFactory.getInstance() .createComponentPopupBuilder(myListScrollPane, myListScrollPane); builder.setFocusable(false).setRequestFocus(false).setCancelKeyEnabled(false) .setFocusOwners(new JComponent[] { myTextField }).setBelongsToGlobalPopupStack(false) .setModalContext(false).setAdText(adText).setMayBeParent(true); builder.setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { return Boolean.TRUE; } }); myDropdownPopup = builder.createPopup(); myDropdownPopup.setLocation(preferredBounds.getLocation()); myDropdownPopup.setSize(preferredBounds.getSize()); myDropdownPopup.show(layeredPane); } else { myDropdownPopup.setLocation(preferredBounds.getLocation()); // in 'focus follows mouse' mode, to avoid focus escaping to editor, don't reduce popup size when list size is reduced final Dimension currentSize = myDropdownPopup.getSize(); if (UISettings.getInstance().HIDE_NAVIGATION_ON_FOCUS_LOSS || preferredBounds.width > currentSize.width || preferredBounds.height > currentSize.height) { myDropdownPopup.setSize(preferredBounds.getSize()); } } }
From source file:com.intellij.xdebugger.impl.ui.DebuggerUIUtil.java
License:Apache License
public static JBPopup createValuePopup(Project project, JComponent component, @Nullable final FullValueEvaluationCallbackImpl callback) { ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, null); builder.setResizable(true).setMovable(true) .setDimensionServiceKey(project, FULL_VALUE_POPUP_DIMENSION_KEY, false).setRequestFocus(false); if (callback != null) { builder.setCancelCallback(new Computable<Boolean>() { @Override/*from ww w. j a v a 2s . c om*/ public Boolean compute() { callback.setObsolete(); return true; } }); } return builder.createPopup(); }