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 boundary, double scale, Color fillColor, Color borderColor) { // 绘制方法 if (boundary == null || boundary.size() < 2) { // 判空 return; // 无数据返回 } // if结束 float strokeWidth = (float) (6 / Math.max(0.5, scale)); // 计算边线宽度(增加一倍,从3改为6) // 填充区域 Path2D fillPath = new Path2D.Double(); // 创建填充路径 boolean first = true; // 首点标记 for (Point2D.Double point : boundary) { // 遍历点 if (first) { // 首个点 fillPath.moveTo(point.x, point.y); // 移动到开始点 first = false; // 更新标记 } else { // 其他点 fillPath.lineTo(point.x, point.y); // 连线到下个点 } // if结束 } // for结束 fillPath.closePath(); // 闭合路径 g2d.setColor(fillColor); // 设置填充色 g2d.fill(fillPath); // 填充区域 // 绘制边界线(包括起点到终点的连接)- 实线 if (boundary.size() >= 2) { Path2D.Double borderPath = new Path2D.Double(); // 创建边界路径 Point2D.Double firstPoint = boundary.get(0); borderPath.moveTo(firstPoint.x, firstPoint.y); // 移动到起点 for (int i = 1; i < boundary.size(); i++) { // 从第二个点到最后一个点 Point2D.Double point = boundary.get(i); borderPath.lineTo(point.x, point.y); // 连线 } // 如果最后一个点不是第一个点,则连接到起点形成闭合 Point2D.Double lastPoint = boundary.get(boundary.size() - 1); if (!lastPoint.equals(firstPoint)) { borderPath.lineTo(firstPoint.x, firstPoint.y); // 连接到起点形成闭合 } // 绘制外层实线边界(宽度增加一倍) g2d.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // 设置实线描边 g2d.setColor(borderColor); // 设置边线颜色 g2d.draw(borderPath); // 绘制完整边界(包括起点到终点的连接) // 在边界线中间绘制深灰色小圆点虚线 float dashedLineWidth = strokeWidth / 3.0f; // 虚线宽度为实线的三分之一 float[] dashPattern = {2.0f, 2.0f}; // 等间隔小圆点虚线模式:2像素实线(形成圆点),2像素空白(均匀间隔) BasicStroke dashedStroke = new BasicStroke( dashedLineWidth, BasicStroke.CAP_ROUND, // 使用圆形端点,形成圆点效果 BasicStroke.JOIN_ROUND, 0.0f, dashPattern, 0.0f ); g2d.setStroke(dashedStroke); // 设置虚线描边 Color darkGrayColor = new Color(64, 64, 64); // 深灰色 g2d.setColor(darkGrayColor); // 设置虚线颜色 g2d.draw(borderPath); // 在中间绘制小圆点虚线 } } // 方法结束 } // 类结束