From f784463ab019c1113cf0b31a249e8802b07a57fa Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 16 十二月 2025 15:26:15 +0800
Subject: [PATCH] 保存地图最后位置
---
src/zhuye/LegendDialog.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/src/zhuye/LegendDialog.java b/src/zhuye/LegendDialog.java
index d595034..7469b67 100644
--- a/src/zhuye/LegendDialog.java
+++ b/src/zhuye/LegendDialog.java
@@ -32,6 +32,29 @@
mainPanel.setBackground(Color.WHITE);
mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));
+ // 璁$畻鍥句緥鍐呭闈㈡澘鐨勫搴︼紙鐢ㄤ簬璁剧疆鍥炬爣灏哄锛�
+ // 鍥句緥瀵硅瘽妗嗗搴� = DIALOG_WIDTH * 0.8
+ // 涓婚潰鏉垮乏鍙宠竟妗嗗悇15鍍忕礌锛屽浘渚嬪唴瀹归潰鏉垮乏鍙冲唴杈硅窛鍚�10鍍忕礌
+ int adjustedWidth = (int) Math.round(UIConfig.DIALOG_WIDTH * 0.8);
+ int iconSize = adjustedWidth - 30 - 20; // 鍑忓幓涓婚潰鏉垮乏鍙宠竟妗�(15*2)鍜屽浘渚嬪唴瀹归潰鏉垮乏鍙冲唴杈硅窛(10*2)
+
+ // 鍒涘缓鍓茶崏鏈哄浘鏍囬潰鏉�
+ JPanel iconPanel = new JPanel(new BorderLayout());
+ iconPanel.setBackground(Color.WHITE);
+ iconPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); // 搴曢儴闂磋窛10鍍忕礌
+
+ JLabel gecaojiLabel = new JLabel();
+ gecaojiLabel.setHorizontalAlignment(SwingConstants.CENTER);
+ ImageIcon gecaojiIcon = loadIcon("image/gecaoji.png", iconSize, iconSize);
+ if (gecaojiIcon != null) {
+ gecaojiLabel.setIcon(gecaojiIcon);
+ } else {
+ // 濡傛灉鍥炬爣鍔犺浇澶辫触锛屾樉绀哄崰浣嶆枃鏈�
+ gecaojiLabel.setText("鍓茶崏鏈哄浘鏍�");
+ gecaojiLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ }
+ iconPanel.add(gecaojiLabel, BorderLayout.CENTER);
+
// 鍥句緥鍐呭闈㈡澘 - 鐩存帴娣诲姞锛屼笉浣跨敤婊氬姩鏉�
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
@@ -61,7 +84,8 @@
contentPanel.remove(contentPanel.getComponentCount() - 1);
}
- // 鐩存帴娣诲姞鍐呭闈㈡澘锛屼笉浣跨敤婊氬姩鏉�
+ // 娣诲姞鍥炬爣闈㈡澘鍜屽浘渚嬪唴瀹归潰鏉�
+ mainPanel.add(iconPanel, BorderLayout.NORTH);
mainPanel.add(contentPanel, BorderLayout.CENTER);
getContentPane().add(mainPanel);
@@ -154,4 +178,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