Package com.nomagic.ui
Class HiDPIScaleUtilities
- java.lang.Object
 - 
- com.nomagic.ui.HiDPIScaleUtilitiesInternal
 - 
- com.nomagic.ui.HiDPIScaleUtilities
 
 
 
- 
@OpenApiAll public class HiDPIScaleUtilities extends com.nomagic.ui.HiDPIScaleUtilitiesInternalUtilities to work with various scaling aspects on HiDPI screens.These utilities do not have any affect on Mac Retina screens. On Retina screens
RetinaUtilitiesshould be used.There are two types of scaling factors: system and user. System scaling factor is managed by JVM. If it is enabled - graphics is scaled automatically. System Scaling factor is calculated using
Toolkit.getScreenResolution()value. User scaling factor is defined by user supplying jvm argument magicdraw.resolution.scale. For example -Dmagicdraw.resolution.scale=2 means scale ui two times. Both scaling factors has multiplicative relation, ui is scaled by both scaling factors. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHiDPIScaleUtilities.ScaledLFIcon 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHI_DPI_SCALEDprivate static java.lang.StringHIDPI_SCALED_LF_KEYprivate static java.util.Map<com.nomagic.ui.IconSizeKey,ResizableIcon>SIZE_ICONS_IMAGEprivate static doublesystemScalingFactorprivate static doubleuserScalingFactorprivate static java.awt.FontwindowsDefaultGUIFont 
- 
Constructor Summary
Constructors Constructor Description HiDPIScaleUtilities() 
- 
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static booleanacceptForUIScaling(java.awt.Component component)static voidaddHiDPIScaledProperty(java.awt.Component component)Mark this component as HiDPI scaledstatic voidadjustFontByLookAndFeelDefaults(java.awt.Component component)Apply L&F default font group if this is Windows L&Fstatic floatcalculateSystemScaleFactor()Calculates system scaling factor.private static voidfixWindowsFont(javax.swing.UIDefaults ui, java.util.Collection<java.awt.Font> defaultWindowsFonts, java.awt.Font segoeUIFont, java.lang.String key)static voidfixWindowsFonts()private static voidfixWindowsFonts(javax.swing.UIDefaults ui)private static doublegetDefinedScalingFactor()Program defined scaling factor.static ResizableIcongetNonScaledIcon(ResizableIcon icon, int size, double maxScale)Return icon scaled down to a given size.static doublegetReducedScalingFactor()Deprecated.use getReducedUserScalingFactor()static doublegetReducedUserScalingFactor()In some cased real scaling scales UI too much.static ResizableIcongetScaled16x16Icon(ResizableIcon icon)Return scaled to 16x16 icon for a given icon.static floatgetScaleFactorByScreenResolution()Deprecated.use calculateSystemScaleFactor()static doublegetScalingFactor()Deprecated.use getUserScalingFactor()private static java.awt.FontgetSegoeUIFont()Segoe UI Font scales nicely with fractional scale.static ResizableIcongetSystemScaled16x16Icon(ResizableIcon icon)static ResizableIcongetSystemScaledIcon(ResizableIcon icon)Return resizable icon scaled by system scale factor.private static ResizableIcongetSystemScaledIcon(ResizableIcon icon, int size)static doublegetSystemScaleFactor()System scale factor.private static doublegetSystemScalingFactor()System defined scaling factor.private static doublegetUserDefinedScaleFactor()static doublegetUserScalingFactor()User scale factor.private static java.awt.FontgetWindowsDefaultGUIFont()private static java.util.Set<java.awt.Font>getWindowsDefaultGUIFonts()Fonts that do not scale well with fractional scale.static booleanisScalingFactorDefined()Checks if system or user scaling factor is defined.static booleanisScalingFactorFromProperty()Deprecated.isUserScalingFactorDefined()static booleanisSystemScalingEnabled()Checks if system scaling is enabled.static booleanisUserScalingFactorDefined()Checks if user scaling factor is defined by jvm argument magicdraw.resolution.scale.static booleanisWindowsLookAndFeel()Check if Windows Look and Feel is active.private static floatnormalizeScaleFactor(float scale)static doublescaleByComponent(java.awt.Component component, double value)static intscaleByComponent(java.awt.Component component, int value)private static doublescaleByGraphics(java.awt.GraphicsConfiguration graphicsConfiguration, double value, java.util.function.Function<java.lang.Double,java.lang.Double> roundingFunction)static voidscaleComponent(HiDPIScalableComponent component)Scale components and its children preferred size and similar.static floatscaleDownFont(float size)Scale font size down.static floatscaleFont(float size)Scale font size.static intscaleIcon(int size)Scale Icon size.private static intscaleIcon(int size, double scalingFactor)private static voidscaleIcons()private static floatscaleLFFont(float size)Scale L&F font size.private static voidscaleLFIcon(java.lang.String iconName)private static voidscaleLFIcon(java.lang.String iconName, double scalingFactor)private static javax.swing.IconscaleLFIcon(javax.swing.Icon icon, boolean onlyIfImageIcon, double scalingFactor)Scale given icon if it was not scaled yetstatic voidscaleLookAndFeel()Scale various java Look&Feel settings like fonts, icons sizes, insets and etc.static doublescaleUI(double size)Scale User Interface item size.static intscaleUI(int size)Scale User Interface item size.private static voidscaleUI(java.awt.Component component)Scale components preferred size and similar.static voidscaleUIRecursively(java.awt.Component component)Scale components and its children preferred size and similar.private static booleanshouldFixWindowsFonts()static intsystemScaleValueUp(int value)Scales given value by system scale factor. 
 - 
 
- 
- 
Field Detail
- 
HIDPI_SCALED_LF_KEY
private static final java.lang.String HIDPI_SCALED_LF_KEY
- See Also:
 - Constant Field Values
 
 
- 
HI_DPI_SCALED
public static final java.lang.String HI_DPI_SCALED
- See Also:
 - Constant Field Values
 
 
- 
userScalingFactor
private static double userScalingFactor
 
- 
systemScalingFactor
private static final double systemScalingFactor
 
- 
windowsDefaultGUIFont
private static java.awt.Font windowsDefaultGUIFont
 
- 
SIZE_ICONS_IMAGE
private static final java.util.Map<com.nomagic.ui.IconSizeKey,ResizableIcon> SIZE_ICONS_IMAGE
 
 - 
 
- 
Method Detail
- 
isSystemScalingEnabled
public static boolean isSystemScalingEnabled()
Checks if system scaling is enabled.- Returns:
 - true if system scaling is enabled
 
 
- 
getSystemScaleFactor
public static double getSystemScaleFactor()
System scale factor. Scaling factor is calculated usingToolkit.getScreenResolution()value.- Returns:
 - system scaling factor.
 
 
- 
systemScaleValueUp
public static int systemScaleValueUp(int value)
Scales given value by system scale factor.- Parameters:
 value- value to scale- Returns:
 - scaled value
 
 
- 
isWindowsLookAndFeel
public static boolean isWindowsLookAndFeel()
Check if Windows Look and Feel is active.- Returns:
 - true if Windows Look and Feel is active
 
 
- 
getSystemScaled16x16Icon
@CheckForNull public static ResizableIcon getSystemScaled16x16Icon(@CheckForNull ResizableIcon icon)
 
- 
getSystemScaledIcon
public static ResizableIcon getSystemScaledIcon(ResizableIcon icon)
Return resizable icon scaled by system scale factor.- Parameters:
 icon- icon to scale- Returns:
 - scaled icon
 
 
- 
getSystemScaledIcon
@CheckForNull private static ResizableIcon getSystemScaledIcon(@CheckForNull ResizableIcon icon, int size)
 
- 
getScaled16x16Icon
@CheckForNull public static ResizableIcon getScaled16x16Icon(@CheckForNull ResizableIcon icon)
Return scaled to 16x16 icon for a given icon. Scaling factor is taken into account, so in scaled environment icon size will be scaled by a scale factor. Scaled icons are cached using WeakReferences.- Parameters:
 icon- icon- Returns:
 - scaled icon
 
 
- 
getNonScaledIcon
@CheckForNull public static ResizableIcon getNonScaledIcon(@CheckForNull ResizableIcon icon, int size, double maxScale)
Return icon scaled down to a given size. Scaled icons are cached using WeakReferences.- Parameters:
 icon- icon- Returns:
 - icon of given size
 - See Also:
 SquareIcon.create(ResizableIcon, int, double)
 
- 
scaleIcon
public static int scaleIcon(int size)
Scale Icon size.- Parameters:
 size- size- Returns:
 - Scaled size or the same value as provided.
 
 
- 
scaleIcon
private static int scaleIcon(int size, double scalingFactor) 
- 
scaleUI
public static double scaleUI(double size)
Scale User Interface item size.- Parameters:
 size- size- Returns:
 - Scaled size or the same value as provided.
 
 
- 
scaleUI
public static int scaleUI(int size)
Scale User Interface item size.- Parameters:
 size- size- Returns:
 - Scaled size or the same value as provided.
 
 
- 
scaleLFFont
private static float scaleLFFont(float size)
Scale L&F font size.- Parameters:
 size- size- Returns:
 - Scaled size or the same value as provided.
 
 
- 
scaleFont
public static float scaleFont(float size)
Scale font size.- Parameters:
 size- size- Returns:
 - Scaled size or the same value as provided.
 
 
- 
scaleDownFont
public static float scaleDownFont(float size)
Scale font size down.- Parameters:
 size- size- Returns:
 - Scaled size or the same value as provided.
 
 
- 
getUserScalingFactor
public static double getUserScalingFactor()
User scale factor. It is defined by jvm argument magicdraw.resolution.scale- Returns:
 - user scaling factor.
 
 
- 
getScalingFactor
@Deprecated public static double getScalingFactor()
Deprecated.use getUserScalingFactor()User scale factor. It is defined by jvm argument magicdraw.resolution.scale- Returns:
 - user scaling factor.
 
 
- 
getReducedUserScalingFactor
public static double getReducedUserScalingFactor()
In some cased real scaling scales UI too much. This methods returns reduced scaling factor for cases then real scaling scales UI too much.- Returns:
 - reduced scaling factor
 
 
- 
getReducedScalingFactor
@Deprecated public static double getReducedScalingFactor()
Deprecated.use getReducedUserScalingFactor()In some cased real scaling scales UI too much. This methods returns reduced scaling factor for cases then real scaling scales UI too much.- Returns:
 - reduced scaling factor
 
 
- 
isScalingFactorDefined
public static boolean isScalingFactorDefined()
Checks if system or user scaling factor is defined.- Returns:
 - true if system or user scaling factor is defined
 
 
- 
isUserScalingFactorDefined
public static boolean isUserScalingFactorDefined()
Checks if user scaling factor is defined by jvm argument magicdraw.resolution.scale.- Returns:
 - true if user scaling factor is defined
 
 
- 
scaleUI
private static void scaleUI(java.awt.Component component)
Scale components preferred size and similar.- Parameters:
 component- component
 
- 
addHiDPIScaledProperty
public static void addHiDPIScaledProperty(java.awt.Component component)
Mark this component as HiDPI scaled- Parameters:
 component- component
 
- 
scaleComponent
public static void scaleComponent(HiDPIScalableComponent component)
Scale components and its children preferred size and similar.- Parameters:
 component- component
 
- 
scaleUIRecursively
public static void scaleUIRecursively(java.awt.Component component)
Scale components and its children preferred size and similar.- Parameters:
 component- component
 
- 
acceptForUIScaling
private static boolean acceptForUIScaling(java.awt.Component component)
 
- 
scaleLookAndFeel
public static void scaleLookAndFeel()
Scale various java Look&Feel settings like fonts, icons sizes, insets and etc. 
- 
fixWindowsFonts
public static void fixWindowsFonts()
 
- 
shouldFixWindowsFonts
private static boolean shouldFixWindowsFonts()
 
- 
fixWindowsFonts
private static void fixWindowsFonts(javax.swing.UIDefaults ui)
 
- 
getSegoeUIFont
private static java.awt.Font getSegoeUIFont()
Segoe UI Font scales nicely with fractional scale. 
- 
getWindowsDefaultGUIFonts
private static java.util.Set<java.awt.Font> getWindowsDefaultGUIFonts()
Fonts that do not scale well with fractional scale. 
- 
fixWindowsFont
private static void fixWindowsFont(javax.swing.UIDefaults ui, java.util.Collection<java.awt.Font> defaultWindowsFonts, java.awt.Font segoeUIFont, java.lang.String key) 
- 
adjustFontByLookAndFeelDefaults
public static void adjustFontByLookAndFeelDefaults(java.awt.Component component)
Apply L&F default font group if this is Windows L&F 
- 
getWindowsDefaultGUIFont
private static java.awt.Font getWindowsDefaultGUIFont()
 
- 
scaleIcons
private static void scaleIcons()
 
- 
scaleLFIcon
@CheckForNull private static javax.swing.Icon scaleLFIcon(@CheckForNull javax.swing.Icon icon, boolean onlyIfImageIcon, double scalingFactor)Scale given icon if it was not scaled yet- Parameters:
 icon- icon- Returns:
 - scaled icon
 
 
- 
scaleLFIcon
private static void scaleLFIcon(java.lang.String iconName)
 
- 
scaleLFIcon
private static void scaleLFIcon(java.lang.String iconName, double scalingFactor) 
- 
getDefinedScalingFactor
private static double getDefinedScalingFactor()
Program defined scaling factor. If not defined chooses system defined.- Returns:
 - Program defined scaling factor.
 
 
- 
getUserDefinedScaleFactor
private static double getUserDefinedScaleFactor()
 
- 
isScalingFactorFromProperty
@Deprecated public static boolean isScalingFactorFromProperty()
Deprecated.isUserScalingFactorDefined()Checks if scaling factor is defined from system property.- Returns:
 - true if scaling factor is from resolution scale property.
 
 
- 
getSystemScalingFactor
private static double getSystemScalingFactor()
System defined scaling factor. Seems to work fine on Windows 8.1. (Make public if method is required outside)- Returns:
 - System defined scaling factor.
 
 
- 
normalizeScaleFactor
private static float normalizeScaleFactor(float scale)
 
- 
calculateSystemScaleFactor
public static float calculateSystemScaleFactor()
Calculates system scaling factor.- Returns:
 - scaling factor.
 
 
- 
getScaleFactorByScreenResolution
@Deprecated public static float getScaleFactorByScreenResolution()
Deprecated.use calculateSystemScaleFactor()Calculates system scaling factor from screen resolution.- Returns:
 - scaling factor.
 
 
- 
scaleByComponent
public static int scaleByComponent(java.awt.Component component, int value) 
- 
scaleByComponent
public static double scaleByComponent(java.awt.Component component, double value) 
- 
scaleByGraphics
private static double scaleByGraphics(@CheckForNull java.awt.GraphicsConfiguration graphicsConfiguration, double value, java.util.function.Function<java.lang.Double,java.lang.Double> roundingFunction) 
 - 
 
 -