@NotNull JBPopup createPopup() { JPanel panel = new JPanel(new BorderLayout()); panel.add(myTextField, BorderLayout.CENTER); ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField) .setCancelOnClickOutside(true) .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish") .setRequestFocus(true) .setResizable(true) .setMayBeParent(true); final JBPopup popup = builder.createPopup(); popup.setMinimumSize(new Dimension(200, 90)); AnAction okAction = new DumbAwareAction() { @Override public void actionPerformed(@NotNull AnActionEvent e) { unregisterCustomShortcutSet(popup.getContent()); popup.closeOk(e.getInputEvent()); } }; okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent()); return popup; }
@Nonnull JBPopup createPopup() { JPanel panel = new JPanel(new BorderLayout()); panel.add(myTextField, BorderLayout.CENTER); ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField) .setCancelOnClickOutside(true) .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish") .setRequestFocus(true) .setResizable(true) .setMayBeParent(true); final JBPopup popup = builder.createPopup(); popup.setMinimumSize(new JBDimension(200, 90)); AnAction okAction = new DumbAwareAction() { @Override public void actionPerformed(@Nonnull AnActionEvent e) { unregisterCustomShortcutSet(popup.getContent()); popup.closeOk(e.getInputEvent()); } }; okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent()); return popup; }
private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after, final String initText) { final JTextArea textArea = new JTextArea(3, 50); textArea.setFont(UIUtil.getTreeFont()); textArea.setText(initText); final JBScrollPane pane = new JBScrollPane(textArea); final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea) .setCancelOnClickOutside(true) .setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish") .setTitle("Comment") .setMovable(true) .setRequestFocus(true).setResizable(true).setMayBeParent(true); final JBPopup popup = builder.createPopup(); final JComponent content = popup.getContent(); final AnAction action = new AnAction() { @Override public void actionPerformed(AnActionEvent e) { popup.closeOk(e.getInputEvent()); unregisterCustomShortcutSet(content); after.consume(textArea.getText()); } }; action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { popup.showInCenterOf(tree); } }, ModalityState.NON_MODAL, project.getDisposed()); }
/** Opens up the Google Login panel as a popup. */ private static void showPopup(AnActionEvent event) { GoogleLoginUsersPanel usersPanel = new GoogleLoginUsersPanel(); ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(usersPanel, usersPanel.getList()); JBPopup popup = popupBuilder.setCancelOnWindowDeactivation(true).createPopup(); JComponent source = (JComponent) event.getInputEvent().getSource(); popup.showUnderneathOf(source); }
public static JBPopup createRegExHelpPopup() throws BadLocationException { final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(new RegExHelpPopup(), null); return builder.setCancelOnClickOutside(false).setBelongsToGlobalPopupStack(true).setFocusable(true).setRequestFocus(true).setMovable(true).setResizable(true) .setCancelOnOtherWindowOpen(false).setCancelButton(new MinimizeButton("Hide")) .setTitle("Regular expressions syntax").setDimensionServiceKey(null, "RegExHelpPopup", true).createPopup(); }
@Override public void showUI() { if (myBalloon != null && myBalloon.isVisible()) { return; } if (myBalloon != null && !myBalloon.isDisposed()) { myBalloon.cancel(); } if (myBalloon == null || myBalloon.isDisposed()) { final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(this, mySearchComponent); myBalloon = builder .setProject(myHelper.getProject()) .setMovable(true) .setResizable(true) .setMayBeParent(true) .setCancelOnClickOutside(true) .setRequestFocus(true) .setCancelKeyEnabled(false) .setCancelCallback(() -> { if (!myCanClose.get()) return false; if (myIsPinned.get()) return false; if (!ApplicationManager.getApplication().isActive()) return false; if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow() == null) return false; List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(this); if (!popups.isEmpty()) { for (JBPopup popup : popups) { popup.cancel(); } return false; } if (myScopeUI.hideAllPopups()) { return false; } DimensionService.getInstance().setSize(SERVICE_KEY, myBalloon.getSize(), myHelper.getProject() ); DimensionService.getInstance().setLocation(SERVICE_KEY, myBalloon.getLocationOnScreen(), myHelper.getProject() ); ((FindManagerImpl)FindManager.getInstance(myProject)).changeGlobalSettings(myHelper.getModel()); return true; }) .createPopup(); Disposer.register(myBalloon, myDisposable); registerCloseAction(myBalloon); final Window window = WindowManager.getInstance().suggestParentWindow(myProject); Component parent = UIUtil.findUltimateParent(window); RelativePoint showPoint = null; Point screenPoint = DimensionService.getInstance().getLocation(SERVICE_KEY); if (screenPoint != null) { showPoint = new RelativePoint(screenPoint); } if (parent != null && showPoint == null) { int height = UISettings.getInstance().getShowNavigationBar() ? 135 : 115; if (parent instanceof IdeFrameImpl && ((IdeFrameImpl)parent).isInFullScreen()) { height -= 20; } showPoint = new RelativePoint(parent, new Point((parent.getSize().width - getPreferredSize().width) / 2, height)); } mySearchComponent.selectAll(); WindowMoveListener windowListener = new WindowMoveListener(this); myTitlePanel.addMouseListener(windowListener); myTitlePanel.addMouseMotionListener(windowListener); Dimension panelSize = getPreferredSize(); Dimension prev = DimensionService.getInstance().getSize(SERVICE_KEY); if (!myCbPreserveCase.isVisible()) { panelSize.width += myCbPreserveCase.getPreferredSize().width + 8; } panelSize.width += JBUI.scale(24);//hidden 'loading' icon panelSize.height *= 2; if (prev != null && prev.height < panelSize.height) prev.height = panelSize.height; myBalloon.setMinimumSize(panelSize); if (prev == null) { panelSize.height *= 1.5; panelSize.width *= 1.15; } myBalloon.setSize(prev != null ? prev : panelSize); if (showPoint != null && showPoint.getComponent() != null) { myBalloon.show(showPoint); } else { myBalloon.showCenteredInCurrentWindow(myProject); } } }
@SuppressWarnings("SSBasedInspection") private void updatePopup() { check(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { myListModel.update(); myList.revalidate(); myList.repaint(); myRenderer.recalculateWidth(); if (myBalloon == null || myBalloon.isDisposed()) { return; } if (myPopup == null || !myPopup.isVisible()) { final ActionCallback callback = ListDelegationUtil.installKeyboardDelegation(getField().getTextEditor(), myList); JBScrollPane content = new JBScrollPane(myList); content.setMinimumSize(new Dimension(myBalloon.getSize().width, 30)); final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null); myPopup = builder.setRequestFocus(false).setCancelKeyEnabled(false).setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { return myBalloon == null || myBalloon.isDisposed() || (!getField().getTextEditor().hasFocus() && !mySkipFocusGain); } }).createPopup(); myPopup.setMinimumSize(new Dimension(myBalloon.getSize().width, 30)); myPopup.getContent().setBorder(new EmptyBorder(0, 0, 0, 0)); Disposer.register(myPopup, new Disposable() { @Override public void dispose() { callback.setDone(); resetFields(); myNonProjectCheckBox.setSelected(false); ActionToolbarImpl.updateAllToolbarsImmediately(); if (myActionEvent != null && myActionEvent.getInputEvent() instanceof MouseEvent) { final Component component = myActionEvent.getInputEvent().getComponent(); if (component != null) { final JLabel label = UIUtil.getParentOfType(JLabel.class, component); if (label != null) { label.setIcon(AllIcons.Actions.FindPlain); } } } myActionEvent = null; } }); myPopup.show(new RelativePoint(getField().getParent(), new Point(0, getField().getParent().getHeight()))); //updatePopupBounds(); ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() { @Override public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { if (action instanceof TextComponentEditorAction) { return; } myPopup.cancel(); } }, myPopup); } else { myList.revalidate(); myList.repaint(); } ScrollingUtil.ensureSelectionExists(myList); if (myList.getModel().getSize() > 0) { updatePopupBounds(); } } }); }