Example usage for com.intellij.openapi.wm IdeFrame getBalloonLayout

List of usage examples for com.intellij.openapi.wm IdeFrame getBalloonLayout

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFrame getBalloonLayout.

Prototype

@Nullable
    BalloonLayout getBalloonLayout();

Source Link

Usage

From source file:com.intellij.ui.popup.NotificationPopup.java

License:Apache License

public NotificationPopup(final JComponent owner, final JComponent content, Color backgroud,
        final boolean useDefaultPreferredSize, ActionListener clickHandler, boolean closeOnClick) {
    final IdeFrame frame = findFrame(owner);
    if (frame == null || !((Window) frame).isShowing() || frame.getBalloonLayout() == null) {
        final FramelessNotificationPopup popup = new FramelessNotificationPopup(owner, content, backgroud,
                useDefaultPreferredSize, clickHandler);

        myImpl = new Impl() {
            public void addListener(JBPopupListener listener) {
                popup.getPopup().addListener(listener);
            }//from  w  w  w . j  a  v  a 2 s  .  c o  m

            public void hide() {
                popup.getPopup().cancel();
            }
        };
    } else {
        final Wrapper wrapper = new NonOpaquePanel(content) {
            @Override
            public Dimension getPreferredSize() {
                final Dimension size = super.getPreferredSize();
                if (useDefaultPreferredSize) {
                    if (size.width > 400 || size.height > 200) {
                        size.width = 400;
                        size.height = 200;
                    }
                }
                return size;
            }
        };

        final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(wrapper).setFadeoutTime(5000)
                .setHideOnClickOutside(false).setHideOnFrameResize(false).setHideOnKeyOutside(false)
                .setCloseButtonEnabled(true).setFillColor(backgroud).setShowCallout(false)
                .setClickHandler(clickHandler, closeOnClick).createBalloon();

        BalloonLayout layout = frame.getBalloonLayout();
        assert layout != null;

        layout.add(balloon);

        myImpl = new Impl() {
            public void addListener(JBPopupListener listener) {
                balloon.addListener(listener);
            }

            public void hide() {
                balloon.hide();
            }
        };
    }
}