Merged SVN plugins
[idea/community.git] / platform / platform-api / src / com / intellij / openapi / ui / popup / util / PopupUtil.java
1 package com.intellij.openapi.ui.popup.util;
2
3 import com.intellij.openapi.ui.popup.JBPopup;
4 import org.jetbrains.annotations.Nullable;
5
6 import javax.swing.*;
7 import java.awt.*;
8
9 public class PopupUtil {
10
11   private PopupUtil() {
12   }
13
14   @Nullable
15   public static Component getOwner(@Nullable Component c) {
16     if (c == null) return null;
17
18     final Window wnd = SwingUtilities.getWindowAncestor(c);
19     if (wnd instanceof JWindow) {
20       final JRootPane root = ((JWindow)wnd).getRootPane();
21       final JBPopup popup = (JBPopup)root.getClientProperty(JBPopup.KEY);
22       if (popup == null) return c;
23
24       final Component owner = popup.getOwner();
25       if (owner == null) return c;
26
27       return getOwner(owner);
28     }
29     else {
30       return c;
31     }
32   }
33
34 }