package zhuye; // 包声明
|
|
import java.awt.BasicStroke; // 描边类
|
import java.awt.Color; // 颜色类
|
import java.awt.Graphics2D; // 绘图上下文
|
import java.awt.geom.Path2D; // 路径类
|
import java.awt.geom.Point2D; // 坐标点类
|
import java.util.List; // 列表接口
|
|
/** // 文档说明开始
|
* Utility for rendering boundary polygons with theme-aligned colors. // 工具类说明
|
*/ // 文档说明结束
|
public final class bianjiedrwa { // 工具类定义
|
private bianjiedrwa() { // 私有构造防止实例化
|
} // 构造结束
|
|
/** // 文档说明开始
|
* Draw boundary polygon using provided stroke/fill colors. // 方法说明
|
*/ // 文档说明结束
|
public static void drawBoundary(Graphics2D g2d, List<Point2D.Double> boundary,
|
double scale, Color fillColor, Color borderColor) { // 绘制方法
|
if (boundary == null || boundary.size() < 2) { // 判空
|
return; // 无数据返回
|
} // if结束
|
|
Path2D path = new Path2D.Double(); // 创建路径
|
boolean first = true; // 首点标记
|
for (Point2D.Double point : boundary) { // 遍历点
|
if (first) { // 首个点
|
path.moveTo(point.x, point.y); // 移动到开始点
|
first = false; // 更新标记
|
} else { // 其他点
|
path.lineTo(point.x, point.y); // 连线到下个点
|
} // if结束
|
} // for结束
|
path.closePath(); // 闭合路径
|
|
float strokeWidth = (float) (3 / Math.max(0.5, scale)); // 计算边线宽度
|
g2d.setStroke(new BasicStroke(strokeWidth)); // 设置描边
|
g2d.setColor(fillColor); // 设置填充色
|
g2d.fill(path); // 填充区域
|
|
g2d.setColor(borderColor); // 设置边线颜色
|
g2d.draw(path); // 绘制边界
|
} // 方法结束
|
} // 类结束
|