2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.ui
.popup
;
19 import com
.intellij
.openapi
.ui
.popup
.Balloon
;
20 import com
.intellij
.openapi
.ui
.popup
.JBPopup
;
21 import com
.intellij
.openapi
.ui
.popup
.JBPopupFactory
;
22 import com
.intellij
.openapi
.ui
.popup
.JBPopupListener
;
23 import com
.intellij
.openapi
.wm
.impl
.IdeFrameImpl
;
24 import com
.intellij
.ui
.components
.panels
.Wrapper
;
25 import com
.intellij
.ui
.components
.panels
.NonOpaquePanel
;
29 import java
.awt
.event
.ActionListener
;
34 public class NotificationPopup
{
38 public NotificationPopup(final JComponent owner
, final JComponent content
, Color backgroud
) {
39 this(owner
, content
, backgroud
, true);
42 public NotificationPopup(final JComponent owner
, final JComponent content
, Color backgroud
, boolean useDefaultPreferredSize
) {
43 this(owner
, content
, backgroud
, useDefaultPreferredSize
, null, false);
46 public NotificationPopup(final JComponent owner
, final JComponent content
, Color backgroud
, final boolean useDefaultPreferredSize
, ActionListener clickHandler
, boolean closeOnClick
) {
47 final IdeFrameImpl frame
= findFrame(owner
);
48 if (frame
== null || !frame
.isShowing()) {
49 final FramelessNotificationPopup popup
= new FramelessNotificationPopup(owner
, content
, backgroud
, useDefaultPreferredSize
, clickHandler
);
52 public void addListener(JBPopupListener listener
) {
53 popup
.getPopup().addListener(listener
);
57 popup
.getPopup().cancel();
61 final Wrapper wrapper
= new NonOpaquePanel(content
) {
63 public Dimension
getPreferredSize() {
64 final Dimension size
= super.getPreferredSize();
65 if (useDefaultPreferredSize
) {
66 if (size
.width
> 400 || size
.height
> 200) {
75 final Balloon balloon
= JBPopupFactory
.getInstance().createBalloonBuilder(wrapper
)
77 .setHideOnClickOutside(false)
78 .setHideOnFrameResize(false)
79 .setHideOnKeyOutside(false)
80 .setCloseButtonEnabled(true)
81 .setFillColor(backgroud
)
82 .setShowCallout(false)
83 .setClickHandler(clickHandler
, closeOnClick
)
86 frame
.getBalloonLayout().add(balloon
);
89 public void addListener(JBPopupListener listener
) {
90 balloon
.addListener(listener
);
100 private IdeFrameImpl
findFrame(JComponent owner
) {
101 final Window frame
= SwingUtilities
.getWindowAncestor(owner
);
102 if (frame
instanceof IdeFrameImpl
) {
103 return (IdeFrameImpl
)frame
;
109 public JBPopup
getPopup() {
115 void addListener(JBPopupListener listener
);
119 public void addListener(JBPopupListener listener
) {