Package org.omegat.util.gui
Class UIScale
java.lang.Object
org.omegat.util.gui.UIScale
This class handles scaling in Swing UIs. It computes a user scaling factor
based on font size and provides methods to scale integer, float,
Dimension and Insets. This class is look and feel
independent.
Two scaling modes are supported for HiDPI displays:
1) system scaling mode
This mode is supported since Java 9 on all platforms and in some Java 8 VMs (e.g. Apple and JetBrains). The JRE determines the scale factor per-display and adds a scaling transformation to the graphics object. E.g. invokesjava.awt.Graphics2D.scale( 1.5, 1.5 ) for 150%. So the JRE does the
scaling itself. E.g. when you draw a 10px line, a 15px line is drawn on
screen. The scale factor may be different for each connected display. The
scale factor may change for a window when moving the window from one display
to another one.
2) user scaling mode
This mode is mainly for Java 8 compatibility, but is also used on Linux or if the default font is changed. The user scale factor is computed based on the used font. The JRE does not scale anything. So we have to invokescale(float) where necessary. There is only one user scale factor
for all displays. The user scale factor may change if the active LaF,
"defaultFont" or "Label.font" has changed. If system scaling mode is
available, the user scale factor is usually 1, but may be larger on Linux or
if the default font is changed.
Note: This class is derived from the FlatLaf library licensed by Apache-2.0.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic floatGet scale factor.static doubleReturns the system scale factor for the given graphics context.static doubleReturns the system scale factor for the given graphics configuration.static booleanReturns true if the JRE scales, which is the case if: - environment variable GDK_SCALE is set and running on Java 9 or later - running on JetBrains Runtime 11 or later, and scaling is enabled in system Settingsstatic voidstatic floatscale(float value) Multiplies the given value by the user scale factor.static intscale(int value) Multiplies the given value by the user scale factor and rounds the result.static DimensionScales the given dimension with the user scale factor.static InsetsScales the given insets with the user scale factor.static voidIf a user scale factor is not 1, scale the given graphics context by invokingGraphics2D.scale(double, double)with a user scale factor.
-
Method Details
-
addPropertyChangeListener
-
removePropertyChangeListener
-
getSystemScaleFactor
Returns the system scale factor for the given graphics context. -
getSystemScaleFactor
Returns the system scale factor for the given graphics configuration. -
getScaleFactor
public static float getScaleFactor()Get scale factor.- Returns:
- float number.
-
scale
public static float scale(float value) Multiplies the given value by the user scale factor. -
scale
public static int scale(int value) Multiplies the given value by the user scale factor and rounds the result. -
scaleGraphics
If a user scale factor is not 1, scale the given graphics context by invokingGraphics2D.scale(double, double)with a user scale factor. -
scale
Scales the given dimension with the user scale factor.If a user scale factor is 1, then the given dimension is simply returned. Otherwise, a new instance of
DimensionorDimensionUIResourceis returned, depending on whether the passed dimension implementsUIResource. -
scale
Scales the given insets with the user scale factor.If a user scale factor is 1, then the given insets are simply returned. Otherwise, a new instance of
InsetsorInsetsUIResourceis returned, depending on whether the passed dimension implementsUIResource. -
isSystemScaling
public static boolean isSystemScaling()Returns true if the JRE scales, which is the case if: - environment variable GDK_SCALE is set and running on Java 9 or later - running on JetBrains Runtime 11 or later, and scaling is enabled in system Settings
-