|
|
@@ -0,0 +1,257 @@
|
|
|
+package com.mes.ui;
|
|
|
+
|
|
|
+import javax.swing.*;
|
|
|
+import javax.swing.border.EmptyBorder;
|
|
|
+import javax.swing.border.TitledBorder;
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
+import java.awt.event.ActionListener;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 启动配置页:工位信息 + 两把拉铆枪 IP / 打铆颗数(无需密码)
|
|
|
+ */
|
|
|
+public class GunConfigFrame extends JFrame {
|
|
|
+
|
|
|
+ private static final Pattern IP_PATTERN = Pattern.compile(
|
|
|
+ "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
|
|
|
+
|
|
|
+ private JTextField gwTxt;
|
|
|
+ private JTextField gwDesTxt;
|
|
|
+ private JTextField serverIpTxt;
|
|
|
+ private JTextField gunAIpTxt;
|
|
|
+ private JTextField gunANumTxt;
|
|
|
+ private JTextField gunBIpTxt;
|
|
|
+ private JTextField gunBNumTxt;
|
|
|
+
|
|
|
+ public GunConfigFrame() {
|
|
|
+ setTitle("启动配置 - " + nullToEmpty(MesClient.mes_gw) + " " + nullToEmpty(MesClient.mes_gw_des));
|
|
|
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
+ setResizable(false);
|
|
|
+ try {
|
|
|
+ setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ }
|
|
|
+
|
|
|
+ JPanel root = new JPanel(new BorderLayout(0, 16));
|
|
|
+ root.setBorder(new EmptyBorder(24, 28, 24, 28));
|
|
|
+ root.setBackground(new Color(245, 247, 250));
|
|
|
+ setContentPane(root);
|
|
|
+
|
|
|
+ JLabel title = new JLabel("启动配置", SwingConstants.CENTER);
|
|
|
+ title.setFont(new Font("微软雅黑", Font.BOLD, 28));
|
|
|
+ title.setForeground(new Color(33, 37, 41));
|
|
|
+ root.add(title, BorderLayout.NORTH);
|
|
|
+
|
|
|
+ JPanel center = new JPanel();
|
|
|
+ center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
|
|
|
+ center.setOpaque(false);
|
|
|
+ center.add(buildStationPanel());
|
|
|
+ center.add(Box.createVerticalStrut(16));
|
|
|
+
|
|
|
+ JPanel guns = new JPanel(new GridLayout(1, 2, 20, 0));
|
|
|
+ guns.setOpaque(false);
|
|
|
+ guns.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
|
+ guns.add(buildGunPanel("A枪", true));
|
|
|
+ guns.add(buildGunPanel("B枪", false));
|
|
|
+ center.add(guns);
|
|
|
+ root.add(center, BorderLayout.CENTER);
|
|
|
+
|
|
|
+ JPanel bottom = new JPanel(new FlowLayout(FlowLayout.CENTER, 16, 0));
|
|
|
+ bottom.setOpaque(false);
|
|
|
+
|
|
|
+ JButton enterBtn = new JButton("保存并进入登录");
|
|
|
+ enterBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ enterBtn.setPreferredSize(new Dimension(200, 44));
|
|
|
+ enterBtn.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ onEnter();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ JLabel tip = new JLabel("工位与枪参数均可修改,保存后写入本地配置");
|
|
|
+ tip.setFont(new Font("微软雅黑", Font.PLAIN, 13));
|
|
|
+ tip.setForeground(new Color(108, 117, 125));
|
|
|
+
|
|
|
+ bottom.add(enterBtn);
|
|
|
+ JPanel south = new JPanel(new BorderLayout());
|
|
|
+ south.setOpaque(false);
|
|
|
+ south.add(bottom, BorderLayout.CENTER);
|
|
|
+ south.add(tip, BorderLayout.SOUTH);
|
|
|
+ root.add(south, BorderLayout.SOUTH);
|
|
|
+
|
|
|
+ Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
|
|
+ int width = 720;
|
|
|
+ int height = 520;
|
|
|
+ setBounds((d.width - width) / 2, (d.height - height) / 2 - 40, width, height);
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel buildStationPanel() {
|
|
|
+ JPanel panel = new JPanel(new GridBagLayout());
|
|
|
+ panel.setBackground(Color.WHITE);
|
|
|
+ panel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
|
+ panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 160));
|
|
|
+ panel.setBorder(BorderFactory.createCompoundBorder(
|
|
|
+ BorderFactory.createTitledBorder(
|
|
|
+ BorderFactory.createLineBorder(new Color(206, 212, 218)),
|
|
|
+ "工位配置",
|
|
|
+ TitledBorder.LEFT,
|
|
|
+ TitledBorder.TOP,
|
|
|
+ new Font("微软雅黑", Font.BOLD, 16),
|
|
|
+ new Color(52, 58, 64)),
|
|
|
+ new EmptyBorder(8, 16, 8, 16)));
|
|
|
+
|
|
|
+ gwTxt = addFormRow(panel, "工位号:", 0);
|
|
|
+ gwTxt.setText(nullToEmpty(MesClient.mes_gw));
|
|
|
+ gwDesTxt = addFormRow(panel, "工位名称:", 1);
|
|
|
+ gwDesTxt.setText(nullToEmpty(MesClient.mes_gw_des));
|
|
|
+ serverIpTxt = addFormRow(panel, "服务器IP:", 2);
|
|
|
+ serverIpTxt.setText(nullToEmpty(MesClient.mes_server_ip));
|
|
|
+ return panel;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JTextField addFormRow(JPanel panel, String labelText, int row) {
|
|
|
+ GridBagConstraints lc = new GridBagConstraints();
|
|
|
+ lc.gridx = 0;
|
|
|
+ lc.gridy = row;
|
|
|
+ lc.anchor = GridBagConstraints.EAST;
|
|
|
+ lc.insets = new Insets(6, 4, 6, 8);
|
|
|
+ JLabel label = new JLabel(labelText);
|
|
|
+ label.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
+ panel.add(label, lc);
|
|
|
+
|
|
|
+ GridBagConstraints fc = new GridBagConstraints();
|
|
|
+ fc.gridx = 1;
|
|
|
+ fc.gridy = row;
|
|
|
+ fc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ fc.weightx = 1;
|
|
|
+ fc.insets = new Insets(6, 0, 6, 4);
|
|
|
+ JTextField field = new JTextField(20);
|
|
|
+ field.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
+ panel.add(field, fc);
|
|
|
+ return field;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel buildGunPanel(String title, boolean isA) {
|
|
|
+ JPanel panel = new JPanel(new GridBagLayout());
|
|
|
+ panel.setBackground(Color.WHITE);
|
|
|
+ panel.setPreferredSize(new Dimension(320, 160));
|
|
|
+ panel.setBorder(BorderFactory.createCompoundBorder(
|
|
|
+ BorderFactory.createTitledBorder(
|
|
|
+ BorderFactory.createLineBorder(new Color(206, 212, 218)),
|
|
|
+ title,
|
|
|
+ TitledBorder.LEFT,
|
|
|
+ TitledBorder.TOP,
|
|
|
+ new Font("微软雅黑", Font.BOLD, 16),
|
|
|
+ new Color(52, 58, 64)),
|
|
|
+ new EmptyBorder(12, 16, 12, 16)));
|
|
|
+
|
|
|
+ GridBagConstraints lc = new GridBagConstraints();
|
|
|
+ lc.gridx = 0;
|
|
|
+ lc.gridy = 0;
|
|
|
+ lc.anchor = GridBagConstraints.EAST;
|
|
|
+ lc.insets = new Insets(8, 4, 8, 8);
|
|
|
+ JLabel ipLabel = new JLabel("IP地址:");
|
|
|
+ ipLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
+ panel.add(ipLabel, lc);
|
|
|
+
|
|
|
+ GridBagConstraints fc = new GridBagConstraints();
|
|
|
+ fc.gridx = 1;
|
|
|
+ fc.gridy = 0;
|
|
|
+ fc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
+ fc.weightx = 1;
|
|
|
+ fc.insets = new Insets(8, 0, 8, 4);
|
|
|
+ JTextField ipTxt = new JTextField(16);
|
|
|
+ ipTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
+ panel.add(ipTxt, fc);
|
|
|
+
|
|
|
+ lc.gridy = 1;
|
|
|
+ JLabel numLabel = new JLabel("打铆颗数:");
|
|
|
+ numLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
+ panel.add(numLabel, lc);
|
|
|
+
|
|
|
+ fc.gridy = 1;
|
|
|
+ JTextField numTxt = new JTextField(16);
|
|
|
+ numTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
+ panel.add(numTxt, fc);
|
|
|
+
|
|
|
+ if (isA) {
|
|
|
+ gunAIpTxt = ipTxt;
|
|
|
+ gunANumTxt = numTxt;
|
|
|
+ gunAIpTxt.setText(MesClient.plcAIp);
|
|
|
+ gunANumTxt.setText(String.valueOf(MesClient.aSetNum));
|
|
|
+ } else {
|
|
|
+ gunBIpTxt = ipTxt;
|
|
|
+ gunBNumTxt = numTxt;
|
|
|
+ gunBIpTxt.setText(MesClient.plcBIp);
|
|
|
+ gunBNumTxt.setText(String.valueOf(MesClient.bSetNum));
|
|
|
+ }
|
|
|
+ return panel;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onEnter() {
|
|
|
+ String gw = gwTxt.getText().trim();
|
|
|
+ String gwDes = gwDesTxt.getText().trim();
|
|
|
+ String serverIp = serverIpTxt.getText().trim();
|
|
|
+ String aIp = gunAIpTxt.getText().trim();
|
|
|
+ String bIp = gunBIpTxt.getText().trim();
|
|
|
+ String aNumStr = gunANumTxt.getText().trim();
|
|
|
+ String bNumStr = gunBNumTxt.getText().trim();
|
|
|
+
|
|
|
+ if (gw.isEmpty()) {
|
|
|
+ JOptionPane.showMessageDialog(this, "请输入工位号", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (gwDes.isEmpty()) {
|
|
|
+ JOptionPane.showMessageDialog(this, "请输入工位名称", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!IP_PATTERN.matcher(serverIp).matches()) {
|
|
|
+ JOptionPane.showMessageDialog(this, "服务器 IP 格式不正确", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!IP_PATTERN.matcher(aIp).matches()) {
|
|
|
+ JOptionPane.showMessageDialog(this, "A枪 IP 格式不正确", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!IP_PATTERN.matcher(bIp).matches()) {
|
|
|
+ JOptionPane.showMessageDialog(this, "B枪 IP 格式不正确", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ short aNum;
|
|
|
+ short bNum;
|
|
|
+ try {
|
|
|
+ aNum = Short.parseShort(aNumStr);
|
|
|
+ bNum = Short.parseShort(bNumStr);
|
|
|
+ if (aNum <= 0 || bNum <= 0) {
|
|
|
+ throw new NumberFormatException("num <= 0");
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(this, "打铆颗数必须是大于 0 的整数", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ MesClient.mes_gw = gw;
|
|
|
+ MesClient.mes_gw_des = gwDes;
|
|
|
+ MesClient.mes_server_ip = serverIp;
|
|
|
+ MesClient.plcAIp = aIp;
|
|
|
+ MesClient.plcBIp = bIp;
|
|
|
+ MesClient.aSetNum = aNum;
|
|
|
+ MesClient.bSetNum = bNum;
|
|
|
+
|
|
|
+ if (!MesClient.saveMesLocalConfig()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MesClient.saveGunConfig();
|
|
|
+
|
|
|
+ setVisible(false);
|
|
|
+ dispose();
|
|
|
+ MesClient.enterAfterGunConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String nullToEmpty(String value) {
|
|
|
+ return value == null ? "" : value;
|
|
|
+ }
|
|
|
+}
|