SystemUtils.java 1.79 KB
package cn.csbr.app.gui.util;

import javafx.stage.Screen;

/**
 * 系统工具.
 *
 * @author fenglinz
 * @since 2018-10-26
 */
public final class SystemUtils {
    /** 标准宽度 */
    //private final static double STANDARD_WIDTH = 1280;
    private final static double STANDARD_WIDTH = 960;

    /** 标准高度 */
    //private final static double STANDARD_HEIGHT = 1024;
    private final static double STANDARD_HEIGHT = 768;

    /** 主屏幕信息 */
    private static Screen primaryScreen;

    static {
        primaryScreen = Screen.getPrimary();
    }

    /**
     * 获取屏幕宽度.
     *
     * @return 屏幕宽度.
     */
    public static double getScreenWidth() {
        double width = primaryScreen.getBounds().getWidth();

        return width > STANDARD_WIDTH ? STANDARD_WIDTH : width;
    }

    /**
     * 获取屏幕高度.
     *
     * @return 屏幕高度
     */
    public static double getScreenHeight() {
        double height = primaryScreen.getBounds().getHeight();

        return height > STANDARD_HEIGHT ? height - ((height - STANDARD_HEIGHT) / 2) : height;
    }

    /**
     * 获取导航按钮区的最小高度.
     *
     * @return 导航按钮区的最小高度
     */
    public static double getNavigationAreaMinHeight() {
        return getScreenHeight() - 70;
    }

    /**
     * 获取数据表格的最小高度.
     *
     * @return 数据表格的最小高度
     */
    public static double getDataTableMinHeight() {
        return getScreenHeight() - 260;
    }

    /**
     * 获取数据表格的最小高度.
     *
     * @param extraHeight 额外减少的高度
     *
     * @return 数据表格的最小高度
     */
    public static double getDataTableMinHeight(double extraHeight) {
        return getDataTableMinHeight() - extraHeight;
    }
}