|
|
|
package com.fanruan.api.util;
|
|
|
|
|
|
|
|
import com.fr.stable.GraphDrawHelper;
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author richie
|
|
|
|
* @version 10.0
|
|
|
|
* Created by richie on 2019/10/25
|
|
|
|
* 图形绘制相关的工具类
|
|
|
|
*/
|
|
|
|
public class GraphKit {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取字体规格属性
|
|
|
|
*
|
|
|
|
* @param font 字体
|
|
|
|
* @return 字体的规格属性
|
|
|
|
*/
|
|
|
|
public static FontMetrics getFontMetrics(Font font) {
|
|
|
|
return GraphDrawHelper.getFontMetrics(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取字体规格属性
|
|
|
|
*
|
|
|
|
* @param font 字体
|
|
|
|
* @param g2d 图形绘制上下文
|
|
|
|
* @return 字体的规格属性
|
|
|
|
*/
|
|
|
|
public static FontMetrics getFontMetrics(Font font, Graphics2D g2d) {
|
|
|
|
return GraphDrawHelper.getFontMetrics(font, g2d);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制指定的形状
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param shape 形状
|
|
|
|
*/
|
|
|
|
public static void draw(Graphics g, Shape shape) {
|
|
|
|
GraphDrawHelper.draw(g, shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 使用特定的线型绘制指定的形状
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param shape 形状
|
|
|
|
* @param lineStyle 线型
|
|
|
|
*/
|
|
|
|
public static void draw(Graphics g, Shape shape, int lineStyle) {
|
|
|
|
GraphDrawHelper.draw(g, shape, lineStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制文本
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param str 待绘制的文本
|
|
|
|
* @param x 横坐标
|
|
|
|
* @param y 纵坐标
|
|
|
|
*/
|
|
|
|
public static void drawString(Graphics g, String str, double x, double y) {
|
|
|
|
GraphDrawHelper.drawString(g, str, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制线段
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param x1 起点横坐标
|
|
|
|
* @param y1 起点纵坐标
|
|
|
|
* @param x2 终点横坐标
|
|
|
|
* @param y2 终点纵坐标
|
|
|
|
*/
|
|
|
|
public static void drawLine(Graphics g, double x1, double y1, double x2, double y2) {
|
|
|
|
GraphDrawHelper.drawLine(g, x1, y1, x2, y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制线段
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param x1 起点横坐标
|
|
|
|
* @param y1 起点纵坐标
|
|
|
|
* @param x2 终点横坐标
|
|
|
|
* @param y2 终点纵坐标
|
|
|
|
* @param lineStyle 线条样式
|
|
|
|
* @see com.fanruan.api.macro.LineConstants
|
|
|
|
*/
|
|
|
|
public static void drawLine(Graphics g,
|
|
|
|
double x1, double y1, double x2, double y2, int lineStyle) {
|
|
|
|
GraphDrawHelper.drawLine(g, x1, y1, x2, y2, lineStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制矩形
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param x 起点横坐标
|
|
|
|
* @param y 起点纵坐标
|
|
|
|
* @param width 矩形宽度
|
|
|
|
* @param height 矩形高度
|
|
|
|
*/
|
|
|
|
public static void drawRect(Graphics g, double x, double y, double width, double height) {
|
|
|
|
GraphDrawHelper.drawRect(g, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制矩形
|
|
|
|
*
|
|
|
|
* @param g 图形绘制上下文
|
|
|
|
* @param x 起点横坐标
|
|
|
|
* @param y 起点纵坐标
|
|
|
|
* @param width 矩形宽度
|
|
|
|
* @param height 矩形高度
|
|
|
|
* @param lineStyle 线条样式
|
|
|
|
* @see com.fanruan.api.macro.LineConstants
|
|
|
|
*/
|
|
|
|
public static void drawRect(Graphics g, double x, double y, double width, double height, int lineStyle) {
|
|
|
|
GraphDrawHelper.drawRect(g, x, y, width, height, lineStyle);
|
|
|
|
}
|
|
|
|
}
|