@Override public void projectOpened() { ApplicationManager.getApplication().invokeLater((DumbAwareRunnable)() -> ApplicationManager.getApplication().runWriteAction( (DumbAwareRunnable)() -> { if (PropertiesComponent.getInstance().getBoolean(ourShowPopup, true)) { final String content = "<html>If you'd like to learn more about PyCharm Edu, " + "click <a href=\"https://www.jetbrains.com/pycharm-edu/quickstart/\">here</a> to watch a tutorial</html>"; final Notification notification = new Notification("Watch Tutorials!", "", content, NotificationType.INFORMATION, new NotificationListener.UrlOpeningListener(true)); StartupManager.getInstance(myProject).registerPostStartupActivity(() -> Notifications.Bus.notify(notification)); Balloon balloon = notification.getBalloon(); if (balloon != null) { balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { notification.expire(); } }); } notification.whenExpired(() -> PropertiesComponent.getInstance().setValue(ourShowPopup, false, true)); } })); }
/** * 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()); }
@Override public void onClosed(LightweightWindowEvent event) { for (final UserTest userTest : myStudyTaskManager.getUserTests(myTask)) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (userTest.isEditable()) { File inputFile = new File(userTest.getInput()); File outputFile = new File(userTest.getOutput()); flushBuffer(userTest.getInputBuffer(), inputFile); flushBuffer(userTest.getOutputBuffer(), outputFile); } } }); } }
private void trackDimensions(@Nullable String dimensionKey) { Window popupWindow = getPopupWindow(); if (popupWindow == null) return; ComponentListener windowListener = new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (myShown) { processOnSizeChanged(); } } }; popupWindow.addComponentListener(windowListener); addPopupListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { popupWindow.removeComponentListener(windowListener); if (dimensionKey != null && myUserSizeChanged) { WindowStateService.getInstance(myProject).putSizeFor(myProject, dimensionKey, myPrevSize); } } }); }
@Override public void onClosed(LightweightWindowEvent event) { for (final UserTest userTest : myStudyTaskManager.getUserTests(myTask)) { ApplicationManager.getApplication().runWriteAction(() -> { if (userTest.isEditable()) { File inputFile = new File(userTest.getInput()); File outputFile = new File(userTest.getOutput()); flushBuffer(userTest.getInputBuffer(), inputFile); flushBuffer(userTest.getOutputBuffer(), outputFile); } }); } }
public void setBalloon(@NotNull final Balloon balloon) { hideBalloon(); myBalloonRef = new WeakReference<Balloon>(balloon); balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (SoftReference.dereference(myBalloonRef) == balloon) { myBalloonRef = null; } } }); }
@Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } Filter filter = myFilterModel.getFilter(); final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants, getPopupText(getTextValues(filter)), supportsNegativeValues()); JBPopup popup = popupBuilder.createPopup(); popup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (event.isOk()) { Collection<String> selectedValues = popupBuilder.getSelectedValues(); if (selectedValues.isEmpty()) { myFilterModel.setFilter(null); } else { myFilterModel.setFilter(createFilter(selectedValues)); rememberValuesInSettings(selectedValues); } } } }); popup.showUnderneathOf(MultipleValueFilterPopupComponent.this); }
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; }
public FramelessNotificationPopup(final JComponent owner, final JComponent content, Color backgroud, boolean useDefaultPreferredSize, final ActionListener listener) { myBackgroud = backgroud; myUseDefaultPreferredSize = useDefaultPreferredSize; myContent = new ContentComponent(content); myActionListener = listener; myFadeInTimer = UIUtil.createNamedTimer("Frameless fade in",10, myFadeTracker); myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myContent, null) .setRequestFocus(false) .setResizable(false) .setMovable(true) .setLocateWithinScreenBounds(false) .setAlpha(0.2f).addListener(new JBPopupAdapter() { public void onClosed(LightweightWindowEvent event) { if (myFadeInTimer.isRunning()) { myFadeInTimer.stop(); } myFadeInTimer.removeActionListener(myFadeTracker); } }) .createPopup(); final Point p = RelativePoint.getSouthEastOf(owner).getScreenPoint(); Rectangle screen = ScreenUtil.getScreenRectangle(p.x, p.y); final Point initial = new Point(screen.x + screen.width - myContent.getPreferredSize().width - 50, screen.y + screen.height - 5); myPopup.showInScreenCoordinates(owner, initial); myFadeInTimer.setRepeats(true); myFadeInTimer.start(); }
@NotNull @Override public Balloon createBalloon() { final BalloonImpl result = new BalloonImpl( myContent, myBorder, myBorderInsets, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myShowCallout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myHideOnLinkClick, myClickHandler, myCloseOnClick, myAnimationCycle, myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle, myContentInsets, myShadow, mySmallVariant, myBlockClicks, myLayer); if (myStorage != null && myAnchor != null) { List<Balloon> balloons = myStorage.get(myAnchor); if (balloons == null) { myStorage.put(myAnchor, balloons = new ArrayList<Balloon>()); Disposer.register(myAnchor, new Disposable() { @Override public void dispose() { List<Balloon> toDispose = myStorage.remove(myAnchor); if (toDispose != null) { for (Balloon balloon : toDispose) { if (!balloon.isDisposed()) { Disposer.dispose(balloon); } } } } }); } balloons.add(result); result.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (!result.isDisposed()) { Disposer.dispose(result); } } }); } return result; }
private void showBalloon() { if (myBalloon != null) { Disposer.dispose(myBalloon); return; } myBalloon = JBPopupFactory.getInstance().createBalloonBuilder(myBalloonComponent) .setAnimationCycle(200) .setCloseButtonEnabled(true) .setHideOnAction(false) .setHideOnClickOutside(false) .setHideOnFrameResize(false) .setHideOnKeyOutside(false) .setSmallVariant(true) .setShadow(true) .createBalloon(); Disposer.register(myBalloon, new Disposable() { @Override public void dispose() { myBalloon = null; } }); myBalloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (myBalloon != null) { Disposer.dispose(myBalloon); } } }); myBalloon.show(new PositionTracker<Balloon>(myIcon) { @Override public RelativePoint recalculateLocation(Balloon object) { return new RelativePoint(myIcon, new Point(myIcon.getSize().width / 2, 4)); } }, Balloon.Position.above); }
@Override public void onClosed(LightweightWindowEvent event) { super.onClosed(event); if (myOnClose != null) { myOnClose.run(); } }
@Override public void beforeShown(final LightweightWindowEvent windowEvent) { final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup(); if (activeLookup != null) { activeLookup.addLookupListener(new LookupAdapter() { @Override public void currentItemChanged(LookupEvent event) { if (windowEvent.asPopup().isVisible()) { //was not canceled yet final LookupElement item = event.getItem(); if (item != null) { PsiElement targetElement = CompletionUtil.getTargetElement(item); if (targetElement == null) { targetElement = DocumentationManager.getInstance(myProject).getElementFromLookup(activeLookup.getEditor(), activeLookup.getPsiFile()); } updatePopup(targetElement); //open next } } else { activeLookup.removeLookupListener(this); } } }); } else { final Component focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject); boolean fromQuickSearch = focusedComponent != null && focusedComponent.getParent() instanceof ChooseByNameBase.JPanelProvider; if (fromQuickSearch) { ChooseByNameBase.JPanelProvider panelProvider = (ChooseByNameBase.JPanelProvider)focusedComponent.getParent(); panelProvider.registerHint(windowEvent.asPopup()); } else if (focusedComponent instanceof JComponent) { HintUpdateSupply supply = HintUpdateSupply.getSupply((JComponent)focusedComponent); if (supply != null) supply.registerHint(windowEvent.asPopup()); } } }
@Override public void projectOpened() { ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new DumbAwareRunnable() { @Override public void run() { if (PropertiesComponent.getInstance().getBoolean(ourShowPopup, true)) { final String content = "<html>If you'd like to learn more about PyCharm Edu, " + "click <a href=\"https://www.jetbrains.com/pycharm-edu/quickstart/\">here</a> to watch a tutorial</html>"; final Notification notification = new Notification("Watch Tutorials!", "", content, NotificationType.INFORMATION, new NotificationListener.UrlOpeningListener(true)); Notifications.Bus.notify(notification); Balloon balloon = notification.getBalloon(); if (balloon != null) { balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { notification.expire(); } }); } notification.whenExpired(new Runnable() { @Override public void run() { PropertiesComponent.getInstance().setValue(ourShowPopup, false, true); } }); } } }); } }); }
public void setBalloon(@NotNull final Balloon balloon) { hideBalloon(); myBalloonRef = new WeakReference<Balloon>(balloon); balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { WeakReference<Balloon> ref = myBalloonRef; if (ref != null && ref.get() == balloon) { myBalloonRef = 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; }
@NotNull public Balloon createBalloon() { final BalloonImpl result = new BalloonImpl(myContent, myBorder, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myShowCalllout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myClickHandler, myCloseOnClick, myAnimationCycle, myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle, myContentInsets, myShadow, mySmallVariant, myBlockClicks, myLayer); if (myAnchor != null) { List<Balloon> balloons = myStorage.get(myAnchor); if (balloons == null) { myStorage.put(myAnchor, balloons = new ArrayList<Balloon>()); Disposer.register(myAnchor, new Disposable() { @Override public void dispose() { List<Balloon> toDispose = myStorage.remove(myAnchor); if (toDispose != null) { for (Balloon balloon : toDispose) { if (!balloon.isDisposed()) { Disposer.dispose(balloon); } } } } }); } balloons.add(result); result.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (!result.isDisposed()) { Disposer.dispose(result); } myStorage.remove(result); } }); } return result; }
public void init(@NotNull AbstractPopup popup, T component, Ref<UsageView> usageView) { myPopup = popup; myComponent = component; myUsageView = usageView; myPopup.addPopupListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { setCanceled(); } }); }
@Override public void beforeShown(final LightweightWindowEvent windowEvent) { final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup(); if (activeLookup != null) { activeLookup.addLookupListener(new LookupAdapter() { @Override public void currentItemChanged(LookupEvent event) { if (windowEvent.asPopup().isVisible()) { //was not canceled yet final LookupElement item = event.getItem(); if (item != null) { PsiElement targetElement = CompletionUtil.getTargetElement(item); if (targetElement == null) { targetElement = DocumentationManager.getInstance(myProject).getElementFromLookup(activeLookup.getEditor(), activeLookup.getPsiFile()); } updatePopup(targetElement); //open next } } else { activeLookup.removeLookupListener(this); } } }); } else { final Component focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject); boolean fromQuickSearch = focusedComponent != null && focusedComponent.getParent() instanceof ChooseByNameBase.JPanelProvider; if (fromQuickSearch) { ChooseByNameBase.JPanelProvider panelProvider = (ChooseByNameBase.JPanelProvider)focusedComponent.getParent(); panelProvider.registerHint(windowEvent.asPopup()); } else if (focusedComponent != null) { if (focusedComponent instanceof JBListWithHintProvider) { ((JBListWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup()); } else if (focusedComponent instanceof JBTableWithHintProvider) { ((JBTableWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup()); } else if (focusedComponent instanceof JBTreeWithHintProvider) { ((JBTreeWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup()); } } } }
private JBPopup buildPopup(final JBList list, final Map<Object, String> filterIndex) { final PopupChooserBuilder listPopupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(list); listPopupBuilder.setTitle("Run a Forge command"); listPopupBuilder.setResizable(true); listPopupBuilder.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { CommandListPopupBuilder.active = false; } }); listPopupBuilder.setItemChoosenCallback((Runnable) () -> { Object selectedObject = list.getSelectedValue(); if (selectedObject instanceof UICommand) { UICommand selectedCommand = (UICommand) selectedObject; // Make sure that this cached command is still enabled if (selectedCommand.isEnabled(uiContext)) { openWizard(selectedCommand); } } }); listPopupBuilder.setFilteringEnabled(filterIndex::get); return listPopupBuilder.createPopup(); }
private void addGeneralComment(@NotNull final Project project, DataContext dataContext) { final CommentForm commentForm = new CommentForm(project, true, myIsReply, null); commentForm.setReview(myReview); if (myIsReply) { final JBTable contextComponent = (JBTable)getContextComponent(); final int selectedRow = contextComponent.getSelectedRow(); if (selectedRow >= 0) { final Object parentComment = contextComponent.getValueAt(selectedRow, 0); if (parentComment instanceof Comment) { commentForm.setParentComment(((Comment)parentComment)); } } else return; } final JBPopup balloon = CommentBalloonBuilder.getNewCommentBalloon(commentForm, myIsReply ? CrucibleBundle .message("crucible.new.reply.$0", commentForm.getParentComment().getPermId()) : CrucibleBundle .message("crucible.new.comment.$0", myReview.getPermaId())); balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if(!commentForm.getText().isEmpty()) { // do not try to save draft if text is empty commentForm.postComment(); } final JComponent component = getContextComponent(); if (component instanceof GeneralCommentsTree) { ((GeneralCommentsTree)component).refresh(); } } }); commentForm.setBalloon(balloon); balloon.showInBestPositionFor(dataContext); commentForm.requestFocus(); }
public void setBalloon(@Nonnull final Balloon balloon) { hideBalloon(); myBalloonRef = new WeakReference<>(balloon); balloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (SoftReference.dereference(myBalloonRef) == balloon) { myBalloonRef = null; } } }); }
@Override public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } Filter filter = myFilterModel.getFilter(); List<String> values = filter == null ? Collections.emptyList() : myFilterModel.getFilterValues(filter); final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants, getPopupText(values), supportsNegativeValues()); JBPopup popup = popupBuilder.createPopup(); popup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (event.isOk()) { List<String> selectedValues = popupBuilder.getSelectedValues(); if (selectedValues.isEmpty()) { myFilterModel.setFilter(null); } else { myFilterModel.setFilter(myFilterModel.createFilter(selectedValues)); rememberValuesInSettings(selectedValues); } } } }); popup.showUnderneathOf(MultipleValueFilterPopupComponent.this); }
@Nonnull @Override public Balloon createBalloon() { final BalloonImpl result = new BalloonImpl(myContent, myBorder, myBorderInsets, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myHideOnCloseClick, myShowCallout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myHideOnLinkClick, myClickHandler, myCloseOnClick, myAnimationCycle, myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle, myContentInsets, myShadow, mySmallVariant, myBlockClicks, myLayer, myRequestFocus, myPointerSize, myCornerToPointerDistance); if (myStorage != null && myAnchor != null) { List<Balloon> balloons = myStorage.get(myAnchor); if (balloons == null) { myStorage.put(myAnchor, balloons = new ArrayList<>()); Disposer.register(myAnchor, new Disposable() { @Override public void dispose() { List<Balloon> toDispose = myStorage.remove(myAnchor); if (toDispose != null) { for (Balloon balloon : toDispose) { if (!balloon.isDisposed()) { Disposer.dispose(balloon); } } } } }); } balloons.add(result); result.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (!result.isDisposed()) { Disposer.dispose(result); } } }); } return result; }
private void showBalloon() { if (myBalloon != null) { Disposer.dispose(myBalloon); return; } myBalloon = JBPopupFactory.getInstance().createBalloonBuilder(myBalloonComponent).setAnimationCycle(200).setCloseButtonEnabled(true).setHideOnAction(false) .setHideOnClickOutside(false).setHideOnFrameResize(false).setHideOnKeyOutside(false).setSmallVariant(true).setShadow(true) .createBalloon(); Disposer.register(myBalloon, new Disposable() { @Override public void dispose() { myBalloon = null; } }); myBalloon.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (myBalloon != null) { Disposer.dispose(myBalloon); } } }); myBalloon.show(new PositionTracker<Balloon>(myIcon) { @Override public RelativePoint recalculateLocation(Balloon object) { return new RelativePoint(myIcon, new Point(myIcon.getSize().width / 2, 4)); } }, Balloon.Position.above); }
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); }
private JPanel createShortContextPanel(final boolean allowNoContexts) { JPanel panel = new JPanel(new BorderLayout()); final JLabel ctxLabel = new JLabel(); final JLabel change = new JLabel(); change.setForeground(PlatformColors.BLUE); change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); panel.add(ctxLabel, BorderLayout.CENTER); panel.add(change, BorderLayout.EAST); final Runnable updateLabel = new Runnable() { @Override public void run() { myExpandByCombo.setEnabled(isExpandableFromEditor()); updateHighlighter(); StringBuilder sb = new StringBuilder(); String oldPrefix = ""; for (TemplateContextType type : getApplicableContexts()) { final TemplateContextType base = type.getBaseContextType(); String ownName = UIUtil.removeMnemonic(type.getPresentableName()); String prefix = ""; if (base != null && !(base instanceof EverywhereContextType)) { prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": "; ownName = StringUtil.decapitalize(ownName); } if (type instanceof EverywhereContextType) { ownName = "Other"; } if (sb.length() > 0) { sb.append(oldPrefix.equals(prefix) ? ", " : "; "); } if (!oldPrefix.equals(prefix)) { sb.append(prefix); oldPrefix = prefix; } sb.append(ownName); } final boolean noContexts = sb.length() == 0; String contexts = (noContexts ? "No applicable contexts" + (allowNoContexts ? "" : " yet") : "Applicable in " + sb.toString()) + ". "; ctxLabel.setText(StringUtil.first(contexts, 100, true)); ctxLabel.setForeground(noContexts ? allowNoContexts ? JBColor.GRAY : JBColor.RED : UIUtil.getLabelForeground()); change.setText(noContexts ? "Define" : "Change"); } }; new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { if (disposeContextPopup()) return false; final JPanel content = createPopupContextPanel(updateLabel, myContext); Dimension prefSize = content.getPreferredSize(); if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) { content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height))); } myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup(); myContextPopup.show(new RelativePoint(change, new Point(change.getWidth() , -content.getPreferredSize().height - 10))); myContextPopup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { myLastSize = content.getSize(); } }); return true; } }.installOn(change); updateLabel.run(); return panel; }
private JPanel createShortContextPanel(final boolean allowNoContexts) { JPanel panel = new JPanel(new BorderLayout()); final JLabel ctxLabel = new JLabel(); final JLabel change = new JLabel(); change.setForeground(PlatformColors.BLUE); change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); panel.add(ctxLabel, BorderLayout.CENTER); panel.add(change, BorderLayout.EAST); final Runnable updateLabel = new Runnable() { @Override public void run() { StringBuilder sb = new StringBuilder(); String oldPrefix = ""; for (TemplateContextType type : getApplicableContexts()) { final TemplateContextType base = type.getBaseContextType(); String ownName = UIUtil.removeMnemonic(type.getPresentableName()); String prefix = ""; if (base != null && !(base instanceof EverywhereContextType)) { prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": "; ownName = StringUtil.decapitalize(ownName); } if (type instanceof EverywhereContextType) { ownName = "Other"; } if (sb.length() > 0) { sb.append(oldPrefix.equals(prefix) ? ", " : "; "); } if (!oldPrefix.equals(prefix)) { sb.append(prefix); oldPrefix = prefix; } sb.append(ownName); } final boolean noContexts = sb.length() == 0; ctxLabel.setText((noContexts ? "No applicable contexts" + (allowNoContexts ? "" : " yet") : "Applicable in " + sb.toString()) + ". "); ctxLabel.setForeground(noContexts ? allowNoContexts ? JBColor.GRAY : JBColor.RED : UIUtil.getLabelForeground()); change.setText(noContexts ? "Define" : "Change"); } }; new ClickListener() { @Override public boolean onClick(MouseEvent e, int clickCount) { if (disposeContextPopup()) return false; final JPanel content = createPopupContextPanel(updateLabel); Dimension prefSize = content.getPreferredSize(); if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) { content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height))); } myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup(); myContextPopup.show(new RelativePoint(change, new Point(change.getWidth() , -content.getPreferredSize().height - 10))); myContextPopup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { myLastSize = content.getSize(); } }); return true; } }.installOn(change); updateLabel.run(); return panel; }
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; }