mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ui: JBPopup.showInCenterOf should honor predefined size
This commit is contained in:
committed by
Aleksey Pivovarov
parent
a29439eefd
commit
82c4442264
@@ -389,7 +389,7 @@ public class AbstractPopup implements JBPopup {
|
||||
|
||||
@Override
|
||||
public void showInCenterOf(@NotNull Component aContainer) {
|
||||
final Point popupPoint = getCenterOf(aContainer, myContent);
|
||||
final Point popupPoint = getCenterOf(aContainer, getPreferredContentSize());
|
||||
show(aContainer, popupPoint.x, popupPoint.y, false);
|
||||
}
|
||||
|
||||
@@ -426,6 +426,10 @@ public class AbstractPopup implements JBPopup {
|
||||
}
|
||||
|
||||
public static Point getCenterOf(final Component aContainer, final JComponent content) {
|
||||
return getCenterOf(aContainer, content.getPreferredSize());
|
||||
}
|
||||
|
||||
private static Point getCenterOf(final Component aContainer, final Dimension contentSize) {
|
||||
final JComponent component = getTargetComponent(aContainer);
|
||||
|
||||
Rectangle visibleBounds = component != null
|
||||
@@ -435,7 +439,7 @@ public class AbstractPopup implements JBPopup {
|
||||
Point containerScreenPoint = visibleBounds.getLocation();
|
||||
SwingUtilities.convertPointToScreen(containerScreenPoint, aContainer);
|
||||
visibleBounds.setLocation(containerScreenPoint);
|
||||
return UIUtil.getCenterPoint(visibleBounds, content.getPreferredSize());
|
||||
return UIUtil.getCenterPoint(visibleBounds, contentSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -579,13 +583,7 @@ public class AbstractPopup implements JBPopup {
|
||||
}
|
||||
|
||||
private RelativePoint relativePointWithDominantRectangle(final JLayeredPane layeredPane, final Rectangle bounds) {
|
||||
Dimension preferredSize = getComponent().getPreferredSize();
|
||||
if (myDimensionServiceKey != null) {
|
||||
final Dimension dimension = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
|
||||
if (dimension != null) {
|
||||
preferredSize = dimension;
|
||||
}
|
||||
}
|
||||
Dimension preferredSize = getPreferredContentSize();
|
||||
final Point leftTopCorner = new Point(bounds.x + bounds.width, bounds.y);
|
||||
final Point leftTopCornerScreen = (Point)leftTopCorner.clone();
|
||||
SwingUtilities.convertPointToScreen(leftTopCornerScreen, layeredPane);
|
||||
@@ -616,6 +614,17 @@ public class AbstractPopup implements JBPopup {
|
||||
return relativePoint;
|
||||
}
|
||||
|
||||
private Dimension getPreferredContentSize() {
|
||||
if (myForcedSize != null) {
|
||||
return myForcedSize;
|
||||
}
|
||||
if (myDimensionServiceKey != null) {
|
||||
final Dimension dimension = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
|
||||
if (dimension != null) return dimension;
|
||||
}
|
||||
return myComponent.getPreferredSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void closeOk(@Nullable InputEvent e) {
|
||||
setOk(true);
|
||||
|
||||
Reference in New Issue
Block a user