@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)); } })); }
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); } } }); }
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); }
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 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; } } }); }
@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(); } }); }
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); }
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; }