diff options
Diffstat (limited to 'platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java')
-rw-r--r-- | platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index e1c326d33cd8..78802ccdf6bb 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -337,7 +337,7 @@ public class AbstractPopup implements JBPopup { } public void setShowHints(boolean show) { - final Window ancestor = SwingUtilities.getWindowAncestor(myComponent); + final Window ancestor = getContentWindow(myComponent); if (ancestor instanceof RootPaneContainer) { final JRootPane rootPane = ((RootPaneContainer)ancestor).getRootPane(); if (rootPane != null) { @@ -757,7 +757,33 @@ public class AbstractPopup implements JBPopup { PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog); myNativePopup = factory.isNativePopup(); - myPopup = factory.getPopup(myOwner, myContent, targetBounds.x, targetBounds.y, this); + Component popupOwner = myOwner; + if (popupOwner instanceof RootPaneContainer) { + // JDK uses cached heavyweight popup for a window ancestor + RootPaneContainer root = (RootPaneContainer)popupOwner; + popupOwner = root.getRootPane(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("expected preferred size: " + myContent.getPreferredSize()); + } + myPopup = factory.getPopup(popupOwner, myContent, targetBounds.x, targetBounds.y, this); + if (LOG.isDebugEnabled()) { + LOG.debug(" actual preferred size: " + myContent.getPreferredSize()); + } + if ((targetBounds.width != myContent.getWidth()) || (targetBounds.height != myContent.getHeight())) { + // JDK uses cached heavyweight popup that is not initialized properly + LOG.debug("the expected size is not equal to the actual size"); + Window popup = myPopup.getWindow(); + if (popup != null) { + popup.setSize(targetBounds.width, targetBounds.height); + if (myContent.getParent().getComponentCount() != 1) { + LOG.debug("unexpected count of components in heavy-weight popup"); + } + } + else { + LOG.debug("cannot fix size for non-heavy-weight popup"); + } + } if (myResizable) { final JRootPane root = myContent.getRootPane(); @@ -799,13 +825,10 @@ public class AbstractPopup implements JBPopup { listener.beforeShown(new LightweightWindowEvent(this)); } - // can be improved by moving in myPopup code - myPopup.getWindow().setSize(myContent.getSize()); - myPopup.setRequestFocus(myRequestFocus); myPopup.show(); - final Window window = SwingUtilities.getWindowAncestor(myContent); + final Window window = getContentWindow(myContent); myWindow = window; @@ -1185,14 +1208,17 @@ public class AbstractPopup implements JBPopup { size = computeWindowSize(size); - final Window window = SwingUtilities.getWindowAncestor(myContent); - window.setSize(size); + final Window window = getContentWindow(myContent); + if (window != null) { + window.setSize(size); + } } public void pack() { - final Window window = SwingUtilities.getWindowAncestor(myContent); - - window.pack(); + final Window window = getContentWindow(myContent); + if (window != null) { + window.pack(); + } } public JComponent getComponent() { @@ -1211,6 +1237,10 @@ public class AbstractPopup implements JBPopup { } myDisposed = true; + if (LOG.isDebugEnabled()) { + LOG.debug("start disposing " + myContent); + } + Disposer.dispose(this, false); ApplicationManager.getApplication().assertIsDispatchThread(); @@ -1257,6 +1287,10 @@ public class AbstractPopup implements JBPopup { IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone); getFocusManager().doWhenFocusSettlesDown(runFinal); } + + if (LOG.isDebugEnabled()) { + LOG.debug("stop disposing content"); + } } private void resetWindow() { @@ -1385,15 +1419,27 @@ public class AbstractPopup implements JBPopup { } public static Window moveTo(JComponent content, Point screenPoint, final Dimension headerCorrectionSize) { - setDefaultCursor(content); - final Window wnd = SwingUtilities.getWindowAncestor(content); - if (headerCorrectionSize != null) { - screenPoint.y -= headerCorrectionSize.height; + final Window wnd = getContentWindow(content); + if (wnd != null) { + wnd.setCursor(Cursor.getDefaultCursor()); + if (headerCorrectionSize != null) { + screenPoint.y -= headerCorrectionSize.height; + } + wnd.setLocation(screenPoint); } - wnd.setLocation(screenPoint); return wnd; } + private static Window getContentWindow(Component content) { + Window window = SwingUtilities.getWindowAncestor(content); + if (window == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("no window ancestor for " + content); + } + } + return window; + } + @Override public Point getLocationOnScreen() { Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null; @@ -1467,7 +1513,7 @@ public class AbstractPopup implements JBPopup { } public static void setDefaultCursor(JComponent content) { - final Window wnd = SwingUtilities.getWindowAncestor(content); + final Window wnd = getContentWindow(content); if (wnd != null) { wnd.setCursor(Cursor.getDefaultCursor()); } |