From 8cc2925fd02c7bed051d4ada51ffb203a1c844da Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 8 Dec 2023 17:53:51 +0100 Subject: [PATCH] FlatPopupFactory: reordered some methods (nothing else changed) --- .../formdev/flatlaf/ui/FlatPopupFactory.java | 130 +++++++++--------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java index 7a25b907..211336de 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatPopupFactory.java @@ -162,67 +162,6 @@ public class FlatPopupFactory } } - /** - * Shows the given popup and, if necessary, fixes the location of a heavy weight popup window. - *

- * On a dual screen setup, where screens use different scale factors, it may happen - * that the window location changes when showing a heavy weight popup window. - * E.g. when opening a dialog on the secondary screen and making combobox popup visible. - *

- * This is a workaround for https://bugs.openjdk.java.net/browse/JDK-8224608 - */ - private static void showPopupAndFixLocation( Popup popup, Window popupWindow ) { - if( popupWindow != null ) { - // remember location of heavy weight popup window - int x = popupWindow.getX(); - int y = popupWindow.getY(); - - popup.show(); - - // restore popup window location if it has changed - // (probably scaled when screens use different scale factors) - if( popupWindow.getX() != x || popupWindow.getY() != y ) - popupWindow.setLocation( x, y ); - } else - popup.show(); - } - - private boolean isOptionEnabled( Component owner, Component contents, String clientKey, String uiKey ) { - Object value = getOption( owner, contents, clientKey, uiKey ); - return (value instanceof Boolean) ? (Boolean) value : false; - } - - private int getBorderCornerRadius( Component owner, Component contents ) { - String uiKey = - (contents instanceof BasicComboPopup) ? "ComboBox.borderCornerRadius" : - (contents instanceof JPopupMenu) ? "PopupMenu.borderCornerRadius" : - (contents instanceof JToolTip) ? "ToolTip.borderCornerRadius" : - "Popup.borderCornerRadius"; - - Object value = getOption( owner, contents, FlatClientProperties.POPUP_BORDER_CORNER_RADIUS, uiKey ); - return (value instanceof Integer) ? (Integer) value : 0; - } - - /** - * Get option from: - *

    - *
  1. client property {@code clientKey} of {@code owner} - *
  2. client property {@code clientKey} of {@code contents} - *
  3. UI property {@code uiKey} - *
- */ - private Object getOption( Component owner, Component contents, String clientKey, String uiKey ) { - for( Component c : new Component[] { owner, contents } ) { - if( c instanceof JComponent ) { - Object value = ((JComponent)c).getClientProperty( clientKey ); - if( value != null ) - return value; - } - } - - return UIManager.get( uiKey ); - } - /** * There is no API in Java 8 to force creation of heavy weight popups, * but it is possible with reflection. Java 9 provides a new method. @@ -258,6 +197,33 @@ public class FlatPopupFactory } } + private boolean isOptionEnabled( Component owner, Component contents, String clientKey, String uiKey ) { + Object value = getOption( owner, contents, clientKey, uiKey ); + return (value instanceof Boolean) ? (Boolean) value : false; + } + + /** + * Get option from: + *
    + *
  1. client property {@code clientKey} of {@code owner} + *
  2. client property {@code clientKey} of {@code contents} + *
  3. UI property {@code uiKey} + *
+ */ + private Object getOption( Component owner, Component contents, String clientKey, String uiKey ) { + for( Component c : new Component[] { owner, contents } ) { + if( c instanceof JComponent ) { + Object value = ((JComponent)c).getClientProperty( clientKey ); + if( value != null ) + return value; + } + } + + return UIManager.get( uiKey ); + } + + //---- tooltips ----------------------------------------------------------- + /** * Usually ToolTipManager places a tooltip at (mouseLocation.x, mouseLocation.y + 20). * In case that the tooltip would be partly outside of the screen, @@ -342,6 +308,8 @@ public class FlatPopupFactory ((JComponent)owner).getToolTipLocation( me ) != null; } + //---- native rounded border ---------------------------------------------- + private static boolean isWindows11BorderSupported() { return SystemInfo.isWindows_11_orLater && FlatNativeWindowsLibrary.isLoaded(); } @@ -387,6 +355,19 @@ public class FlatPopupFactory FlatNativeWindowsLibrary.setWindowCornerPreference( hwnd, FlatNativeWindowsLibrary.DWMWCP_DONOTROUND ); } + private int getBorderCornerRadius( Component owner, Component contents ) { + String uiKey = + (contents instanceof BasicComboPopup) ? "ComboBox.borderCornerRadius" : + (contents instanceof JPopupMenu) ? "PopupMenu.borderCornerRadius" : + (contents instanceof JToolTip) ? "ToolTip.borderCornerRadius" : + "Popup.borderCornerRadius"; + + Object value = getOption( owner, contents, FlatClientProperties.POPUP_BORDER_CORNER_RADIUS, uiKey ); + return (value instanceof Integer) ? (Integer) value : 0; + } + + //---- fixes -------------------------------------------------------------- + private static boolean overlapsHeavyWeightComponent( Component owner, Component contents, int x, int y ) { if( owner == null ) return false; @@ -421,7 +402,7 @@ public class FlatPopupFactory * On Linux with Wayland, since Java 21, Swing adds a window focus listener to popup owner/invoker window, * which hides the popup as soon as the owner/invoker window looses focus. * This works fine for light-weight popups. - * It also works for heavy-weight popups if the do not request focus. + * It also works for heavy-weight popups if they do not request focus. * Because FlatLaf always uses heavy-weight popups, all popups that request focus * are broken since Java 21. * @@ -449,6 +430,31 @@ public class FlatPopupFactory } } + /** + * Shows the given popup and, if necessary, fixes the location of a heavy weight popup window. + *

+ * On a dual screen setup, where screens use different scale factors, it may happen + * that the window location changes when showing a heavy weight popup window. + * E.g. when opening a dialog on the secondary screen and making combobox popup visible. + *

+ * This is a workaround for https://bugs.openjdk.java.net/browse/JDK-8224608 + */ + private static void showPopupAndFixLocation( Popup popup, Window popupWindow ) { + if( popupWindow != null ) { + // remember location of heavy weight popup window + int x = popupWindow.getX(); + int y = popupWindow.getY(); + + popup.show(); + + // restore popup window location if it has changed + // (probably scaled when screens use different scale factors) + if( popupWindow.getX() != x || popupWindow.getY() != y ) + popupWindow.setLocation( x, y ); + } else + popup.show(); + } + //---- class NonFlashingPopup --------------------------------------------- private static class NonFlashingPopup