826220679@qq.com
2025-10-31 9aca70f16836952e2e3462ecc69dabe679811eb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
package home;
 
import javax.swing.*;
import java.awt.*;
import java.util.Locale;
import java.util.ResourceBundle;
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.util.PropertyResourceBundle;
 
public class MainFrame extends JFrame {
    private static final long serialVersionUID = 1L;
    private ResourceBundle messages;
    private Locale currentLocale;
    private CardLayout cardLayout;
    private JPanel mainPanel;
    private JButton serialCommBtn, networkCommBtn, networkConfigBtn;
    private JComboBox<String> languageCombo;
    
    // ¸÷¹¦ÄÜÃæ°å
    private SerialCommunicationPanel serialPanel;
    private NetworkCommunicationPanel networkPanel;
    private NetworkConfigPanel configPanel;
    private DataLogPanel dataLogPanel;
    private SendPanel sendPanel;
    
    // ÐÂÔö£º¿ì½Ý¼ÆËãÃæ°åÏà¹Ø
    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) ? 
                "Messages_en.properties" : "Messages_zh.properties";
 
        File langFile = new File("systemfile/" + fileName);
 
        if (!langFile.exists()) {
            System.err.println("ĬÈÏ×ÊÔ´ÎļþδÕÒµ½: " + langFile.getAbsolutePath());
            // ±¸Ó÷½°¸£º³¢ÊÔ´ÓÀà·¾¶¼ÓÔØ
            try {
                return ResourceBundle.getBundle("Messages", locale);
            } catch (Exception e) {
                System.err.println("ÎÞ·¨¼ÓÔØ±¸ÓÃ×ÊÔ´Îļþ");
                return createDefaultResourceBundle();
            }
        }
 
        try (InputStream inputStream = new FileInputStream(langFile)) {
            return new PropertyResourceBundle(inputStream);
        } catch (IOException e) {
            System.err.println("ÎÞ·¨¼ÓÔØ×ÊÔ´Îļþ: " + e.getMessage());
            // ±¸Ó÷½°¸
            try {
                return ResourceBundle.getBundle("Messages", locale);
            } catch (Exception ex) {
                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", "×ø±ê¼ÆË㹤¾ß");
        
        try {
            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£¬·µ»ØÄ¬ÈÏÖµ
                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 "Ð޸ij£ÓÃÖ¸Áî";
            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);
        setLocationRelativeTo(null);
        
        // ´´½¨¶¥²¿°´Å¥Ãæ°å
        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");
        
        // ´´½¨ÓÒ²àÃæ°å£¨Êý¾ÝÈÕÖ¾ºÍ·¢ËÍÃæ°å£©
        JPanel rightPanel = createRightPanel();
        
        // ÉèÖò¼¾Ö
        setLayout(new BorderLayout());
        add(topPanel, BorderLayout.NORTH);
        add(mainPanel, BorderLayout.CENTER);
        add(rightPanel, BorderLayout.EAST);
        
        // ³õʼ»¯¿ì½Ý¼ÆËã¶Ô»°¿ò
        initQuickCalculationDialog();
        
        // Ìí¼Óʼþ¼àÌý
        setupEventListeners();
        
        // ¹Ø¼üÐ޸ģºÁ¬½Ó´®¿ÚÃæ°åºÍÊý¾ÝÈÕÖ¾Ãæ°å
        connectPanels();
    }
    
    private JPanel createTopPanel() {
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        
        // Ê¹ÓÃ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"});
        languageCombo.setSelectedIndex(0);
        languageCombo.addActionListener(e -> {
            Locale newLocale = languageCombo.getSelectedIndex() == 0 ? 
                    Locale.SIMPLIFIED_CHINESE : Locale.ENGLISH;
            switchLanguage(newLocale);
        });
        
        panel.add(serialCommBtn);
        panel.add(networkCommBtn);
        panel.add(networkConfigBtn);
        panel.add(quickCalcBtn); // Ìí¼Ó¿ì½Ý¼ÆËã°´Å¥
        
        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;
    }
    
    /**
     * ³õʼ»¯¿ì½Ý¼ÆËã¶Ô»°¿ò
     */
    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);
        });
    }
    
    /**
     * ¹Ø¼üÐ޸ģºÁ¬½Ó´®¿ÚÃæ°åºÍÊý¾ÝÈÕÖ¾Ãæ°å
     */
    private void connectPanels() {
        if (serialPanel != null && dataLogPanel != null) {
            serialPanel.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")); // ¸üпì½Ý¼ÆËã°´Å¥Îı¾
        
        // ¸üÐÂÓïÑÔ±êÇ©
        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 (sendPanel != null) sendPanel.updateLanguage();
        
        // ¸üпì½Ý¼ÆËãÃæ°å
        if (quickCalcPanel != null) {
            // ÖØÐ´´½¨¿ì½Ý¼ÆËãÃæ°åÒÔ¸üÐÂÓïÑÔ
            quickCalcDialog.getContentPane().removeAll();
            quickCalcPanel = new QuickCalculationPanel(messages);
            quickCalcDialog.add(quickCalcPanel);
            quickCalcDialog.revalidate();
            quickCalcDialog.repaint();
        }
    }
    
    public Locale getCurrentLocale() {
        return currentLocale;
    }
    
    /**
     * »ñÈ¡Êý¾ÝÈÕÖ¾Ãæ°åʵÀý
     * @return DataLogPanelʵÀý
     */
    public DataLogPanel getDataLogPanel() {
        return dataLogPanel;
    }
    
    /**
     * ´ÓÀ©Õ¹Ãæ°å·¢ËÍÊý¾Ý
     * @param data Òª·¢Ë͵ÄÊý¾Ý
     * @param isHex ÊÇ·ñΪHEX¸ñʽ
     */
    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()) {
                currentPanel = comp;
                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ʵÏÖÀ´µ÷ÓÃÏàÓ¦·½·¨
            
            // Ê¾Àý£ºÈç¹û´®¿ÚÃæ°åÓз¢ËÍÊý¾ÝµÄ·½·¨
            // serialPanel.sendData(data, isHex);
        } else {
            System.err.println("´®¿ÚÃæ°åδ³õʼ»¯");
        }
    }
    
    /**
     * Í¨¹ýÍøÂç·¢ËÍÊý¾Ý
     */
    private void sendViaNetwork(String data, boolean isHex) {
        if (networkPanel != null) {
            // ÕâÀïµ÷ÓÃÍøÂçÃæ°åµÄ·¢ËÍ·½·¨
            // ÐèÒª¸ù¾ÝÄúµÄNetworkCommunicationPanelʵÏÖÀ´µ÷ÓÃÏàÓ¦·½·¨
            
            // Ê¾Àý£ºÈç¹ûÍøÂçÃæ°åÓз¢ËÍÊý¾ÝµÄ·½·¨
            // networkPanel.sendData(data, isHex);
        } else {
            System.err.println("ÍøÂçÃæ°åδ³õʼ»¯");
        }
    }
    
    public void addToDataLog(String logMessage) {
        if (dataLogPanel != null) {
            // Í¨¹ýDataLogPanelµÄ¹«¹²·½·¨Ìí¼ÓÈÕÖ¾
            dataLogPanel.addLog(logMessage);
        }
    }
}