- java.lang.Object
-
- bdv.ui.UIUtils
-
public final class UIUtils extends Object
AWT/Swing helpers.- Author:
- Tobias Pietzsch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUIUtils.TextPosition
-
Constructor Summary
Constructors Constructor Description UIUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddrawString(Graphics g, UIUtils.TextPosition textPosition, int line, String text)static FontgetFont(String key)static booleangetUIBoolean(String key, boolean defaultValue)Get boolean property with the specifiedkeyfrom the swingUIManager.static doublegetUIScaleFactor(Object key)Get an approximate UI scaling factor.static voidinstallFlatLafInfos()static booleanisDark(String key)Tell if the LAF color specified for the provided key is darker than 50% gray.static Colormix(Color c1, Color c2, double c1Weight)Mix colorsc1andc2by ratiosc1Weightand(1-c1Weight), respectively.static voidresetPropertyCaches()Resets the caches forgetUIScaleFactor(java.lang.Object).static voidsetMinimumHeight(Component component, int minimumHeight)Set the minimum height of a component (leaving the minimum width untouched).static voidsetMinimumWidth(Component component, int minimumWidth)Set the minimum width of a component (leaving the minimum height untouched).static voidsetPreferredHeight(Component component, int preferredHeight)Set the preferred height of a component (leaving the preferred width untouched).static voidsetPreferredWidth(Component component, int preferredWidth)Set the preferred width of a component (leaving the preferred height untouched).
-
-
-
Method Detail
-
mix
public static Color mix(Color c1, Color c2, double c1Weight)
Mix colorsc1andc2by ratiosc1Weightand(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).
-
drawString
public static void drawString(Graphics g, UIUtils.TextPosition textPosition, int line, String text)
-
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
-
resetPropertyCaches
public static void resetPropertyCaches()
Resets the caches forgetUIScaleFactor(java.lang.Object).
-
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 specifiedkeyfrom the swingUIManager. If the property is not set, returndefaultValueinstead.
-
installFlatLafInfos
public static void installFlatLafInfos()
-
-