You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.1 KiB
98 lines
3.1 KiB
package com.fine.theme.utils; |
|
|
|
import com.formdev.flatlaf.util.UIScale; |
|
|
|
import javax.swing.plaf.DimensionUIResource; |
|
import javax.swing.plaf.InsetsUIResource; |
|
import javax.swing.plaf.UIResource; |
|
import java.awt.Dimension; |
|
import java.awt.Graphics2D; |
|
import java.awt.Insets; |
|
|
|
/** |
|
* UI缩放工具 |
|
* |
|
* @author vito |
|
* @since 11.0 |
|
* Created on 2023/11/15 |
|
*/ |
|
public class FineUIScale { |
|
/** |
|
* Multiplies the given value by the user scale factor. |
|
*/ |
|
public static float scale(float value) { |
|
return UIScale.scale(value); |
|
} |
|
|
|
/** |
|
* Multiplies the given value by the user scale factor and rounds the result. |
|
*/ |
|
public static int scale(int value) { |
|
return UIScale.scale(value); |
|
} |
|
|
|
/** |
|
* Similar as {@link #scale(int)} but always "rounds down". |
|
* <p> |
|
* For use in special cases. {@link #scale(int)} is the preferred method. |
|
*/ |
|
public static int scale2(int value) { |
|
return UIScale.scale2(value); |
|
} |
|
|
|
/** |
|
* Divides the given value by the user scale factor. |
|
*/ |
|
public static float unscale(float value) { |
|
return UIScale.unscale(value); |
|
} |
|
|
|
/** |
|
* Divides the given value by the user scale factor and rounds the result. |
|
*/ |
|
public static int unscale(int value) { |
|
return UIScale.unscale(value); |
|
} |
|
|
|
/** |
|
* If user scale factor is not 1, scale the given graphics context by invoking |
|
* {@link Graphics2D#scale(double, double)} with user scale factor. |
|
*/ |
|
public static void scaleGraphics(Graphics2D g) { |
|
UIScale.scaleGraphics(g); |
|
} |
|
|
|
/** |
|
* Scales the given dimension with the user scale factor. |
|
* <p> |
|
* If user scale factor is 1, then the given dimension is simply returned. |
|
* Otherwise, a new instance of {@link Dimension} or {@link DimensionUIResource} |
|
* is returned, depending on whether the passed dimension implements {@link UIResource}. |
|
*/ |
|
public static Dimension scale(Dimension dimension) { |
|
return UIScale.scale(dimension); |
|
} |
|
|
|
/** |
|
* Scales the given insets with the user scale factor. |
|
* <p> |
|
* If user scale factor is 1, then the given insets is simply returned. |
|
* Otherwise, a new instance of {@link Insets} or {@link InsetsUIResource} |
|
* is returned, depending on whether the passed dimension implements {@link UIResource}. |
|
*/ |
|
public static Insets scale(Insets insets) { |
|
return UIScale.scale(insets); |
|
} |
|
|
|
/** |
|
* Creates a scaled {@link Dimension} object based on the specified width and height. |
|
* <p> |
|
* This method uses the current user scale factor to adjust the provided width and height values: |
|
* - If the user scale factor is 1 (no scaling), the original width and height values are returned unchanged. |
|
* - If the user scale factor is different from 1, a new {@link Dimension} instance is created and returned, |
|
* with the width and height values scaled according to the user scale factor. |
|
*/ |
|
public static Dimension createScaleDimension(int width, int height) { |
|
return scale(new Dimension(width, height)); |
|
} |
|
}
|
|
|