|
@@ -38,7 +38,7 @@ public class MesClientComponent extends JPanel {
|
|
|
public JButton resetBtn;
|
|
public JButton resetBtn;
|
|
|
// 工作状态
|
|
// 工作状态
|
|
|
// 0:未扫码,等待允许扫码信号 1:扫码成功,质量检查 2:质量合格,开始做件 3:加工完成,提交结果
|
|
// 0:未扫码,等待允许扫码信号 1:扫码成功,质量检查 2:质量合格,开始做件 3:加工完成,提交结果
|
|
|
- public static Integer work_status = 0;
|
|
|
|
|
|
|
+ public Integer work_status = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
public JLabel sllabel1;
|
|
public JLabel sllabel1;
|
|
@@ -46,42 +46,53 @@ public class MesClientComponent extends JPanel {
|
|
|
public JLabel sllabel2;
|
|
public JLabel sllabel2;
|
|
|
|
|
|
|
|
|
|
|
|
|
- // UI
|
|
|
|
|
|
|
+ // UI(布局随 workWidth、workHeight 缩放,避免写死 350×400 下的像素坐标)
|
|
|
public MesClientComponent(Oprno opno){
|
|
public MesClientComponent(Oprno opno){
|
|
|
oprnoClass = opno;
|
|
oprnoClass = opno;
|
|
|
|
|
+ int w = workWidth;
|
|
|
|
|
+ int h = workHeight;
|
|
|
this.setLayout(null);
|
|
this.setLayout(null);
|
|
|
this.setBackground(Color.WHITE);
|
|
this.setBackground(Color.WHITE);
|
|
|
- // 设置灰色边框
|
|
|
|
|
this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
|
this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
|
|
|
|
+
|
|
|
|
|
+ int margin = Math.max(8, w / 40);
|
|
|
|
|
+ int hTitle = Math.max(36, (int) Math.round(h * 0.15));
|
|
|
|
|
+ int hStatus = Math.max(32, (int) Math.round(h * 0.15));
|
|
|
|
|
+ int hSn = Math.max(32, (int) Math.round(h * 0.15));
|
|
|
|
|
+ int hBtn = Math.max(40, (int) Math.round(h * 0.15));
|
|
|
|
|
+ int hLab = Math.max(28, (int) Math.round(h * 0.125));
|
|
|
|
|
+ int gap = Math.max(4, margin / 2);
|
|
|
|
|
+
|
|
|
|
|
+ int y = 0;
|
|
|
JLabel oprnoLabel = new JLabel(oprnoClass.getOprno());
|
|
JLabel oprnoLabel = new JLabel(oprnoClass.getOprno());
|
|
|
oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
oprnoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
oprnoLabel.setForeground(Color.BLACK);
|
|
oprnoLabel.setForeground(Color.BLACK);
|
|
|
- oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, 30));
|
|
|
|
|
- oprnoLabel.setBounds(0, 0, workWidth, 60);
|
|
|
|
|
|
|
+ int titleFont = Math.max(16, Math.min(36, w / 11));
|
|
|
|
|
+ oprnoLabel.setFont(new Font("微软雅黑", Font.PLAIN, titleFont));
|
|
|
|
|
+ oprnoLabel.setBounds(0, y, w, hTitle);
|
|
|
this.add(oprnoLabel);
|
|
this.add(oprnoLabel);
|
|
|
- // 状态栏
|
|
|
|
|
|
|
+ y += hTitle;
|
|
|
|
|
+
|
|
|
status_menu = new JButton("等待上料信号");
|
|
status_menu = new JButton("等待上料信号");
|
|
|
- // 状态栏位置
|
|
|
|
|
- status_menu.setBounds(10, 60, workWidth - 20, 60);
|
|
|
|
|
- // 状态栏文字颜色
|
|
|
|
|
|
|
+ status_menu.setBounds(margin, y, w - 2 * margin, hStatus);
|
|
|
status_menu.setForeground(Color.GREEN);
|
|
status_menu.setForeground(Color.GREEN);
|
|
|
- // 为状态按钮添加点击事件监听器
|
|
|
|
|
status_menu.addActionListener(new ActionListener() {
|
|
status_menu.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- // 设置状态栏按钮字体为微软雅黑,普通样式,大小20
|
|
|
|
|
- status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
|
|
- // 设置状态栏按钮背景色为黑色
|
|
|
|
|
|
|
+ int statusFont = Math.max(14, Math.min(22, w / 16));
|
|
|
|
|
+ status_menu.setFont(new Font("微软雅黑", Font.PLAIN, statusFont));
|
|
|
status_menu.setBackground(Color.BLACK);
|
|
status_menu.setBackground(Color.BLACK);
|
|
|
- // 将状态栏按钮添加到当前面板
|
|
|
|
|
this.add(status_menu);
|
|
this.add(status_menu);
|
|
|
|
|
+ y += hStatus + gap;
|
|
|
|
|
+
|
|
|
productSn = new JTextField("");
|
|
productSn = new JTextField("");
|
|
|
productSn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
productSn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
productSn.setForeground(Color.BLACK);
|
|
productSn.setForeground(Color.BLACK);
|
|
|
- productSn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
|
|
|
|
+ int snFont = Math.max(14, Math.min(22, w / 16));
|
|
|
|
|
+ productSn.setFont(new Font("微软雅黑", Font.PLAIN, snFont));
|
|
|
productSn.setEditable(false);
|
|
productSn.setEditable(false);
|
|
|
- productSn.setBounds(10, 130, workWidth-20, 60);
|
|
|
|
|
|
|
+ productSn.setBounds(margin, y, w - 2 * margin, hSn);
|
|
|
productSn.addFocusListener(new FocusAdapter() {
|
|
productSn.addFocusListener(new FocusAdapter() {
|
|
|
@Override
|
|
@Override
|
|
|
public void focusGained(FocusEvent e) {
|
|
public void focusGained(FocusEvent e) {
|
|
@@ -89,19 +100,22 @@ public class MesClientComponent extends JPanel {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
this.add(productSn);
|
|
this.add(productSn);
|
|
|
|
|
+ y += hSn + gap;
|
|
|
|
|
|
|
|
scanBtn = new JButton("扫码");
|
|
scanBtn = new JButton("扫码");
|
|
|
final MesClientComponent thisComponent = this;
|
|
final MesClientComponent thisComponent = this;
|
|
|
scanBtn.addActionListener(new ActionListener() {
|
|
scanBtn.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
System.out.println("扫码");
|
|
System.out.println("扫码");
|
|
|
- // 获取工件码
|
|
|
|
|
thisComponent.scanBtnClick();
|
|
thisComponent.scanBtnClick();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
scanBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
scanBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
|
|
|
- scanBtn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
|
|
- scanBtn.setBounds(10, 200, workWidth/2 - 5, 60);
|
|
|
|
|
|
|
+ int btnFont = Math.max(16, Math.min(32, w / 10));
|
|
|
|
|
+ scanBtn.setFont(new Font("微软雅黑", Font.PLAIN, btnFont));
|
|
|
|
|
+ int btnGap = gap;
|
|
|
|
|
+ int btnW = (w - 2 * margin - btnGap) / 2;
|
|
|
|
|
+ scanBtn.setBounds(margin, y, btnW, hBtn);
|
|
|
this.add(scanBtn);
|
|
this.add(scanBtn);
|
|
|
|
|
|
|
|
resetBtn = new JButton("刷新");
|
|
resetBtn = new JButton("刷新");
|
|
@@ -111,41 +125,47 @@ public class MesClientComponent extends JPanel {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
resetBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
|
|
resetBtn.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
|
|
|
- resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
|
|
|
|
|
- resetBtn.setBounds(170, 200, workWidth/2 - 5, 60);
|
|
|
|
|
|
|
+ resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, btnFont));
|
|
|
|
|
+ resetBtn.setBounds(margin + btnW + btnGap, y, btnW, hBtn);
|
|
|
this.add(resetBtn);
|
|
this.add(resetBtn);
|
|
|
|
|
+ y += hBtn + gap;
|
|
|
|
|
+
|
|
|
sllabel1 = new JLabel("上料允许");
|
|
sllabel1 = new JLabel("上料允许");
|
|
|
sllabel1.setHorizontalAlignment(SwingConstants.CENTER);
|
|
sllabel1.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
sllabel1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
|
|
sllabel1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
|
|
|
sllabel1.setForeground(Color.BLACK);
|
|
sllabel1.setForeground(Color.BLACK);
|
|
|
- sllabel1.setBounds(0, 280, workWidth/2, 50);
|
|
|
|
|
|
|
+ sllabel1.setBounds(0, y, w / 2, hLab);
|
|
|
this.add(sllabel1);
|
|
this.add(sllabel1);
|
|
|
sllabel2 = new JLabel("下料允许");
|
|
sllabel2 = new JLabel("下料允许");
|
|
|
sllabel2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
sllabel2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
sllabel2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
|
|
sllabel2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
|
|
|
sllabel2.setForeground(Color.BLACK);
|
|
sllabel2.setForeground(Color.BLACK);
|
|
|
- sllabel2.setBounds(190, 280, workWidth/2, 50);
|
|
|
|
|
|
|
+ sllabel2.setBounds(w / 2, y, w - w / 2, hLab);
|
|
|
this.add(sllabel2);
|
|
this.add(sllabel2);
|
|
|
- // 加入定时任务
|
|
|
|
|
|
|
+
|
|
|
this.startOprnoTimer();
|
|
this.startOprnoTimer();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 扫码按钮
|
|
// 扫码按钮
|
|
|
public void scanBtnClick() {
|
|
public void scanBtnClick() {
|
|
|
- if (!(work_status == 0)){
|
|
|
|
|
|
|
+ if (work_status != 0) {
|
|
|
status_menu.setText("工件加工中,请勿重复扫码");
|
|
status_menu.setText("工件加工中,请勿重复扫码");
|
|
|
- }else {
|
|
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
String sn = S7PLCUtils.getSnInOprno(oprnoClass, MesClient.s7PLC);
|
|
String sn = S7PLCUtils.getSnInOprno(oprnoClass, MesClient.s7PLC);
|
|
|
- if (sn.equals("")){
|
|
|
|
|
- if (productSn.getText().isEmpty()){
|
|
|
|
|
- // 状态栏改变
|
|
|
|
|
- status_menu.setText("扫码结果为空");
|
|
|
|
|
- productSn.setText(oprnoClass.getMes_in());
|
|
|
|
|
- }
|
|
|
|
|
- }else {
|
|
|
|
|
- productSn.setText(sn);
|
|
|
|
|
- work_status = 1;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (sn == null || sn.trim().isEmpty()) {
|
|
|
|
|
+ setMenuStatus("扫码结果为空", -1);
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ sn = sn.trim();
|
|
|
|
|
+ productSn.setText(sn);
|
|
|
|
|
+ work_status = 1;
|
|
|
|
|
+ setMenuStatus("已读取工件码,等待校验", 0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("读取 PLC 工件码失败", e);
|
|
|
|
|
+ setMenuStatus("读取 PLC 失败", -1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|