From 48ee74129bb09a817a0bbbabe860c4007b74c66b Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期日, 21 十二月 2025 12:37:44 +0800
Subject: [PATCH] 新增了往返路径
---
src/zhuye/LegendDialog.java | 142 ++++++++++++++++++++++-------------------------
1 files changed, 66 insertions(+), 76 deletions(-)
diff --git a/src/zhuye/LegendDialog.java b/src/zhuye/LegendDialog.java
index 9317694..f3c852f 100644
--- a/src/zhuye/LegendDialog.java
+++ b/src/zhuye/LegendDialog.java
@@ -6,14 +6,13 @@
import java.awt.*;
public class LegendDialog extends JDialog {
- private final Color THEME_COLOR;
-
- public LegendDialog(Component parent, Color themeColor) {
- super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null,
- "鍥句緥", true);
- this.THEME_COLOR = themeColor;
- // 浣跨敤缁熶竴瀵硅瘽妗嗗昂瀵革紙6.5 瀵哥珫灞忥級
- initializeDialog(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT);
+
+ public LegendDialog(Component parent, Color ignoredThemeColor) {
+ super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null,
+ "鍥句緥", true);
+ int adjustedWidth = (int) Math.round(UIConfig.DIALOG_WIDTH * 0.8);
+ int adjustedHeight = (int) Math.round(UIConfig.DIALOG_HEIGHT * 0.4);
+ initializeDialog(adjustedWidth, adjustedHeight);
initializeLegendContent();
if (parent == null) {
setLocationRelativeTo(null); // 灞呬腑鏄剧ず
@@ -33,13 +32,6 @@
mainPanel.setBackground(Color.WHITE);
mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));
- // 鏍囬 - 淇敼涓�"鍥句緥"
- JLabel titleLabel = new JLabel("鍥句緥", JLabel.CENTER);
- titleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
- titleLabel.setForeground(new Color(60, 60, 60));
- titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
- mainPanel.add(titleLabel, BorderLayout.NORTH);
-
// 鍥句緥鍐呭闈㈡澘 - 鐩存帴娣诲姞锛屼笉浣跨敤婊氬姩鏉�
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
@@ -56,6 +48,7 @@
{"璺緞鏂瑰悜", "255,0,0", "arrow"},
{"闅滅鐗╁尯鍩�", "255,0,0", "obstacle_fill"},
{"鍓茶崏鏈轰綅缃�", "0,150,0", "mow"},
+ {"寰�杩旇矾寰�", "0,0,0", "railway"},
{"鍓茶崏杞ㄨ抗", "100,150,200", "trail"}
};
@@ -69,64 +62,9 @@
contentPanel.remove(contentPanel.getComponentCount() - 1);
}
- // 鐩存帴娣诲姞鍐呭闈㈡澘锛屼笉浣跨敤婊氬姩鏉�
+ // 娣诲姞鍥句緥鍐呭闈㈡澘
mainPanel.add(contentPanel, BorderLayout.CENTER);
- // 搴曢儴鎸夐挳闈㈡澘
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- buttonPanel.setBackground(Color.WHITE);
- buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
-
- // 缇庡寲鍏抽棴鎸夐挳
- JButton closeButton = new JButton("鍏抽棴") {
- @Override
- protected void paintComponent(Graphics g) {
- Graphics2D g2 = (Graphics2D) g.create();
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
- // 缁樺埗鍦嗚鐭╁舰鑳屾櫙
- g2.setColor(THEME_COLOR);
- g2.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
-
- // 缁樺埗杈规
- g2.setColor(THEME_COLOR.darker());
- g2.setStroke(new BasicStroke(1.5f));
- g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 15, 15);
-
- // 缁樺埗鏂囧瓧
- g2.setColor(Color.WHITE);
- g2.setFont(getFont());
- FontMetrics fm = g2.getFontMetrics();
- int x = (getWidth() - fm.stringWidth(getText())) / 2;
- int y = (getHeight() - fm.getHeight()) / 2 + fm.getAscent();
- g2.drawString(getText(), x, y);
-
- g2.dispose();
- }
- };
-
- closeButton.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 12));
- closeButton.setForeground(Color.WHITE);
- closeButton.setBackground(THEME_COLOR);
- closeButton.setFocusPainted(false);
- closeButton.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
- closeButton.setContentAreaFilled(false);
- closeButton.setPreferredSize(new Dimension(70, 28));
- closeButton.addActionListener(e -> dispose());
-
- // 娣诲姞榧犳爣鎮仠鏁堟灉
- closeButton.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseEntered(java.awt.event.MouseEvent evt) {
- closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
- }
- public void mouseExited(java.awt.event.MouseEvent evt) {
- closeButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
- }
- });
-
- buttonPanel.add(closeButton);
- mainPanel.add(buttonPanel, BorderLayout.SOUTH);
-
getContentPane().add(mainPanel);
}
@@ -183,11 +121,30 @@
g2d.fillPolygon(xPoints, yPoints, 3);
break;
case "mow":
- g2d.setColor(itemColor);
- g2d.fillOval(x, y, size, size);
- g2d.setColor(new Color(100, 100, 100));
- g2d.setStroke(new BasicStroke(1));
- g2d.drawOval(x, y, size, size);
+ ImageIcon icon = loadIcon("image/gecaoji.png", size + 8, size + 8);
+ if (icon != null) {
+ icon.paintIcon(this, g2d, x - 4, y - 4);
+ } else {
+ g2d.setColor(itemColor);
+ g2d.fillOval(x, y, size, size);
+ g2d.setColor(new Color(100, 100, 100));
+ g2d.setStroke(new BasicStroke(1));
+ g2d.drawOval(x, y, size, size);
+ }
+ break;
+ case "railway":
+ // 1. 缁樺埗搴曞眰榛戣壊瀹炵嚎
+ g2d.setColor(Color.BLACK);
+ g2d.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+ g2d.drawLine(x, y + size/2, x + size, y + size/2);
+
+ // 2. 缁樺埗椤跺眰鐧借壊铏氱嚎
+ float dashLen = 3.0f * 2.0f;
+ float dashSpace = 3.0f * 2.0f;
+ float[] dashPattern = {dashLen, dashSpace};
+ g2d.setColor(Color.WHITE);
+ g2d.setStroke(new BasicStroke(1.2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 10.0f, dashPattern, 0.0f));
+ g2d.drawLine(x, y + size/2, x + size, y + size/2);
break;
case "trail":
g2d.setColor(itemColor);
@@ -217,4 +174,37 @@
return itemPanel;
}
+
+ /**
+ * 鍔犺浇骞剁缉鏀惧浘鏍�
+ * @param iconPath 鍥炬爣璺緞
+ * @param width 鐩爣瀹藉害
+ * @param height 鐩爣楂樺害
+ * @return 缂╂斁鍚庣殑鍥炬爣
+ */
+ private ImageIcon loadIcon(String iconPath, int width, int height) {
+ try {
+ java.net.URL imgURL = getClass().getClassLoader().getResource(iconPath);
+ if (imgURL == null) {
+ // 灏濊瘯浠庢枃浠剁郴缁熷姞杞�
+ java.io.File imgFile = new java.io.File(iconPath);
+ if (imgFile.exists()) {
+ ImageIcon originalIcon = new ImageIcon(imgFile.getAbsolutePath());
+ Image scaledImage = originalIcon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
+ ImageIcon scaledIcon = new ImageIcon(scaledImage);
+ scaledIcon.setDescription(iconPath);
+ return scaledIcon;
+ }
+ } else {
+ ImageIcon originalIcon = new ImageIcon(imgURL);
+ Image scaledImage = originalIcon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
+ ImageIcon scaledIcon = new ImageIcon(scaledImage);
+ scaledIcon.setDescription(iconPath);
+ return scaledIcon;
+ }
+ } catch (Exception e) {
+ System.err.println("鏃犳硶鍔犺浇鍥炬爣: " + iconPath + " - " + e.getMessage());
+ }
+ return null;
+ }
}
\ No newline at end of file
--
Gitblit v1.10.0