/** * Create and show popup */ private void createPopup() { if (myPopup != null) { return; } myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myChooserPanel, myChooser).setModalContext(false).setFocusable(false) .setResizable(true).setCancelOnClickOutside(false).setMinSize(new Dimension(200, 200)) .setDimensionServiceKey(myProject, "GotoFile_FileTypePopup", false).createPopup(); myPopup.addListener(new JBPopupListener.Adapter() { @Override public void onClosed(LightweightWindowEvent event) { myPopup = null; } }); myPopup.showUnderneathOf(myToolbar.getComponent()); }
private void hideAndDispose(final boolean ok) { if (myDisposed) return; myDisposed = true; hideComboBoxPopups(); final Runnable disposeRunnable = new Runnable() { @Override public void run() { myFadedOut = true; for (JBPopupListener each : myListeners) { each.onClosed(new LightweightWindowEvent(BalloonImpl.this, ok)); } Disposer.dispose(BalloonImpl.this); onDisposed(); } }; Toolkit.getDefaultToolkit().removeAWTEventListener(myAwtActivityListener); if (myLayeredPane != null) { myLayeredPane.removeComponentListener(myComponentListener); Disposer.register(ApplicationManager.getApplication(), this); // to be safe if Application suddenly exits and animation wouldn't have a chance to complete runAnimation(false, myLayeredPane, new Runnable() { @Override public void run() { disposeRunnable.run(); } }); } else { disposeRunnable.run(); } myVisible = false; myTracker = null; }
private void hideAndDispose(final boolean ok) { if (myDisposed) return; myDisposed = true; final Runnable disposeRunnable = new Runnable() { public void run() { myFadedOut = true; for (JBPopupListener each : myListeners) { each.onClosed(new LightweightWindowEvent(BalloonImpl.this, ok)); } Disposer.dispose(BalloonImpl.this); onDisposed(); } }; Toolkit.getDefaultToolkit().removeAWTEventListener(myAwtActivityListener); if (myLayeredPane != null) { myLayeredPane.removeComponentListener(myComponentListener); runAnimation(false, myLayeredPane, new Runnable() { @Override public void run() { disposeRunnable.run(); } }); } else { disposeRunnable.run(); } myVisible = false; myTracker = null; }
public FindPopupWithProgress(@NotNull final Project project, @NotNull Collection<String> variants, @NotNull Function<String, Future> function) { myFunction = function; myTextField = new TextFieldWithProgress(project, variants) { @Override public void onOk() { if (myFuture == null) { final Future future = myFunction.fun(getText().trim()); myFuture = future; showProgress(); ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { try { future.get(); okPopup(); } catch (CancellationException ex) { cancelPopup(); } catch (InterruptedException ex) { cancelPopup(); } catch (ExecutionException ex) { LOG.error(ex); cancelPopup(); } } }); } } }; myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextField, myTextField.getPreferableFocusComponent()) .setCancelOnClickOutside(true).setCancelOnWindowDeactivation(true).setCancelKeyEnabled(true).setRequestFocus(true).createPopup(); myPopup.addListener(new JBPopupListener.Adapter() { @Override public void onClosed(LightweightWindowEvent event) { if (!event.isOk()) { if (myFuture != null) { myFuture.cancel(true); } } myFuture = null; myTextField.hideProgress(); } }); final JBTextField field = new JBTextField(20); final Dimension size = field.getPreferredSize(); final Insets insets = myTextField.getBorder().getBorderInsets(myTextField); size.height += 6 + insets.top + insets.bottom; size.width += 4 + insets.left + insets.right; myPopup.setSize(size); }
@Override public void addListener(@NotNull JBPopupListener listener) { myListeners.add(listener); }
public void addListener(JBPopupListener listener) { }
/** * @param listener popup listener (will be called back when popup closed) */ public SuggestionList(@SuppressWarnings("NullableProblems") @NotNull final JBPopupListener listener) { myListener = listener; }
public void addListener(JBPopupListener listener) { myListeners.add(listener); }
public GoToHashOrRefPopup(@Nonnull final Project project, @Nonnull VcsLogRefs variants, Collection<VirtualFile> roots, @Nonnull Function<String, Future> onSelectedHash, @Nonnull Function<VcsRef, Future> onSelectedRef, @Nonnull VcsLogColorManager colorManager, @Nonnull Comparator<VcsRef> comparator) { myOnSelectedHash = onSelectedHash; myOnSelectedRef = onSelectedRef; myTextField = new TextFieldWithProgress(project, new VcsRefCompletionProvider(project, variants, roots, colorManager, comparator)) { @Override public void onOk() { if (myFuture == null) { final Future future = ((mySelectedRef == null || (!mySelectedRef.getName().equals(getText().trim()))) ? myOnSelectedHash.fun(getText().trim()) : myOnSelectedRef.fun(mySelectedRef)); myFuture = future; showProgress(); ApplicationManager.getApplication().executeOnPooledThread(() -> { try { future.get(); okPopup(); } catch (CancellationException ex) { cancelPopup(); } catch (InterruptedException ex) { cancelPopup(); } catch (ExecutionException ex) { LOG.error(ex); cancelPopup(); } }); } } }; myTextField.setAlignmentX(Component.LEFT_ALIGNMENT); JBLabel label = new JBLabel("Enter hash or branch/tag name:"); label.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD)); label.setAlignmentX(Component.LEFT_ALIGNMENT); JPanel panel = new JPanel(); BoxLayout layout = new BoxLayout(panel, BoxLayout.PAGE_AXIS); panel.setLayout(layout); panel.add(label); panel.add(myTextField); panel.setBorder(new EmptyBorder(2, 2, 2, 2)); myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField.getPreferableFocusComponent()) .setCancelOnClickOutside(true).setCancelOnWindowDeactivation(true).setCancelKeyEnabled(true).setRequestFocus(true).createPopup(); myPopup.addListener(new JBPopupListener.Adapter() { @Override public void onClosed(LightweightWindowEvent event) { if (!event.isOk()) { if (myFuture != null) { myFuture.cancel(true); } } myFuture = null; myTextField.hideProgress(); } }); }
private void hideAndDispose(final boolean ok) { if (myDisposed) return; if (mySmartFadeoutPaused) { mySmartFadeoutPaused = false; return; } if (myTraceDispose) { Logger.getInstance("#com.intellij.ui.BalloonImpl").error("Dispose balloon before showing", new Throwable()); } myDisposed = true; hideComboBoxPopups(); final Runnable disposeRunnable = () -> { myFadedOut = true; if (myRequestFocus) { if (myOriginalFocusOwner != null) { myFocusManager.requestFocus(myOriginalFocusOwner, false); } } for (JBPopupListener each : myListeners) { each.onClosed(new LightweightWindowEvent(this, ok)); } Disposer.dispose(this); onDisposed(); }; Toolkit.getDefaultToolkit().removeAWTEventListener(myAwtActivityListener); if (myLayeredPane != null) { myLayeredPane.removeComponentListener(myComponentListener); runAnimation(false, myLayeredPane, disposeRunnable); } else { disposeRunnable.run(); } myVisible = false; myTracker = null; }
@Override public void addListener(@Nonnull JBPopupListener listener) { myListeners.add(listener); }
void addListener(JBPopupListener listener);