From 487a5b943571d6ab57c4baddca1cbcc7b2062e73 Mon Sep 17 00:00:00 2001 From: 826220679@qq.com <826220679@qq.com> Date: 星期三, 27 八月 2025 23:06:57 +0800 Subject: [PATCH] 20250827 --- src/home/VisualizationPanel.java | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/home/VisualizationPanel.java b/src/home/VisualizationPanel.java index 8b24e30..47e2180 100644 --- a/src/home/VisualizationPanel.java +++ b/src/home/VisualizationPanel.java @@ -4,11 +4,16 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Image; import java.awt.RenderingHints; + +import javax.imageio.ImageIO; import javax.swing.BorderFactory; import javax.swing.JPanel; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; +import java.io.File; +import java.io.IOException; // 可视化面板类 class VisualizationPanel extends JPanel { @@ -30,12 +35,20 @@ private Font boldFont = new Font("Microsoft YaHei", Font.BOLD, 14); private Font normalFont = new Font("Microsoft YaHei", Font.PLAIN, 12); private Font titleFont = new Font("Microsoft YaHei", Font.BOLD, 12); + private Image logoImage; // 添加图片变量 public VisualizationPanel(AOAFollowSystem parentFrame) { this.parentFrame = parentFrame; setPreferredSize(new Dimension(400, 400)); setBorder(BorderFactory.createTitledBorder(parentFrame.getString("visualization"))); + // 加载图片 + try { + logoImage = ImageIO.read(new File("systemfile/1.png")); + } catch (IOException e) { + System.err.println("无法加载图片: systemfile/1.png"); + e.printStackTrace(); + } // 添加鼠标滚轮监听器 addMouseWheelListener(new MouseWheelListener() { @Override @@ -84,11 +97,22 @@ int centerX = getWidth() / 2; int centerY = getHeight()/ 2 - 30; - int maxRadius = (int) (Math.min(centerX, centerY) * scaleFactor - 20); + int baseRadius = Math.min(centerX, centerY) - 20; // 基础半径(不缩放) + int maxRadius = (int) (baseRadius * scaleFactor); // 缩放后的半径 // 设置背景颜色 g2d.setColor(new Color(240, 240, 240)); g2d.fillRect(0, 0, getWidth(), getHeight()); + + // 在左下角绘制图片 + if (logoImage != null) { + int imgWidth = logoImage.getWidth(this); + int imgHeight = logoImage.getHeight(this); + // 调整图片大小,使其适合面板 + int scaledWidth =150; // 设置图片宽度 + int scaledHeight = (int) (imgHeight * (scaledWidth * 1.0 / imgWidth)); // 按比例计算高度 + g2d.drawImage(logoImage, 5, getHeight() - scaledHeight - 5, scaledWidth, scaledHeight, this); + } // 绘制坐标轴 g2d.setColor(Color.LIGHT_GRAY); @@ -123,8 +147,8 @@ for (int i = 1; i <= 5; i++) { int radius = maxRadius * i / 5; g2d.drawOval(centerX - radius, centerY - radius, radius * 2, radius * 2); - // 修改:将距离标签显示在圆圈正南方中间 - String distanceLabel = (int)(i * 200 * scaleFactor) + "cm"; // 修改:乘以scaleFactor而不是除以 + // 修改:距离标签不随缩放变化,保持实际距离 + String distanceLabel = i * 200 + "cm"; int labelWidth = g2d.getFontMetrics().stringWidth(distanceLabel); g2d.drawString(distanceLabel, centerX - labelWidth / 2, centerY + radius + 15); } @@ -140,7 +164,7 @@ // 绘制B点(标签点) if (distance > 0) { // 根据距离计算缩放比例(最大1000厘米) - double scaledDistance = Math.min(distance, 1000) * maxRadius / 1000.0 ; // 修改:添加乘以scaleFactor + double scaledDistance = Math.min(distance, 1000) * maxRadius / 1000.0; // 将导航角度转换为数学角度(从正东方向开始,逆时针为正) double mathAngle = 90 - angle; // 导航角度转换为数学角度 @@ -162,13 +186,7 @@ g2d.setFont(boldFont); g2d.setColor(Color.RED); - // 计算文本位置(B点正下方) - int textY = bY + 25; - g2d.drawString(distanceText, bX - g2d.getFontMetrics().stringWidth(distanceText)/2, textY); - g2d.drawString(angleText, bX - g2d.getFontMetrics().stringWidth(angleText)/2, textY + 20); - // 恢复原始字体 - g2d.setFont(normalFont); // 在面板底部显示距离和角度信息 - 实时获取字符串,不使用缓存 g2d.setFont(boldFont); @@ -179,18 +197,30 @@ g2d.drawString(parentFrame.getString("signal") + signalQuality, 10, 100); g2d.setFont(normalFont); g2d.setColor(Color.BLUE); - g2d.fillOval(bX - 5, bY - 5, 10, 10); + g2d.fillOval(bX -10, bY -10, 20, 20); // B点正上方显示设备编号 g2d.setFont(titleFont); - g2d.drawString(tagid, bX - g2d.getFontMetrics().stringWidth(tagid)/2, bY - 15); + g2d.setColor(Color.BLUE); + g2d.drawString(tagid, bX - g2d.getFontMetrics().stringWidth(tagid)/2, bY - 25); g2d.setFont(normalFont); + + // 计算文本位置(B点正下方) + int textY = bY + 25; + g2d.setColor(Color.BLUE); + g2d.drawString(distanceText, bX - g2d.getFontMetrics().stringWidth(distanceText)/2, textY); + g2d.drawString(angleText, bX - g2d.getFontMetrics().stringWidth(angleText)/2, textY + 20); + g2d.setFont(normalFont); + + } // 显示当前缩放比例 g2d.setColor(Color.DARK_GRAY); - g2d.drawString(String.format("缩放: %.1fx", scaleFactor), getWidth() - 80, 20); + g2d.drawString(String.format("%s: %.1fx", parentFrame.getString("scale"), scaleFactor), getWidth() - 80, 20); + + } public void updateLanguage() { -- Gitblit v1.9.3