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);
|
}
|
}
|