From 8d662de2fd262b3a485f16e197cb4d0ca2a61cdf Mon Sep 17 00:00:00 2001
From: zsh_root <979909237@qq.com>
Date: 星期三, 10 十二月 2025 17:03:47 +0800
Subject: [PATCH] 发布版V1.0
---
src/home/MainFrame.java | 735 ++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 470 insertions(+), 265 deletions(-)
diff --git a/src/home/MainFrame.java b/src/home/MainFrame.java
index 43a42a5..4822b14 100644
--- a/src/home/MainFrame.java
+++ b/src/home/MainFrame.java
@@ -9,6 +9,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.util.PropertyResourceBundle;
+import javax.imageio.ImageIO;
public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
@@ -18,38 +19,43 @@
private JPanel mainPanel;
private JButton serialCommBtn, networkCommBtn, networkConfigBtn;
private JComboBox<String> languageCombo;
-
- // 各功能面板
+ // 鏂板锛氬崼鏄熸暟鎹寜閽笌闈㈡澘
+ private JButton satelliteBtn;
+ private SatelliteDataPanel satellitePanel;
+
+ // 鍚勫姛鑳介潰鏉�
private SerialCommunicationPanel serialPanel;
private NetworkCommunicationPanel networkPanel;
private NetworkConfigPanel configPanel;
private DataLogPanel dataLogPanel;
private SendPanel sendPanel;
-
- // 新增:快捷计算面板相关
+ private JSplitPane contentSplitPane;
+ private JSplitPane rightSplitPane;
+
+ // 鏂板锛氬揩鎹疯绠楅潰鏉跨浉鍏�
private JButton quickCalcBtn;
private JDialog quickCalcDialog;
private QuickCalculationPanel quickCalcPanel;
-
+
public MainFrame() {
this.currentLocale = Locale.SIMPLIFIED_CHINESE;
this.messages = loadResourceBundle(currentLocale);
initializeUI();
}
-
+
private ResourceBundle loadResourceBundle(Locale locale) {
- String fileName = locale.equals(Locale.ENGLISH) ?
+ String fileName = locale.equals(Locale.ENGLISH) ?
"Messages_en.properties" : "Messages_zh.properties";
File langFile = new File("systemfile/" + fileName);
if (!langFile.exists()) {
- System.err.println("默认资源文件未找到: " + langFile.getAbsolutePath());
- // 备用方案:尝试从类路径加载
+ System.err.println("榛樿璧勬簮鏂囦欢鏈壘鍒�: " + langFile.getAbsolutePath());
+ // 澶囩敤鏂规锛氬皾璇曚粠绫昏矾寰勫姞杞�
try {
return ResourceBundle.getBundle("Messages", locale);
} catch (Exception e) {
- System.err.println("无法加载备用资源文件");
+ System.err.println("鏃犳硶鍔犺浇澶囩敤璧勬簮鏂囦欢");
return createDefaultResourceBundle();
}
}
@@ -57,349 +63,517 @@
try (InputStream inputStream = new FileInputStream(langFile)) {
return new PropertyResourceBundle(inputStream);
} catch (IOException e) {
- System.err.println("无法加载资源文件: " + e.getMessage());
- // 备用方案
+ System.err.println("鏃犳硶鍔犺浇璧勬簮鏂囦欢: " + e.getMessage());
+ // 澶囩敤鏂规
try {
return ResourceBundle.getBundle("Messages", locale);
} catch (Exception ex) {
- System.err.println("无法加载备用资源文件");
+ System.err.println("鏃犳硶鍔犺浇澶囩敤璧勬簮鏂囦欢");
return createDefaultResourceBundle();
}
}
}
-
+
private ResourceBundle createDefaultResourceBundle() {
- // 创建默认资源包(中文)
+ // 鍒涘缓榛樿璧勬簮鍖咃紙涓枃锛�
java.util.Properties properties = new java.util.Properties();
- properties.setProperty("app.title", "配置软件");
- properties.setProperty("serial.communication", "串口通信");
- properties.setProperty("network.communication", "网络通信");
- properties.setProperty("network.config", "网络配置");
- properties.setProperty("language.switch", "语言切换");
- properties.setProperty("select.serial", "选择串口");
- properties.setProperty("baud.rate", "波特率");
- properties.setProperty("open", "打开");
- properties.setProperty("close", "关闭");
- // 新增:快捷计算相关资源
- properties.setProperty("quick.calculation", "快捷计算");
- properties.setProperty("quick.calc.title", "坐标计算工具");
-
+ properties.setProperty("app.title", "閰嶇疆杞欢");
+ properties.setProperty("serial.communication", "涓插彛閫氫俊");
+ properties.setProperty("network.communication", "缃戠粶閫氫俊");
+ properties.setProperty("network.config", "缃戠粶閰嶇疆");
+ properties.setProperty("language.switch", "璇█鍒囨崲");
+ properties.setProperty("select.serial", "閫夋嫨涓插彛");
+ properties.setProperty("baud.rate", "娉㈢壒鐜�");
+ properties.setProperty("open", "鎵撳紑");
+ properties.setProperty("close", "鍏抽棴");
+ // 鏂板锛氬揩鎹疯绠楃浉鍏宠祫婧�
+ properties.setProperty("quick.calculation", "蹇嵎璁$畻");
+ properties.setProperty("quick.calc.title", "鍧愭爣璁$畻宸ュ叿");
+
try {
- return new PropertyResourceBundle(new java.io.ByteArrayInputStream(
- properties.toString().replace("=", ": ").getBytes()));
- } catch (IOException e) {
- e.printStackTrace();
- }
- return messages;
+ return new PropertyResourceBundle(new java.io.ByteArrayInputStream(
+ properties.toString().replace("=", ": ").getBytes()));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return messages;
}
-
+
public String getString(String key) {
if (messages != null) {
try {
return messages.getString(key);
} catch (Exception e) {
- // 如果资源文件中没有找到对应的key,返回默认值
+ // 濡傛灉璧勬簮鏂囦欢涓病鏈夋壘鍒板搴旂殑key锛岃繑鍥為粯璁ゅ��
return getDefaultString(key);
}
}
return getDefaultString(key);
}
-
+
private String getDefaultString(String key) {
- // 默认文本(中文)
+ // 榛樿鏂囨湰锛堜腑鏂囷級
switch (key) {
- case "app.title": return "配置软件";
- case "serial.communication": return "串口通信";
- case "network.communication": return "网络通信";
- case "network.config": return "网络配置";
- case "language.switch": return "语言切换";
- case "select.serial": return "选择串口";
- case "baud.rate": return "波特率";
- case "open": return "打开";
- case "close": return "关闭";
- case "base.parameters": return "基础参数";
- case "base.station": return "基站";
- case "tag": return "标签";
- case "anti.collision": return "防撞";
- case "upgrade": return "升级";
- case "device.version": return "设备版本";
- case "device.id": return "设备编号";
- case "comm.frequency": return "通信频率";
- case "base.stations.per.comm": return "单次通信基站数";
- case "group.id": return "分组编号";
- case "distance.calibration": return "距离校准值";
- case "device.type": return "设备类型";
- case "base.station.ranging": return "基站主动测距";
- case "alarm.device": return "报警设备";
- case "pairing.id": return "配对编号";
- case "heartbeat.switch": return "心跳包开关";
- case "modbus.mode": return "MODBUS模式";
- case "rf.power": return "射频发射功率";
- case "read.parameters": return "读取参数";
- case "save.parameters": return "保存参数";
- case "restart.device": return "重启设备";
- case "reset.factory": return "恢复出厂设置";
- case "protocol.type": return "协议类型";
- case "local.host.address": return "本地主机地址";
- case "local.host.port": return "本地主机端口";
- case "remote.host.address": return "远程主机地址";
- case "remote.host.port": return "远程主机端口";
- case "data.log": return "数据日志";
- case "ascii.display": return "ASCII显示";
- case "auto.save": return "自动保存";
- case "show.time": return "显示时间";
- case "start": return "开始";
- case "pause": return "暂停";
- case "clear": return "清空";
- case "send.data": return "发送数据";
- case "hex.send": return "HEX发送";
- case "loop.send": return "循环发送";
- case "loop.time": return "循环时间(ms)";
- case "send": return "发送";
- case "extension": return "扩展";
- case "LANGUAGE": return "Language";
- case "external.control": return "外部控制";
- case "adjacent.stations.count": return "相邻基站数量";
- case "adjacent.station1": return "相邻基站1";
- case "adjacent.station2": return "相邻基站2";
- case "adjacent.station3": return "相邻基站3";
- case "adjacent.station4": return "相邻基站4";
- case "adjacent.station5": return "相邻基站5";
- case "adjacent.station6": return "相邻基站6";
- case "adjacent.station7": return "相邻基站7";
- case "adjacent.station8": return "相邻基站8";
- case "adjacent.station9": return "相邻基站9";
- case "adjacent.station10": return "相邻基站10";
- case "sync.station.id": return "同步基站ID";
- case "sync.station.type": return "同步基站类型";
- case "tag.id": return "标签ID";
- case "tag.type": return "标签类型";
- case "tag.mode": return "标签模式";
- case "tag.interval": return "标签间隔";
- case "tag.power": return "标签功率";
- case "tag.sensitivity": return "标签灵敏度";
- case "anti.collision.enable": return "防撞使能";
- case "safety.distance": return "安全距离";
- case "warning.distance": return "警告距离";
- case "alarm.distance": return "报警距离";
- case "alarm.type": return "报警类型";
- case "upgrade.description": return "固件升级功能\n\n请选择要升级的固件文件,然后点击开始升级按钮。升级过程中请勿断开电源。";
- case "start.upgrade": return "开始升级";
-
- // 新增:快捷计算相关键值对
- case "quick.calculation": return "快捷计算";
- case "quick.calc.title": return "坐标计算工具";
-
- // 升级相关键值对
- case "upgrade.instructions": return "升级说明";
- case "select.folder": return "选择文件夹";
- case "browse": return "浏览";
- case "select.bin.file": return "选择BIN文件";
- case "selected.file": return "已选择文件";
- case "file.selected": return "文件已选择";
- case "please.select.folder.first": return "请先选择文件夹";
- case "warning": return "警告";
- case "upgrade.completed": return "升级完成";
- case "success": return "成功";
- case "upgrade.in.progress": return "升级进行中...";
- case "select.upgrade.file": return "选择升级文件";
- case "upgrade.file": return "升级文件";
- case "upgrade.progress": return "升级进度";
- case "cancel.upgrade": return "取消升级";
- case "upgrade.success": return "升级成功";
- case "upgrade.failed": return "升级失败";
- case "confirm.upgrade": return "确认升级";
- case "upgrade.confirmation": return "升级确认";
- case "upgrade.confirm.message": return "确定要开始升级吗?升级过程中请勿断开电源。";
- case "select.file": return "选择文件";
- case "no.file.selected": return "未选择文件";
- case "file.not.found": return "文件未找到";
- case "invalid.file": return "无效文件";
- case "upgrade.ready": return "准备升级";
- case "preparing.upgrade": return "准备升级环境...";
- case "writing.firmware": return "写入固件...";
- case "verifying.firmware": return "验证固件...";
- case "upgrade.cancelled": return "升级已取消";
-
- // 扩展面板相关键值对
- case "common.commands": return "常用指令";
- case "command.string": return "指令字符串";
- case "save.common.commands": return "保存常用指令";
- case "modify.common.commands": return "修改常用指令";
- case "load.commands.failed": return "加载指令失败:";
- case "save.commands.success": return "保存指令成功!";
- case "save.commands.failed": return "保存指令失败:";
- case "command.cannot.empty": return "指令不能为空!";
- case "now.can.modify.commands": return "现在可以修改表格中的指令内容,修改完成后点击保存常用指令按钮";
- case "prompt": return "提示";
- case "error": return "错误";
-
- // 扩展命令相关键值对
- case "extension.command": return "扩展命令";
-
- default: return key;
+ case "app.title":
+ return "閰嶇疆杞欢";
+ case "serial.communication":
+ return "涓插彛閫氫俊";
+ case "network.communication":
+ return "缃戠粶閫氫俊";
+ case "network.config":
+ return "缃戠粶閰嶇疆";
+ case "language.switch":
+ return "璇█鍒囨崲";
+ case "select.serial":
+ return "閫夋嫨涓插彛";
+ case "baud.rate":
+ return "娉㈢壒鐜�";
+ case "open":
+ return "鎵撳紑";
+ case "close":
+ return "鍏抽棴";
+ case "base.parameters":
+ return "鍩虹鍙傛暟";
+ case "base.station":
+ return "鍩虹珯";
+ case "tag":
+ return "鏍囩";
+ case "anti.collision":
+ return "闃叉挒";
+ case "upgrade":
+ return "鍗囩骇";
+ case "device.version":
+ return "璁惧鐗堟湰";
+ case "device.id":
+ return "璁惧缂栧彿";
+ case "comm.frequency":
+ return "閫氫俊棰戠巼";
+ case "base.stations.per.comm":
+ return "鍗曟閫氫俊鍩虹珯鏁�";
+ case "group.id":
+ return "鍒嗙粍缂栧彿";
+ case "distance.calibration":
+ return "璺濈鏍″噯鍊�";
+ case "device.type":
+ return "璁惧绫诲瀷";
+ case "base.station.ranging":
+ return "鍩虹珯涓诲姩娴嬭窛";
+ case "alarm.device":
+ return "鎶ヨ璁惧";
+ case "pairing.id":
+ return "閰嶅缂栧彿";
+ case "heartbeat.switch":
+ return "蹇冭烦鍖呭紑鍏�";
+ case "modbus.mode":
+ return "MODBUS妯″紡";
+ case "rf.power":
+ return "灏勯鍙戝皠鍔熺巼";
+ case "read.parameters":
+ return "璇诲彇鍙傛暟";
+ case "save.parameters":
+ return "淇濆瓨鍙傛暟";
+ case "restart.device":
+ return "閲嶅惎璁惧";
+ case "reset.factory":
+ return "鎭㈠鍑哄巶璁剧疆";
+ case "protocol.type":
+ return "鍗忚绫诲瀷";
+ case "local.host.address":
+ return "鏈湴涓绘満鍦板潃";
+ case "local.host.port":
+ return "鏈湴涓绘満绔彛";
+ case "remote.host.address":
+ return "杩滅▼涓绘満鍦板潃";
+ case "remote.host.port":
+ return "杩滅▼涓绘満绔彛";
+ case "data.log":
+ return "鏁版嵁鏃ュ織";
+ case "ascii.display":
+ return "ASCII鏄剧ず";
+ case "auto.save":
+ return "鑷姩淇濆瓨";
+ case "show.time":
+ return "鏄剧ず鏃堕棿";
+ case "start":
+ return "寮�濮�";
+ case "pause":
+ return "鏆傚仠";
+ case "clear":
+ return "娓呯┖";
+ case "send.data":
+ return "鍙戦�佹暟鎹�";
+ case "hex.send":
+ return "HEX鍙戦��";
+ case "loop.send":
+ return "寰幆鍙戦��";
+ case "loop.time":
+ return "寰幆鏃堕棿(ms)";
+ case "send":
+ return "鍙戦��";
+ case "extension":
+ return "鎵╁睍";
+ case "LANGUAGE":
+ return "Language";
+ case "external.control":
+ return "澶栭儴鎺у埗";
+ case "adjacent.stations.count":
+ return "鐩搁偦鍩虹珯鏁伴噺";
+ case "adjacent.station1":
+ return "鐩搁偦鍩虹珯1";
+ case "adjacent.station2":
+ return "鐩搁偦鍩虹珯2";
+ case "adjacent.station3":
+ return "鐩搁偦鍩虹珯3";
+ case "adjacent.station4":
+ return "鐩搁偦鍩虹珯4";
+ case "adjacent.station5":
+ return "鐩搁偦鍩虹珯5";
+ case "adjacent.station6":
+ return "鐩搁偦鍩虹珯6";
+ case "adjacent.station7":
+ return "鐩搁偦鍩虹珯7";
+ case "adjacent.station8":
+ return "鐩搁偦鍩虹珯8";
+ case "adjacent.station9":
+ return "鐩搁偦鍩虹珯9";
+ case "adjacent.station10":
+ return "鐩搁偦鍩虹珯10";
+ case "sync.station.id":
+ return "鍚屾鍩虹珯ID";
+ case "sync.station.type":
+ return "鍚屾鍩虹珯绫诲瀷";
+ case "tag.id":
+ return "鏍囩ID";
+ case "tag.type":
+ return "鏍囩绫诲瀷";
+ case "tag.mode":
+ return "鏍囩妯″紡";
+ case "tag.interval":
+ return "鏍囩闂撮殧";
+ case "tag.power":
+ return "鏍囩鍔熺巼";
+ case "tag.sensitivity":
+ return "鏍囩鐏垫晱搴�";
+ case "anti.collision.enable":
+ return "闃叉挒浣胯兘";
+ case "safety.distance":
+ return "瀹夊叏璺濈";
+ case "warning.distance":
+ return "璀﹀憡璺濈";
+ case "alarm.distance":
+ return "鎶ヨ璺濈";
+ case "alarm.type":
+ return "鎶ヨ绫诲瀷";
+ case "upgrade.description":
+ return "鍥轰欢鍗囩骇鍔熻兘\n\n璇烽�夋嫨瑕佸崌绾х殑鍥轰欢鏂囦欢锛岀劧鍚庣偣鍑诲紑濮嬪崌绾ф寜閽�傚崌绾ц繃绋嬩腑璇峰嬁鏂紑鐢垫簮銆�";
+ case "start.upgrade":
+ return "寮�濮嬪崌绾�";
+
+ // 鏂板锛氬揩鎹疯绠楃浉鍏抽敭鍊煎
+ case "quick.calculation":
+ return "蹇嵎璁$畻";
+ case "quick.calc.title":
+ return "鍧愭爣璁$畻宸ュ叿";
+ // 鏂板锛氬崼鏄熸暟鎹浉鍏抽敭鍊煎
+ case "satellite.data":
+ return "鍗槦鏁版嵁";
+ case "sat.table.title":
+ return "鍗槦鏁版嵁";
+ case "sat.col.prn":
+ return "PRN";
+ case "sat.col.snr":
+ return "淇″櫔姣�(SNR)";
+ case "sat.col.azimuth":
+ return "鏂逛綅瑙�";
+ case "sat.col.elevation":
+ return "浠拌";
+ case "sat.col.used":
+ return "鏄惁琚娇鐢�";
+ // 鍗囩骇鐩稿叧閿�煎
+ case "upgrade.instructions":
+ return "鍗囩骇璇存槑";
+ case "select.folder":
+ return "閫夋嫨鏂囦欢澶�";
+ case "browse":
+ return "娴忚";
+ case "select.bin.file":
+ return "閫夋嫨BIN鏂囦欢";
+ case "selected.file":
+ return "宸查�夋嫨鏂囦欢";
+ case "file.selected":
+ return "鏂囦欢宸查�夋嫨";
+ case "please.select.folder.first":
+ return "璇峰厛閫夋嫨鏂囦欢澶�";
+ case "warning":
+ return "璀﹀憡";
+ case "upgrade.completed":
+ return "鍗囩骇瀹屾垚";
+ case "success":
+ return "鎴愬姛";
+ case "upgrade.in.progress":
+ return "鍗囩骇杩涜涓�...";
+ case "select.upgrade.file":
+ return "閫夋嫨鍗囩骇鏂囦欢";
+ case "upgrade.file":
+ return "鍗囩骇鏂囦欢";
+ case "upgrade.progress":
+ return "鍗囩骇杩涘害";
+ case "cancel.upgrade":
+ return "鍙栨秷鍗囩骇";
+ case "upgrade.success":
+ return "鍗囩骇鎴愬姛";
+ case "upgrade.failed":
+ return "鍗囩骇澶辫触";
+ case "confirm.upgrade":
+ return "纭鍗囩骇";
+ case "upgrade.confirmation":
+ return "鍗囩骇纭";
+ case "upgrade.confirm.message":
+ return "纭畾瑕佸紑濮嬪崌绾у悧锛熷崌绾ц繃绋嬩腑璇峰嬁鏂紑鐢垫簮銆�";
+ case "select.file":
+ return "閫夋嫨鏂囦欢";
+ case "no.file.selected":
+ return "鏈�夋嫨鏂囦欢";
+ case "file.not.found":
+ return "鏂囦欢鏈壘鍒�";
+ case "invalid.file":
+ return "鏃犳晥鏂囦欢";
+ case "upgrade.ready":
+ return "鍑嗗鍗囩骇";
+ case "preparing.upgrade":
+ return "鍑嗗鍗囩骇鐜...";
+ case "writing.firmware":
+ return "鍐欏叆鍥轰欢...";
+ case "verifying.firmware":
+ return "楠岃瘉鍥轰欢...";
+ case "upgrade.cancelled":
+ return "鍗囩骇宸插彇娑�";
+
+ // 鎵╁睍闈㈡澘鐩稿叧閿�煎
+ case "common.commands":
+ return "甯哥敤鎸囦护";
+ case "command.string":
+ return "鎸囦护瀛楃涓�";
+ case "save.common.commands":
+ return "淇濆瓨甯哥敤鎸囦护";
+ case "modify.common.commands":
+ return "淇敼甯哥敤鎸囦护";
+ case "load.commands.failed":
+ return "鍔犺浇鎸囦护澶辫触锛�";
+ case "save.commands.success":
+ return "淇濆瓨鎸囦护鎴愬姛锛�";
+ case "save.commands.failed":
+ return "淇濆瓨鎸囦护澶辫触锛�";
+ case "command.cannot.empty":
+ return "鎸囦护涓嶈兘涓虹┖锛�";
+ case "now.can.modify.commands":
+ return "鐜板湪鍙互淇敼琛ㄦ牸涓殑鎸囦护鍐呭锛屼慨鏀瑰畬鎴愬悗鐐瑰嚮淇濆瓨甯哥敤鎸囦护鎸夐挳";
+ case "prompt":
+ return "鎻愮ず";
+ case "error":
+ return "閿欒";
+
+ // 鎵╁睍鍛戒护鐩稿叧閿�煎
+ case "extension.command":
+ return "鎵╁睍鍛戒护";
+
+ default:
+ return key;
}
}
-
+
private void initializeUI() {
setTitle(getString("app.title"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(1200, 800);
+ setSize(1250, 800);
setLocationRelativeTo(null);
-
- // 创建顶部按钮面板
+
+ // 璁剧疆绐楀彛鍥炬爣
+ setWindowIcon();
+
+ // 鍒涘缓椤堕儴鎸夐挳闈㈡澘
JPanel topPanel = createTopPanel();
-
- // 创建主内容面板
+
+ // 鍒涘缓涓诲唴瀹归潰鏉�
cardLayout = new CardLayout();
mainPanel = new JPanel(cardLayout);
-
- // 初始化各功能面板
+
+ // 鍒濆鍖栧悇鍔熻兘闈㈡澘
serialPanel = new SerialCommunicationPanel(this);
networkPanel = new NetworkCommunicationPanel(this);
configPanel = new NetworkConfigPanel(this);
-
+
mainPanel.add(serialPanel, "SERIAL");
mainPanel.add(networkPanel, "NETWORK");
mainPanel.add(configPanel, "CONFIG");
-
- // 创建右侧面板(数据日志和发送面板)
+ // 鏂板锛氬崼鏄熸暟鎹潰鏉�
+ satellitePanel = new SatelliteDataPanel(this);
+ mainPanel.add(satellitePanel, "SATELLITE");
+
+ // 鍒涘缓鍙充晶闈㈡澘锛堟暟鎹棩蹇楀拰鍙戦�侀潰鏉匡級
JPanel rightPanel = createRightPanel();
-
- // 设置布局
+
+ // 璁剧疆甯冨眬
setLayout(new BorderLayout());
add(topPanel, BorderLayout.NORTH);
- add(mainPanel, BorderLayout.CENTER);
- add(rightPanel, BorderLayout.EAST);
-
- // 初始化快捷计算对话框
+
+ contentSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainPanel, rightPanel);
+ contentSplitPane.setResizeWeight(0.6); // 淇敼锛氳缃富闈㈡澘鍗�60%
+ contentSplitPane.setOneTouchExpandable(true);
+ contentSplitPane.setContinuousLayout(true);
+ contentSplitPane.setDividerLocation(0.6); // 淇敼锛氬垎鍓叉潯浣嶇疆鍦�60%澶�
+ add(contentSplitPane, BorderLayout.CENTER);
+
+ // 鍒濆鍖栧揩鎹疯绠楀璇濇
initQuickCalculationDialog();
-
- // 添加事件监听
+
+ // 娣诲姞浜嬩欢鐩戝惉
setupEventListeners();
-
- // 关键修改:连接串口面板和数据日志面板
+
+ // 鍏抽敭淇敼锛氳繛鎺ヤ覆鍙i潰鏉垮拰鏁版嵁鏃ュ織闈㈡澘
connectPanels();
}
-
+
private JPanel createTopPanel() {
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
-
- // 使用ButtonUtils创建导航按钮
+
+ // 浣跨敤ButtonUtils鍒涘缓瀵艰埅鎸夐挳
serialCommBtn = ButtonUtils.createBlueButton(getString("serial.communication"));
networkCommBtn = ButtonUtils.createBlueButton(getString("network.communication"));
networkConfigBtn = ButtonUtils.createBlueButton(getString("network.config"));
-
- // 新增:快捷计算按钮
+
+ // 鏂板锛氬揩鎹疯绠楁寜閽�
quickCalcBtn = ButtonUtils.createBlueButton(getString("quick.calculation"));
-
- languageCombo = new JComboBox<>(new String[]{"中文", "English"});
+ // 鏂板锛氬崼鏄熸暟鎹寜閽�
+ satelliteBtn = ButtonUtils.createBlueButton(getString("satellite.data"));
+
+ languageCombo = new JComboBox<>(new String[]{"涓枃", "English"});
languageCombo.setSelectedIndex(0);
languageCombo.addActionListener(e -> {
- Locale newLocale = languageCombo.getSelectedIndex() == 0 ?
+ Locale newLocale = languageCombo.getSelectedIndex() == 0 ?
Locale.SIMPLIFIED_CHINESE : Locale.ENGLISH;
switchLanguage(newLocale);
});
-
+
panel.add(serialCommBtn);
panel.add(networkCommBtn);
panel.add(networkConfigBtn);
- panel.add(quickCalcBtn); // 添加快捷计算按钮
-
+ panel.add(quickCalcBtn); // 娣诲姞蹇嵎璁$畻鎸夐挳
+ panel.add(satelliteBtn); // 娣诲姞鍗槦鏁版嵁鎸夐挳
+
JLabel languageLabel = new JLabel(getString("LANGUAGE") + ":");
panel.add(Box.createHorizontalStrut(20));
panel.add(languageLabel);
panel.add(languageCombo);
-
+
return panel;
}
-
+
private JPanel createRightPanel() {
- JPanel panel = new JPanel(new BorderLayout());
- panel.setPreferredSize(new Dimension(400, getHeight()));
-
dataLogPanel = new DataLogPanel(this);
sendPanel = new SendPanel(this);
-
- panel.add(dataLogPanel, BorderLayout.CENTER);
- panel.add(sendPanel, BorderLayout.SOUTH);
-
- return panel;
+
+ rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, dataLogPanel, sendPanel);
+ rightSplitPane.setResizeWeight(0.75); // 3:1 楂樺害姣斾緥
+ rightSplitPane.setContinuousLayout(true);
+ rightSplitPane.setDividerSize(6);
+ rightSplitPane.setBorder(null);
+ SwingUtilities.invokeLater(() -> rightSplitPane.setDividerLocation(0.75));
+
+ JPanel container = new JPanel(new BorderLayout());
+ // 淇敼锛氳缃彸渚ч潰鏉垮搴︿负涓荤獥鍙e搴︾殑40%锛�4:6姣斾緥锛�
+ container.setPreferredSize(new Dimension((int)(getWidth() * 0.4), getHeight()));
+ container.add(rightSplitPane, BorderLayout.CENTER);
+ return container;
}
-
+
/**
- * 初始化快捷计算对话框
+ * 鍒濆鍖栧揩鎹疯绠楀璇濇
*/
private void initQuickCalculationDialog() {
quickCalcDialog = new JDialog(this, getString("quick.calc.title"), false);
quickCalcDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
quickCalcDialog.setSize(900, 700);
quickCalcDialog.setLocationRelativeTo(this);
-
- // 创建快捷计算面板
+
+ // 鍒涘缓蹇嵎璁$畻闈㈡澘
quickCalcPanel = new QuickCalculationPanel(messages);
quickCalcDialog.add(quickCalcPanel);
}
-
+
private void setupEventListeners() {
serialCommBtn.addActionListener(e -> cardLayout.show(mainPanel, "SERIAL"));
networkCommBtn.addActionListener(e -> cardLayout.show(mainPanel, "NETWORK"));
networkConfigBtn.addActionListener(e -> cardLayout.show(mainPanel, "CONFIG"));
-
- // 新增:快捷计算按钮事件监听
+
+ // 鏂板锛氬揩鎹疯绠楁寜閽簨浠剁洃鍚�
quickCalcBtn.addActionListener(e -> {
quickCalcDialog.setVisible(true);
});
+
+ // 鏂板锛氬崼鏄熸暟鎹寜閽簨浠剁洃鍚�
+ satelliteBtn.addActionListener(e -> {
+ cardLayout.show(mainPanel, "SATELLITE");
+ });
}
-
+
/**
- * 关键修改:连接串口面板和数据日志面板
+ * 鍏抽敭淇敼锛氳繛鎺ヤ覆鍙i潰鏉垮拰鏁版嵁鏃ュ織闈㈡澘
*/
private void connectPanels() {
if (serialPanel != null && dataLogPanel != null) {
serialPanel.setDataLogPanel(dataLogPanel);
}
+ if (networkPanel != null && dataLogPanel != null) {
+ networkPanel.setDataLogPanel(dataLogPanel);
+ }
+ if (satellitePanel != null && dataLogPanel != null) {
+ satellitePanel.setDataLogPanel(dataLogPanel);
+ }
+
}
-
+
private void switchLanguage(Locale newLocale) {
this.currentLocale = newLocale;
this.messages = loadResourceBundle(currentLocale);
- // 更新界面文本
+ // 鏇存柊鐣岄潰鏂囨湰
updateUILanguage();
- // 更新语言选择框
+ // 鏇存柊璇█閫夋嫨妗�
languageCombo.setSelectedIndex(newLocale.equals(Locale.SIMPLIFIED_CHINESE) ? 0 : 1);
revalidate();
repaint();
}
-
+
private void updateUILanguage() {
- // 更新导航按钮文本
+ // 鏇存柊瀵艰埅鎸夐挳鏂囨湰
serialCommBtn.setText(getString("serial.communication"));
networkCommBtn.setText(getString("network.communication"));
networkConfigBtn.setText(getString("network.config"));
- quickCalcBtn.setText(getString("quick.calculation")); // 更新快捷计算按钮文本
-
- // 更新语言标签
+ quickCalcBtn.setText(getString("quick.calculation")); // 鏇存柊蹇嵎璁$畻鎸夐挳鏂囨湰
+ if (satelliteBtn != null) satelliteBtn.setText(getString("satellite.data")); // 鏇存柊鍗槦鎸夐挳鏂囨湰
+
+ // 鏇存柊璇█鏍囩
setTitle(getString("app.title"));
-
- // 更新对话框标题
+
+ // 鏇存柊瀵硅瘽妗嗘爣棰�
if (quickCalcDialog != null) {
quickCalcDialog.setTitle(getString("quick.calc.title"));
}
-
- // 更新各面板文本
+
+ // 鏇存柊鍚勯潰鏉挎枃鏈�
if (serialPanel != null) serialPanel.updateLanguage();
if (networkPanel != null) networkPanel.updateLanguage();
if (configPanel != null) configPanel.updateLanguage();
if (dataLogPanel != null) dataLogPanel.updateLanguage();
+ if (satellitePanel != null) satellitePanel.updateLanguage();
if (sendPanel != null) sendPanel.updateLanguage();
-
- // 更新快捷计算面板
+
+ // 鏇存柊蹇嵎璁$畻闈㈡澘
if (quickCalcPanel != null) {
- // 重新创建快捷计算面板以更新语言
+ // 閲嶆柊鍒涘缓蹇嵎璁$畻闈㈡澘浠ユ洿鏂拌瑷�
quickCalcDialog.getContentPane().removeAll();
quickCalcPanel = new QuickCalculationPanel(messages);
quickCalcDialog.add(quickCalcPanel);
@@ -407,30 +581,32 @@
quickCalcDialog.repaint();
}
}
-
+
public Locale getCurrentLocale() {
return currentLocale;
}
-
+
/**
- * 获取数据日志面板实例
- * @return DataLogPanel实例
+ * 鑾峰彇鏁版嵁鏃ュ織闈㈡澘瀹炰緥
+ *
+ * @return DataLogPanel瀹炰緥
*/
public DataLogPanel getDataLogPanel() {
return dataLogPanel;
}
-
+
/**
- * 从扩展面板发送数据
- * @param data 要发送的数据
- * @param isHex 是否为HEX格式
+ * 浠庢墿灞曢潰鏉垮彂閫佹暟鎹�
+ *
+ * @param data 瑕佸彂閫佺殑鏁版嵁
+ * @param isHex 鏄惁涓篐EX鏍煎紡
*/
public void sendDataFromExtension(String data, boolean isHex) {
if (data == null || data.trim().isEmpty()) {
return;
}
-
- // 根据当前激活的面板决定发送方式
+
+ // 鏍规嵁褰撳墠婵�娲荤殑闈㈡澘鍐冲畾鍙戦�佹柟寮�
Component currentPanel = null;
for (Component comp : mainPanel.getComponents()) {
if (comp.isVisible()) {
@@ -438,53 +614,82 @@
break;
}
}
-
+
if (currentPanel instanceof SerialCommunicationPanel) {
- // 串口通信面板激活,通过串口发送
+ // 涓插彛閫氫俊闈㈡澘婵�娲伙紝閫氳繃涓插彛鍙戦��
sendViaSerial(data, isHex);
} else if (currentPanel instanceof NetworkCommunicationPanel) {
- // 网络通信面板激活,通过网络发送
+ // 缃戠粶閫氫俊闈㈡澘婵�娲伙紝閫氳繃缃戠粶鍙戦��
sendViaNetwork(data, isHex);
} else {
- // 默认尝试通过串口发送
+ // 榛樿灏濊瘯閫氳繃涓插彛鍙戦��
sendViaSerial(data, isHex);
}
}
-
+
/**
- * 通过串口发送数据
+ * 閫氳繃涓插彛鍙戦�佹暟鎹�
*/
private void sendViaSerial(String data, boolean isHex) {
if (serialPanel != null) {
- // 这里调用串口面板的发送方法
- // 需要根据您的SerialCommunicationPanel实现来调用相应方法
-
- // 示例:如果串口面板有发送数据的方法
+ // 杩欓噷璋冪敤涓插彛闈㈡澘鐨勫彂閫佹柟娉�
+ // 闇�瑕佹牴鎹偍鐨凷erialCommunicationPanel瀹炵幇鏉ヨ皟鐢ㄧ浉搴旀柟娉�
+
+ // 绀轰緥锛氬鏋滀覆鍙i潰鏉挎湁鍙戦�佹暟鎹殑鏂规硶
// serialPanel.sendData(data, isHex);
} else {
- System.err.println("串口面板未初始化");
+ System.err.println("涓插彛闈㈡澘鏈垵濮嬪寲");
}
}
-
+
/**
- * 通过网络发送数据
+ * 閫氳繃缃戠粶鍙戦�佹暟鎹�
*/
private void sendViaNetwork(String data, boolean isHex) {
if (networkPanel != null) {
- // 这里调用网络面板的发送方法
- // 需要根据您的NetworkCommunicationPanel实现来调用相应方法
-
- // 示例:如果网络面板有发送数据的方法
- // networkPanel.sendData(data, isHex);
+ if (isHex) {
+ // networkPanel.sendHexNetworkData(data);
+ } else {
+ //networkPanel.sendNetworkData(data.getBytes(java.nio.charset.StandardCharsets.UTF_8));
+ }
} else {
- System.err.println("网络面板未初始化");
+ System.err.println("缃戠粶闈㈡澘鏈垵濮嬪寲");
}
}
-
+
public void addToDataLog(String logMessage) {
if (dataLogPanel != null) {
- // 通过DataLogPanel的公共方法添加日志
+ // 閫氳繃DataLogPanel鐨勫叕鍏辨柟娉曟坊鍔犳棩蹇�
dataLogPanel.addLog(logMessage);
}
}
+
+
+ /**
+ * 鑾峰彇缃戠粶閫氫俊闈㈡澘瀹炰緥
+ */
+ public NetworkCommunicationPanel getNetworkCommunicationPanel() {
+ // 鏍规嵁鎮ㄧ殑瀹為檯瀹炵幇杩斿洖缃戠粶閫氫俊闈㈡澘
+ // 渚嬪锛屽鏋滅綉缁滈�氫俊闈㈡澘鏄�夐」鍗′腑鐨勪竴涓紝鍙互杩欐牱鑾峰彇锛�
+ return networkPanel;
+ }
+
+ /**
+ * 璁剧疆绐楀彛鍥炬爣
+ */
+ private void setWindowIcon() {
+ try {
+ File iconFile = new File("image/setting.png");
+ if (iconFile.exists()) {
+ Image icon = ImageIO.read(iconFile);
+ if (icon != null) {
+ setIconImage(icon);
+ }
+ } else {
+ System.err.println("鍥炬爣鏂囦欢涓嶅瓨鍦�: " + iconFile.getAbsolutePath());
+ }
+ } catch (IOException e) {
+ System.err.println("鍔犺浇鍥炬爣鏂囦欢澶辫触: " + e.getMessage());
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.10.0