|
@@ -9,12 +9,18 @@ import java.awt.event.ActionListener;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 启动配置页:工位信息 + 两把拉铆枪 IP / 打铆颗数(无需密码)
|
|
|
|
|
|
|
+ * 工位 + 拉铆枪配置页。
|
|
|
|
|
+ * 启动时弹出一次进入登录;登录后也可从「设置」菜单再次打开修改。
|
|
|
*/
|
|
*/
|
|
|
public class GunConfigFrame extends JFrame {
|
|
public class GunConfigFrame extends JFrame {
|
|
|
|
|
|
|
|
private static final Pattern IP_PATTERN = Pattern.compile(
|
|
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?)$");
|
|
"^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
|
|
|
|
|
+ /** 工位号:OP080 或 OP080A */
|
|
|
|
|
+ private static final Pattern OPRNO_PATTERN = Pattern.compile("^OP\\d{3}[A-Z]?$");
|
|
|
|
|
+
|
|
|
|
|
+ /** true=启动进入登录前;false=登录后修改配置 */
|
|
|
|
|
+ private final boolean startupMode;
|
|
|
|
|
|
|
|
private JTextField gwTxt;
|
|
private JTextField gwTxt;
|
|
|
private JTextField gwDesTxt;
|
|
private JTextField gwDesTxt;
|
|
@@ -25,8 +31,14 @@ public class GunConfigFrame extends JFrame {
|
|
|
private JTextField gunBNumTxt;
|
|
private JTextField gunBNumTxt;
|
|
|
|
|
|
|
|
public GunConfigFrame() {
|
|
public GunConfigFrame() {
|
|
|
- setTitle("启动配置 - " + nullToEmpty(MesClient.mes_gw) + " " + nullToEmpty(MesClient.mes_gw_des));
|
|
|
|
|
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
|
+ this(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public GunConfigFrame(boolean startupMode) {
|
|
|
|
|
+ this.startupMode = startupMode;
|
|
|
|
|
+ setTitle((startupMode ? "启动配置" : "工位/枪配置") + " - "
|
|
|
|
|
+ + nullToEmpty(MesClient.mes_gw) + " " + nullToEmpty(MesClient.mes_gw_des));
|
|
|
|
|
+ setDefaultCloseOperation(startupMode ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE);
|
|
|
setResizable(false);
|
|
setResizable(false);
|
|
|
try {
|
|
try {
|
|
|
setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
|
|
setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
|
|
@@ -38,7 +50,7 @@ public class GunConfigFrame extends JFrame {
|
|
|
root.setBackground(new Color(245, 247, 250));
|
|
root.setBackground(new Color(245, 247, 250));
|
|
|
setContentPane(root);
|
|
setContentPane(root);
|
|
|
|
|
|
|
|
- JLabel title = new JLabel("启动配置", SwingConstants.CENTER);
|
|
|
|
|
|
|
+ JLabel title = new JLabel(startupMode ? "启动配置" : "工位 / 枪配置", SwingConstants.CENTER);
|
|
|
title.setFont(new Font("微软雅黑", Font.BOLD, 28));
|
|
title.setFont(new Font("微软雅黑", Font.BOLD, 28));
|
|
|
title.setForeground(new Color(33, 37, 41));
|
|
title.setForeground(new Color(33, 37, 41));
|
|
|
root.add(title, BorderLayout.NORTH);
|
|
root.add(title, BorderLayout.NORTH);
|
|
@@ -60,7 +72,7 @@ public class GunConfigFrame extends JFrame {
|
|
|
JPanel bottom = new JPanel(new FlowLayout(FlowLayout.CENTER, 16, 0));
|
|
JPanel bottom = new JPanel(new FlowLayout(FlowLayout.CENTER, 16, 0));
|
|
|
bottom.setOpaque(false);
|
|
bottom.setOpaque(false);
|
|
|
|
|
|
|
|
- JButton enterBtn = new JButton("保存并进入登录");
|
|
|
|
|
|
|
+ JButton enterBtn = new JButton(startupMode ? "保存并进入登录" : "保存配置");
|
|
|
enterBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
enterBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
enterBtn.setPreferredSize(new Dimension(200, 44));
|
|
enterBtn.setPreferredSize(new Dimension(200, 44));
|
|
|
enterBtn.addActionListener(new ActionListener() {
|
|
enterBtn.addActionListener(new ActionListener() {
|
|
@@ -69,12 +81,27 @@ public class GunConfigFrame extends JFrame {
|
|
|
onEnter();
|
|
onEnter();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ bottom.add(enterBtn);
|
|
|
|
|
+
|
|
|
|
|
+ if (!startupMode) {
|
|
|
|
|
+ JButton cancelBtn = new JButton("取消");
|
|
|
|
|
+ cancelBtn.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
|
|
+ cancelBtn.setPreferredSize(new Dimension(120, 44));
|
|
|
|
|
+ cancelBtn.addActionListener(new ActionListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
|
+ dispose();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ bottom.add(cancelBtn);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- JLabel tip = new JLabel("工位与枪参数均可修改,保存后写入本地配置");
|
|
|
|
|
|
|
+ JLabel tip = new JLabel(startupMode
|
|
|
|
|
+ ? "工位与枪参数均可修改,保存后写入本地配置"
|
|
|
|
|
+ : "修改服务器IP/枪IP后会重新连接PLC;工位号变更后建议重连MES");
|
|
|
tip.setFont(new Font("微软雅黑", Font.PLAIN, 13));
|
|
tip.setFont(new Font("微软雅黑", Font.PLAIN, 13));
|
|
|
tip.setForeground(new Color(108, 117, 125));
|
|
tip.setForeground(new Color(108, 117, 125));
|
|
|
|
|
|
|
|
- bottom.add(enterBtn);
|
|
|
|
|
JPanel south = new JPanel(new BorderLayout());
|
|
JPanel south = new JPanel(new BorderLayout());
|
|
|
south.setOpaque(false);
|
|
south.setOpaque(false);
|
|
|
south.add(bottom, BorderLayout.CENTER);
|
|
south.add(bottom, BorderLayout.CENTER);
|
|
@@ -87,6 +114,13 @@ public class GunConfigFrame extends JFrame {
|
|
|
setBounds((d.width - width) / 2, (d.height - height) / 2 - 40, width, height);
|
|
setBounds((d.width - width) / 2, (d.height - height) / 2 - 40, width, height);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 登录后打开配置(非模态独立窗) */
|
|
|
|
|
+ public static void openForEdit() {
|
|
|
|
|
+ GunConfigFrame frame = new GunConfigFrame(false);
|
|
|
|
|
+ frame.setVisible(true);
|
|
|
|
|
+ frame.toFront();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private JPanel buildStationPanel() {
|
|
private JPanel buildStationPanel() {
|
|
|
JPanel panel = new JPanel(new GridBagLayout());
|
|
JPanel panel = new JPanel(new GridBagLayout());
|
|
|
panel.setBackground(Color.WHITE);
|
|
panel.setBackground(Color.WHITE);
|
|
@@ -116,7 +150,7 @@ public class GunConfigFrame extends JFrame {
|
|
|
lc.gridx = 0;
|
|
lc.gridx = 0;
|
|
|
lc.gridy = row;
|
|
lc.gridy = row;
|
|
|
lc.anchor = GridBagConstraints.EAST;
|
|
lc.anchor = GridBagConstraints.EAST;
|
|
|
- lc.insets = new Insets(6, 4, 6, 8);
|
|
|
|
|
|
|
+ lc.insets = new Insets(8, 4, 8, 8);
|
|
|
JLabel label = new JLabel(labelText);
|
|
JLabel label = new JLabel(labelText);
|
|
|
label.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
label.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
panel.add(label, lc);
|
|
panel.add(label, lc);
|
|
@@ -126,7 +160,7 @@ public class GunConfigFrame extends JFrame {
|
|
|
fc.gridy = row;
|
|
fc.gridy = row;
|
|
|
fc.fill = GridBagConstraints.HORIZONTAL;
|
|
fc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
fc.weightx = 1;
|
|
fc.weightx = 1;
|
|
|
- fc.insets = new Insets(6, 0, 6, 4);
|
|
|
|
|
|
|
+ fc.insets = new Insets(8, 0, 8, 4);
|
|
|
JTextField field = new JTextField(20);
|
|
JTextField field = new JTextField(20);
|
|
|
field.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
field.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
panel.add(field, fc);
|
|
panel.add(field, fc);
|
|
@@ -136,7 +170,6 @@ public class GunConfigFrame extends JFrame {
|
|
|
private JPanel buildGunPanel(String title, boolean isA) {
|
|
private JPanel buildGunPanel(String title, boolean isA) {
|
|
|
JPanel panel = new JPanel(new GridBagLayout());
|
|
JPanel panel = new JPanel(new GridBagLayout());
|
|
|
panel.setBackground(Color.WHITE);
|
|
panel.setBackground(Color.WHITE);
|
|
|
- panel.setPreferredSize(new Dimension(320, 160));
|
|
|
|
|
panel.setBorder(BorderFactory.createCompoundBorder(
|
|
panel.setBorder(BorderFactory.createCompoundBorder(
|
|
|
BorderFactory.createTitledBorder(
|
|
BorderFactory.createTitledBorder(
|
|
|
BorderFactory.createLineBorder(new Color(206, 212, 218)),
|
|
BorderFactory.createLineBorder(new Color(206, 212, 218)),
|
|
@@ -145,14 +178,14 @@ public class GunConfigFrame extends JFrame {
|
|
|
TitledBorder.TOP,
|
|
TitledBorder.TOP,
|
|
|
new Font("微软雅黑", Font.BOLD, 16),
|
|
new Font("微软雅黑", Font.BOLD, 16),
|
|
|
new Color(52, 58, 64)),
|
|
new Color(52, 58, 64)),
|
|
|
- new EmptyBorder(12, 16, 12, 16)));
|
|
|
|
|
|
|
+ new EmptyBorder(8, 12, 8, 12)));
|
|
|
|
|
|
|
|
GridBagConstraints lc = new GridBagConstraints();
|
|
GridBagConstraints lc = new GridBagConstraints();
|
|
|
lc.gridx = 0;
|
|
lc.gridx = 0;
|
|
|
lc.gridy = 0;
|
|
lc.gridy = 0;
|
|
|
lc.anchor = GridBagConstraints.EAST;
|
|
lc.anchor = GridBagConstraints.EAST;
|
|
|
lc.insets = new Insets(8, 4, 8, 8);
|
|
lc.insets = new Insets(8, 4, 8, 8);
|
|
|
- JLabel ipLabel = new JLabel("IP地址:");
|
|
|
|
|
|
|
+ JLabel ipLabel = new JLabel("IP:");
|
|
|
ipLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
ipLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
panel.add(ipLabel, lc);
|
|
panel.add(ipLabel, lc);
|
|
|
|
|
|
|
@@ -162,19 +195,28 @@ public class GunConfigFrame extends JFrame {
|
|
|
fc.fill = GridBagConstraints.HORIZONTAL;
|
|
fc.fill = GridBagConstraints.HORIZONTAL;
|
|
|
fc.weightx = 1;
|
|
fc.weightx = 1;
|
|
|
fc.insets = new Insets(8, 0, 8, 4);
|
|
fc.insets = new Insets(8, 0, 8, 4);
|
|
|
- JTextField ipTxt = new JTextField(16);
|
|
|
|
|
|
|
+ JTextField ipTxt = new JTextField(14);
|
|
|
ipTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
ipTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
panel.add(ipTxt, fc);
|
|
panel.add(ipTxt, fc);
|
|
|
|
|
|
|
|
- lc.gridy = 1;
|
|
|
|
|
- JLabel numLabel = new JLabel("打铆颗数:");
|
|
|
|
|
|
|
+ GridBagConstraints lc2 = new GridBagConstraints();
|
|
|
|
|
+ lc2.gridx = 0;
|
|
|
|
|
+ lc2.gridy = 1;
|
|
|
|
|
+ lc2.anchor = GridBagConstraints.EAST;
|
|
|
|
|
+ lc2.insets = new Insets(8, 4, 8, 8);
|
|
|
|
|
+ JLabel numLabel = new JLabel("颗数:");
|
|
|
numLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
numLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
- panel.add(numLabel, lc);
|
|
|
|
|
|
|
+ panel.add(numLabel, lc2);
|
|
|
|
|
|
|
|
- fc.gridy = 1;
|
|
|
|
|
- JTextField numTxt = new JTextField(16);
|
|
|
|
|
|
|
+ GridBagConstraints fc2 = new GridBagConstraints();
|
|
|
|
|
+ fc2.gridx = 1;
|
|
|
|
|
+ fc2.gridy = 1;
|
|
|
|
|
+ fc2.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
|
+ fc2.weightx = 1;
|
|
|
|
|
+ fc2.insets = new Insets(8, 0, 8, 4);
|
|
|
|
|
+ JTextField numTxt = new JTextField(14);
|
|
|
numTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
numTxt.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
- panel.add(numTxt, fc);
|
|
|
|
|
|
|
+ panel.add(numTxt, fc2);
|
|
|
|
|
|
|
|
if (isA) {
|
|
if (isA) {
|
|
|
gunAIpTxt = ipTxt;
|
|
gunAIpTxt = ipTxt;
|
|
@@ -191,7 +233,7 @@ public class GunConfigFrame extends JFrame {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void onEnter() {
|
|
private void onEnter() {
|
|
|
- String gw = gwTxt.getText().trim();
|
|
|
|
|
|
|
+ String gw = gwTxt.getText().trim().toUpperCase();
|
|
|
String gwDes = gwDesTxt.getText().trim();
|
|
String gwDes = gwDesTxt.getText().trim();
|
|
|
String serverIp = serverIpTxt.getText().trim();
|
|
String serverIp = serverIpTxt.getText().trim();
|
|
|
String aIp = gunAIpTxt.getText().trim();
|
|
String aIp = gunAIpTxt.getText().trim();
|
|
@@ -203,6 +245,10 @@ public class GunConfigFrame extends JFrame {
|
|
|
JOptionPane.showMessageDialog(this, "请输入工位号", "提示", JOptionPane.WARNING_MESSAGE);
|
|
JOptionPane.showMessageDialog(this, "请输入工位号", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!OPRNO_PATTERN.matcher(gw).matches()) {
|
|
|
|
|
+ JOptionPane.showMessageDialog(this, "工位号格式不正确,应为 OP080 或 OP080A", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
if (gwDes.isEmpty()) {
|
|
if (gwDes.isEmpty()) {
|
|
|
JOptionPane.showMessageDialog(this, "请输入工位名称", "提示", JOptionPane.WARNING_MESSAGE);
|
|
JOptionPane.showMessageDialog(this, "请输入工位名称", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
return;
|
|
return;
|
|
@@ -233,6 +279,8 @@ public class GunConfigFrame extends JFrame {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ boolean gunIpChanged = !aIp.equals(MesClient.plcAIp) || !bIp.equals(MesClient.plcBIp);
|
|
|
|
|
+
|
|
|
MesClient.mes_gw = gw;
|
|
MesClient.mes_gw = gw;
|
|
|
MesClient.mes_gw_des = gwDes;
|
|
MesClient.mes_gw_des = gwDes;
|
|
|
MesClient.mes_server_ip = serverIp;
|
|
MesClient.mes_server_ip = serverIp;
|
|
@@ -248,7 +296,25 @@ public class GunConfigFrame extends JFrame {
|
|
|
|
|
|
|
|
setVisible(false);
|
|
setVisible(false);
|
|
|
dispose();
|
|
dispose();
|
|
|
- MesClient.enterAfterGunConfig();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (startupMode) {
|
|
|
|
|
+ MesClient.enterAfterGunConfig();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 登录后修改:刷新标题,枪IP变了则重连PLC
|
|
|
|
|
+ if (MesClient.mesClientFrame != null) {
|
|
|
|
|
+ MesClient.mesClientFrame.setTitle("MES系统客户端:" + MesClient.mes_gw + "- " + MesClient.mes_gw_des);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (gunIpChanged) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ MesClient.initPlc();
|
|
|
|
|
+ MesClient.setMenuStatus("枪IP已更新并重连PLC", 0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ MesClient.setMenuStatus("PLC重连失败:" + e.getMessage(), -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ MesClient.setMenuStatus("配置已保存", 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static String nullToEmpty(String value) {
|
|
private static String nullToEmpty(String value) {
|