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
package home;
 
import javax.swing.*;
import java.awt.*;
 
public class NetworkConfigPanel extends JPanel {
    private static final long serialVersionUID = 1L;
    private MainFrame mainFrame;
    private JComboBox<String> protocolCombo;
    private JTextField addressField, portField;
    private JButton openBtn, searchBtn;
    private JLabel protocolLabel, addressLabel, portLabel;
    private JTable deviceTable;
    private JPanel basicSettingsPanel, portSettingsPanel;
    
    public NetworkConfigPanel(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        initializeUI();
    }
    
    private void initializeUI() {
        setLayout(new BorderLayout());
        
        // ¿ØÖÆÃæ°å
        add(createControlPanel(), BorderLayout.NORTH);
        
        // É豸±í¸ñºÍÅäÖÃÃæ°å
        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        splitPane.setLeftComponent(createDeviceTablePanel());
        splitPane.setRightComponent(createConfigPanel());
        splitPane.setDividerLocation(400);
        
        add(splitPane, BorderLayout.CENTER);
    }
    
    private JPanel createControlPanel() {
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
        
        protocolLabel = new JLabel(getString("protocol.type"));
        panel.add(protocolLabel);
        
        protocolCombo = new JComboBox<>(new String[]{"UDP", "TCP"});
        protocolCombo.setPreferredSize(new Dimension(150, 25));
        panel.add(protocolCombo);
        
        addressLabel = new JLabel(getString("local.host.address"));
        panel.add(addressLabel);
        
        addressField = new JTextField();
        addressField.setPreferredSize(new Dimension(150, 25));
        panel.add(addressField);
        
        portLabel = new JLabel(getString("local.host.port"));
        panel.add(portLabel);
        
        portField = new JTextField();
        portField.setPreferredSize(new Dimension(150, 25));
        panel.add(portField);
        
        // Ê¹ÓÃButtonUtils»ñȡͳһÑùʽµÄ°´Å¥
        openBtn = ButtonUtils.createBlueButton(getString("open"));
        searchBtn = ButtonUtils.createBlueButton(getString("search.devices"));
        
        panel.add(openBtn);
        panel.add(searchBtn);
        
        return panel;
    }
    
    private JPanel createDeviceTablePanel() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createTitledBorder(getString("device.list")));
        
        String[] columnNames = {
            getString("select"),
            getString("device.ip"),
            getString("device.name"),
            getString("mac.address"),
            getString("version")
        };
        
        Object[][] data = {}; // ¿ÕÊý¾Ý£¬Êµ¼ÊʹÓÃʱ¶¯Ì¬Ìî³ä
        deviceTable = new JTable(data, columnNames);
        JScrollPane scrollPane = new JScrollPane(deviceTable);
        
        panel.add(scrollPane, BorderLayout.CENTER);
        
        return panel;
    }
    
    private JPanel createConfigPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        
        // ´´½¨°üº¬»ù´¡ÉèÖúͶ˿ÚÉèÖõĹö¶¯Ãæ°å
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        
        // Ìí¼Ó¶¥²¿¼ä¾à
        contentPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
        
        // »ù´¡ÉèÖÃ
        basicSettingsPanel = createBasicSettingsPanel();
        contentPanel.add(basicSettingsPanel);
        contentPanel.add(Box.createVerticalStrut(10));
        
        // ¶Ë¿ÚÉèÖÃ
        portSettingsPanel = createPortSettingsPanel();
        contentPanel.add(portSettingsPanel);
        
        // ½«ÄÚÈÝÃæ°å·ÅÈë¹ö¶¯Ãæ°å
        JScrollPane scrollPane = new JScrollPane(contentPanel);
        scrollPane.setBorder(BorderFactory.createEmptyBorder());
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        JPanel wrapperPanel = new JPanel(new BorderLayout());
        wrapperPanel.add(scrollPane, BorderLayout.CENTER);
        
        return wrapperPanel;
    }
    
    private JPanel createBasicSettingsPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setBorder(BorderFactory.createTitledBorder(getString("basic.settings")));
        
        // µÚÒ»ÐÐ
        panel.add(createParameterRow("ip.address.type", createComboBox(new String[]{getString("static.ip")}, 150, 25), true));
        
        // µÚ¶þÐÐ
        panel.add(createParameterRow("module.static.ip", createTextField("", 150, 25), true));
        
        // µÚÈýÐÐ
        panel.add(createParameterRow("subnet.mask", createTextField("", 150, 25), true));
        
        // µÚËÄÐÐ
        panel.add(createParameterRow("gateway", createTextField("", 150, 25), true));
        
        // µÚÎåÐÐ
        panel.add(createParameterRow("dns.address", createTextField("", 150, 25), false));
        
        // µÚÁùÐÐ
        panel.add(createParameterRow("user.mac.address", createTextField("", 150, 25), false));
        
        // µÚÆßÐÐ
        panel.add(createParameterRow("timeout.restart", createTextField("", 150, 25), false));
        
        // µÚ°ËÐÐ
        panel.add(createParameterRow("http.service.port", createTextField("", 150, 25), false));
        
        // µÚ¾ÅÐÐ
        panel.add(createParameterRow("username", createTextField("", 150, 25), false));
        
        // µÚÊ®ÐÐ
        panel.add(createParameterRow("password", createTextField("", 150, 25), false));
        
        // µÚʮһÐÐ
        panel.add(createParameterRow("device.name", createTextField("", 150, 25), false));
        
        // µÚÊ®¶þÐР- Ñ¡Ïѡ¿ò£¨µÚÒ»ÐУ©
        JPanel optionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
        optionPanel.add(new JLabel(getString("options") + ":"));
        
        JPanel checkPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
        checkPanel.add(new JCheckBox("Index"));
        checkPanel.add(new JCheckBox("Reset"));
        checkPanel.add(new JCheckBox("Link"));
        checkPanel.add(new JCheckBox("RFC2217"));
        
        optionPanel.add(checkPanel);
        optionPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
        panel.add(optionPanel);
        
        // µÚÊ®ÈýÐР- Ñ¡Ïѡ¿ò£¨µÚ¶þÐУ©
        JPanel optionPanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
        // Ìí¼Ó¿Õ±êÇ©±£³Ö¶ÔÆë
        optionPanel2.add(new JLabel(" "));
        
        JPanel checkPanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
        checkPanel2.add(new JCheckBox(getString("clear.cache")));
        checkPanel2.add(new JCheckBox(getString("serial.settings")));
        
        optionPanel2.add(checkPanel2);
        optionPanel2.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
        panel.add(optionPanel2);
        
        return panel;
    }
    
    private JPanel createPortSettingsPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.setBorder(BorderFactory.createTitledBorder(getString("port.settings")));
        
        // µÚÒ»ÐÐ
        panel.add(createParameterRow("module.work.mode", createComboBox(new String[]{"UDP Client", "TCP Client", "TCP Server"}, 150, 25), false));
        
        // µÚ¶þÐÐ
        panel.add(createParameterRow("target.ip.domain", createTextField("", 150, 25), false));
        
        // µÚÈýÐÐ
        panel.add(createParameterRow("short.connection.time", createTextField("", 150, 25), false));
        
        // µÚËÄÐÐ
        panel.add(createParameterRow("serial.baud.rate", createComboBoxWithSelection(new String[]{"9600", "19200", "38400", "115200", "921600"}, "115200", 150, 25), false));
        
        // µÚÎåÐÐ
        panel.add(createParameterRow("local.port", createTextField("", 150, 25), false));
        
        // µÚÁùÐÐ
        panel.add(createParameterRow("remote.port", createTextField("", 150, 25), false));
        
        // µÚÆßÐÐ
        panel.add(createParameterRow("tcp.server.connections", createComboBox(new String[]{"4", "3", "2", "1"}, 150, 25), false));
        
        // µÚ°ËÐР- ¿ªÆô¶ÌÁ¬½Ó¸´Ñ¡¿ò
        JPanel shortConnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
        shortConnPanel.add(new JLabel(" ")); // ¿Õ±êÇ©±£³Ö¶ÔÆë
        
        JPanel shortConnSubPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
        shortConnSubPanel.add(new JCheckBox(getString("enable.short.connection")));
        
        shortConnPanel.add(shortConnSubPanel);
        shortConnPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
        panel.add(shortConnPanel);
        
        // µÚ¾ÅÐР- Ð£Ñé/Êý¾Ý/Í£Ö¹
        JPanel parityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
        parityPanel.add(new JLabel(getString("parity.data.stop") + ":"));
        
        JPanel paritySubPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
        paritySubPanel.add(createComboBox(new String[]{"NONE"}, 80, 25));
        paritySubPanel.add(createComboBox(new String[]{"8"}, 60, 25));
        paritySubPanel.add(createComboBox(new String[]{"1"}, 60, 25));
        
        parityPanel.add(paritySubPanel);
        parityPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
        panel.add(parityPanel);
        
        // µÚÊ®ÐР- ±£´æ²ÎÊý°´Å¥
        JPanel savePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        savePanel.add(ButtonUtils.createBlueButton(getString("save.parameters")));
        savePanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
        panel.add(savePanel);
        
        return panel;
    }
    
    // ´´½¨²ÎÊýÐеĸ¨Öú·½·¨£¬²Î¿¼BaseStationPanelµÄ²¼¾Ö
    private JPanel createParameterRow(String paramKey, JComponent component, boolean withStar) {
        JPanel paramPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
        
        String labelText = getString(paramKey);
        if (withStar) {
            labelText += " ¡ï";
        }
        
        JLabel label = new JLabel(labelText);
        label.setPreferredSize(new Dimension(140, 25));
        
        paramPanel.add(label);
        paramPanel.add(component);
        
        // ÉèÖù̶¨¸ß¶È
        paramPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
        return paramPanel;
    }
    
    // ´´½¨Îı¾¿òµÄ¸¨Öú·½·¨
    private JTextField createTextField(String text, int width, int height) {
        JTextField textField = new JTextField(text);
        textField.setPreferredSize(new Dimension(width, height));
        return textField;
    }
    
    // ´´½¨ÏÂÀ­¿òµÄ¸¨Öú·½·¨
    private JComboBox<String> createComboBox(String[] items, int width, int height) {
        JComboBox<String> comboBox = new JComboBox<>(items);
        comboBox.setPreferredSize(new Dimension(width, height));
        return comboBox;
    }
    
    // ´´½¨´øÄ¬ÈÏÑ¡ÔñµÄÏÂÀ­¿ò
    private JComboBox<String> createComboBoxWithSelection(String[] items, String selected, int width, int height) {
        JComboBox<String> comboBox = createComboBox(items, width, height);
        comboBox.setSelectedItem(selected);
        return comboBox;
    }
    
    public void updateLanguage() {
        // ¸üпØÖÆÃæ°åÎı¾
        protocolLabel.setText(getString("protocol.type"));
        addressLabel.setText(getString("local.host.address"));
        portLabel.setText(getString("local.host.port"));
        openBtn.setText(getString("open"));
        searchBtn.setText(getString("search.devices"));
        
        // ¸üÐÂÉ豸±í¸ñ±êÌâ
        if (deviceTable != null) {
            // ¸üбí¸ñ±êÌâ
            String[] columnNames = {
                getString("select"),
                getString("device.ip"),
                getString("device.name"),
                getString("mac.address"),
                getString("version")
            };
            // ÕâÀïÐèÒª¸üбí¸ñÁÐÃû£¬ÎªÁ˼òµ¥Æð¼û£¬ÎÒÃÇÖ»¸üб߿ò±êÌâ
            JViewport viewport = (JViewport) deviceTable.getParent();
            if (viewport != null) {
                JScrollPane scrollPane = (JScrollPane) viewport.getParent();
                if (scrollPane != null) {
                    scrollPane.setBorder(BorderFactory.createTitledBorder(getString("device.list")));
                }
            }
        }
        
        // ¸üÐÂÉèÖÃÃæ°å±ß¿ò±êÌâ
        if (basicSettingsPanel != null) {
            basicSettingsPanel.setBorder(BorderFactory.createTitledBorder(getString("basic.settings")));
        }
        if (portSettingsPanel != null) {
            portSettingsPanel.setBorder(BorderFactory.createTitledBorder(getString("port.settings")));
        }
        
        revalidate();
        repaint();
    }
    
    private String getString(String key) {
        return mainFrame.getString(key);
    }
}