Class BgImage

java.lang.Object
com.imyeyu.fx.utils.BgImage

public class BgImage extends Object
背景图片封装。build() 作为导出作用,最后执行

默认原图大小,不平铺,居原点

    // 适应缩放的 Cover 背景图片构建
    new BgImage("/cover.png").cover().build()
Since:
2021-02-13 12:53
Author:
夜雨
  • Constructor Summary

    Constructors
    Constructor
    Description
    BgImage(File file)
    背景图构造器
    背景图构造器
    BgImage(javafx.scene.image.Image img)
    背景图构造器
  • Method Summary

    Modifier and Type
    Method
    Description
    bottom(double size)
    居下
    javafx.scene.layout.Background
     
    居中背景图片
    自适应保持比例时尽量最大化的背景
    horizontal(javafx.geometry.Side side, double size, boolean asPercent)
    水平对齐方式
    left(double size)
    居左
    pos(javafx.geometry.Side sideH, double posH, boolean hAsPercent, javafx.geometry.Side sideV, double posV, boolean vAsPercent)
    背景位置
    repeat(javafx.scene.layout.BackgroundRepeat repeat)
    双轴平铺方式
    repeatX(javafx.scene.layout.BackgroundRepeat repeat)
    X 轴平铺方式
    repeatY(javafx.scene.layout.BackgroundRepeat repeat)
    Y 轴平铺方式
    right(double size)
    居右
    static void
    setBg(javafx.scene.Node node, String url, int width, int x, int y)
    JavaFX 设置组件背景,底色为默认
    static void
    setBgTp(javafx.scene.Node node, String url, int width, int x, int y)
    JavaFX 设置组件背景,底色为透明
    size(double width, double height, boolean widthAsPercent, boolean heightAsPercent, boolean isContain, boolean isCover)
    图像大小
    top(double size)
    居上
    vertical(javafx.geometry.Side side, double size, boolean asPercent)
    垂直对齐方式
    xy(double x, double y)
    坐标轴定位

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BgImage

      public BgImage(String url)
      背景图构造器
      Parameters:
      url - 图片位置(程序内资源)
    • BgImage

      public BgImage(File file)
      背景图构造器
      Parameters:
      file - 图片文件(程序外资源)
    • BgImage

      public BgImage(javafx.scene.image.Image img)
      背景图构造器
      Parameters:
      img - 图像
  • Method Details

    • repeat

      public BgImage repeat(javafx.scene.layout.BackgroundRepeat repeat)
      双轴平铺方式
      Parameters:
      repeat - 填充方式
      Returns:
      本实例
    • repeatX

      public BgImage repeatX(javafx.scene.layout.BackgroundRepeat repeat)
      X 轴平铺方式
      Parameters:
      repeat - 填充方式
      Returns:
      本实例
    • repeatY

      public BgImage repeatY(javafx.scene.layout.BackgroundRepeat repeat)
      Y 轴平铺方式
      Parameters:
      repeat - 填充方式
      Returns:
      本实例
    • pos

      public BgImage pos(javafx.geometry.Side sideH, double posH, boolean hAsPercent, javafx.geometry.Side sideV, double posV, boolean vAsPercent)
      背景位置
      Parameters:
      sideH - 相对水平位置,左或右
      posH - 相对水平距离
      hAsPercent - true 为水平距离是百分比
      sideV - 相对垂直位置,上或下
      posV - 相对垂直距离
      vAsPercent - true 为垂直距离是百分比
      Returns:
      本实例
    • horizontal

      public BgImage horizontal(javafx.geometry.Side side, double size, boolean asPercent)
      水平对齐方式
      Parameters:
      side - 相对位置
      size - 相对距离
      asPercent - true 百分比数据
      Returns:
      本实例
    • left

      public BgImage left(double size)
      居左
      Parameters:
      size - 距离
      Returns:
      本实例
    • right

      public BgImage right(double size)
      居右
      Parameters:
      size - 距离
      Returns:
      本实例
    • vertical

      public BgImage vertical(javafx.geometry.Side side, double size, boolean asPercent)
      垂直对齐方式
      Parameters:
      side - 相对位置
      size - 相对距离
      asPercent - true 百分比数据
      Returns:
      本实例
    • top

      public BgImage top(double size)
      居上
      Parameters:
      size - 距离
      Returns:
      本实例
    • bottom

      public BgImage bottom(double size)
      居下
      Parameters:
      size - 距离
      Returns:
      本实例
    • xy

      public BgImage xy(double x, double y)
      坐标轴定位
      Parameters:
      x - 轴
      y - 轴
      Returns:
      本实例
    • size

      public BgImage size(double width, double height, boolean widthAsPercent, boolean heightAsPercent, boolean isContain, boolean isCover)
      图像大小
      Parameters:
      width - 宽度
      height - 高度
      widthAsPercent - true 为参数是百分比
      heightAsPercent - true 为参数是百分比
      isContain - true 为尽量最大化图像
      isCover - true 为保持比例
      Returns:
      本实例
    • cover

      public BgImage cover()
      自适应保持比例时尽量最大化的背景
      Returns:
      本实例
    • center

      public BgImage center()
      居中背景图片
      Returns:
      本实例
    • build

      public javafx.scene.layout.Background build()
      Returns:
      最终构造背景
    • setBg

      public static void setBg(javafx.scene.Node node, String url, int width, int x, int y)
      JavaFX 设置组件背景,底色为默认
      Parameters:
      node - 节点
      url - 背景路径
      width - 宽度
      x - X 轴偏移
      y - Y 轴偏移
    • setBgTp

      public static void setBgTp(javafx.scene.Node node, String url, int width, int x, int y)
      JavaFX 设置组件背景,底色为透明
      Parameters:
      node - 节点
      url - 背景路径
      width - 宽度
      x - X 轴偏移
      y - Y 轴偏移