Package bdv.ui

Class UIUtils


  • public final class UIUtils
    extends Object
    AWT/Swing helpers.
    Author:
    Tobias Pietzsch
    • Constructor Detail

      • UIUtils

        public UIUtils()
    • Method Detail

      • mix

        public static Color mix​(Color c1,
                                Color c2,
                                double c1Weight)
        Mix colors c1 and c2 by ratios c1Weight and (1-c1Weight), respectively.
      • setPreferredWidth

        public static void setPreferredWidth​(Component component,
                                             int preferredWidth)
        Set the preferred width of a component (leaving the preferred height untouched).
      • setPreferredHeight

        public static void setPreferredHeight​(Component component,
                                              int preferredHeight)
        Set the preferred height of a component (leaving the preferred width untouched).
      • setMinimumWidth

        public static void setMinimumWidth​(Component component,
                                           int minimumWidth)
        Set the minimum width of a component (leaving the minimum height untouched).
      • setMinimumHeight

        public static void setMinimumHeight​(Component component,
                                            int minimumHeight)
        Set the minimum height of a component (leaving the minimum width untouched).
      • getUIScaleFactor

        public static double getUIScaleFactor​(Object key)
        Get an approximate UI scaling factor. TODO UI scaling depends on the LAF and there is no straight forward way to get a consistent scaling factor that works on all platforms. However, some LAFs have implemented their own strategy to estimate this scaling factor and adjust font sizes and element heights accordingly. We therefore use the default font size compared to a hypothesized 'normal' font size of 12 as a surrogate for the UI scaling factor. This is not great.
        Returns:
        approximate UI scaling factor
      • getFont

        public static Font getFont​(String key)
      • isDark

        public static boolean isDark​(String key)
        Tell if the LAF color specified for the provided key is darker than 50% gray. If the property is undefined, it is considered not dark. E.g. isDark( "Panel.background" ) is often a good indicator that an LAF is dark/ inverse.
        Returns:
        true for dark colors
      • getUIBoolean

        public static boolean getUIBoolean​(String key,
                                           boolean defaultValue)
        Get boolean property with the specified key from the swing UIManager. If the property is not set, return defaultValue instead.
      • installFlatLafInfos

        public static void installFlatLafInfos()