|
@@ -86,6 +86,7 @@ public class MainFrame extends JFrame {
|
|
|
private JMenuItem serverIpItem;
|
|
private JMenuItem serverIpItem;
|
|
|
private JMenuItem featuresItem;
|
|
private JMenuItem featuresItem;
|
|
|
private JMenuItem deviceInfoUiItem;
|
|
private JMenuItem deviceInfoUiItem;
|
|
|
|
|
+ private JMenuItem prefixWhitelistItem;
|
|
|
// 界面布局子菜单(mes123解锁后显示)
|
|
// 界面布局子菜单(mes123解锁后显示)
|
|
|
private JMenu layoutMenu;
|
|
private JMenu layoutMenu;
|
|
|
// 手动提交子菜单(解锁后显示;若勾选"始终显示"则不受解锁控制)
|
|
// 手动提交子菜单(解锁后显示;若勾选"始终显示"则不受解锁控制)
|
|
@@ -273,6 +274,12 @@ public class MainFrame extends JFrame {
|
|
|
deviceInfoUiItem.addActionListener(e -> showDeviceInfoUiDialog());
|
|
deviceInfoUiItem.addActionListener(e -> showDeviceInfoUiDialog());
|
|
|
projectDeviceMenu.add(deviceInfoUiItem);
|
|
projectDeviceMenu.add(deviceInfoUiItem);
|
|
|
|
|
|
|
|
|
|
+ prefixWhitelistItem = new JMenuItem("前缀白名单");
|
|
|
|
|
+ prefixWhitelistItem.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/resources/image/bg/menu_setting.png"))));
|
|
|
|
|
+ prefixWhitelistItem.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
|
|
+ prefixWhitelistItem.addActionListener(e -> showPrefixWhitelistDialog());
|
|
|
|
|
+ projectDeviceMenu.add(prefixWhitelistItem);
|
|
|
|
|
+
|
|
|
refreshMenuTexts(); // 首次填充显示当前值
|
|
refreshMenuTexts(); // 首次填充显示当前值
|
|
|
|
|
|
|
|
// ========== 子菜单:界面布局(默认隐藏,密码解锁后显示) ==========
|
|
// ========== 子菜单:界面布局(默认隐藏,密码解锁后显示) ==========
|
|
@@ -1411,6 +1418,155 @@ public class MainFrame extends JFrame {
|
|
|
"切换成功", JOptionPane.INFORMATION_MESSAGE);
|
|
"切换成功", JOptionPane.INFORMATION_MESSAGE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ========== 前缀白名单 ==========
|
|
|
|
|
+
|
|
|
|
|
+ /** 内置前缀在列表中的标记后缀,带此后缀的项不可删除 */
|
|
|
|
|
+ private static final String BUILTIN_TAG = " (内置)";
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 前缀白名单里的一个类别(工件码/冷板码/底护板码)
|
|
|
|
|
+ * 内置前缀置顶回显且不可删除,用户追加项可增删
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final class PrefixSection {
|
|
|
|
|
+ private final com.mes.core.ProjectConfigManager.PrefixKind kind;
|
|
|
|
|
+ private final String builtin;
|
|
|
|
|
+ private final DefaultListModel<String> model = new DefaultListModel<>();
|
|
|
|
|
+ private final JPanel panel = new JPanel(new BorderLayout(4, 4));
|
|
|
|
|
+
|
|
|
|
|
+ PrefixSection(String title,
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind kind,
|
|
|
|
|
+ com.mes.core.ProjectConfigManager pc,
|
|
|
|
|
+ Component owner) {
|
|
|
|
|
+ this.kind = kind;
|
|
|
|
|
+ this.builtin = pc.getBuiltinPrefix(kind);
|
|
|
|
|
+
|
|
|
|
|
+ if (!builtin.isEmpty()) model.addElement(builtin + BUILTIN_TAG);
|
|
|
|
|
+ for (String s : pc.getExtraPrefixes(kind)) model.addElement(s);
|
|
|
|
|
+
|
|
|
|
|
+ JList<String> list = new JList<>(model);
|
|
|
|
|
+ list.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
|
|
+ JScrollPane sp = new JScrollPane(list);
|
|
|
|
|
+ sp.setPreferredSize(new Dimension(190, 150));
|
|
|
|
|
+
|
|
|
|
|
+ JButton addBtn = new JButton("添加");
|
|
|
|
|
+ addBtn.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
|
|
+ addBtn.addActionListener(e -> {
|
|
|
|
|
+ String input = JOptionPane.showInputDialog(owner, "输入新的" + title + ":");
|
|
|
|
|
+ if (input == null) return;
|
|
|
|
|
+ String t = input.trim();
|
|
|
|
|
+ if (t.isEmpty()) return;
|
|
|
|
|
+ if (contains(t)) {
|
|
|
|
|
+ JOptionPane.showMessageDialog(owner, "该前缀已存在:" + t,
|
|
|
|
|
+ "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ model.addElement(t);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ JButton delBtn = new JButton("删除");
|
|
|
|
|
+ delBtn.setFont(new Font("微软雅黑", Font.PLAIN, 15));
|
|
|
|
|
+ delBtn.addActionListener(e -> {
|
|
|
|
|
+ int idx = list.getSelectedIndex();
|
|
|
|
|
+ if (idx < 0) return;
|
|
|
|
|
+ if (model.getElementAt(idx).endsWith(BUILTIN_TAG)) {
|
|
|
|
|
+ JOptionPane.showMessageDialog(owner, "内置前缀由项目决定,不可删除",
|
|
|
|
|
+ "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ model.remove(idx);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ JPanel btns = new JPanel();
|
|
|
|
|
+ btns.add(addBtn);
|
|
|
|
|
+ btns.add(delBtn);
|
|
|
|
|
+
|
|
|
|
|
+ JLabel head = new JLabel(title);
|
|
|
|
|
+ head.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
|
|
|
|
+ panel.add(head, BorderLayout.NORTH);
|
|
|
|
|
+ panel.add(sp, BorderLayout.CENTER);
|
|
|
|
|
+ panel.add(btns, BorderLayout.SOUTH);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 是否已包含该前缀(内置项去掉标记后比较) */
|
|
|
|
|
+ private boolean contains(String value) {
|
|
|
|
|
+ if (value.equals(builtin)) return true;
|
|
|
|
|
+ for (int i = 0; i < model.size(); i++) {
|
|
|
|
|
+ String v = model.getElementAt(i);
|
|
|
|
|
+ if (v.endsWith(BUILTIN_TAG)) continue;
|
|
|
|
|
+ if (v.equals(value)) return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JPanel getPanel() { return panel; }
|
|
|
|
|
+
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind getKind() { return kind; }
|
|
|
|
|
+
|
|
|
|
|
+ /** 用户追加部分(不含内置) */
|
|
|
|
|
+ List<String> collectExtras() {
|
|
|
|
|
+ List<String> out = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < model.size(); i++) {
|
|
|
|
|
+ String v = model.getElementAt(i);
|
|
|
|
|
+ if (v.endsWith(BUILTIN_TAG)) continue;
|
|
|
|
|
+ out.add(v);
|
|
|
|
|
+ }
|
|
|
|
|
+ return out;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 弹出前缀白名单配置对话框(工件码/冷板码/底护板码三类)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void showPrefixWhitelistDialog() {
|
|
|
|
|
+ com.mes.core.ProjectConfigManager pc = com.mes.core.ProjectConfigManager.getInstance();
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.Project cur = pc.getCurrentProject();
|
|
|
|
|
+
|
|
|
|
|
+ List<PrefixSection> sections = new ArrayList<>();
|
|
|
|
|
+ sections.add(new PrefixSection("工件码前缀",
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind.PRODUCT, pc, this));
|
|
|
|
|
+ sections.add(new PrefixSection("冷板码前缀",
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind.COLD_PLATE, pc, this));
|
|
|
|
|
+ sections.add(new PrefixSection("底护板码前缀",
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind.BOTTOM_PLATE, pc, this));
|
|
|
|
|
+
|
|
|
|
|
+ JPanel grid = new JPanel(new GridLayout(1, 3, 10, 0));
|
|
|
|
|
+ for (PrefixSection s : sections) grid.add(s.getPanel());
|
|
|
|
|
+
|
|
|
|
|
+ JLabel head = new JLabel("当前项目:" + (cur != null ? cur.getDisplay() : "?"));
|
|
|
|
|
+ head.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
|
|
+ JLabel hint = new JLabel("<html><font color='gray' size='3'>"
|
|
|
|
|
+ + "内置前缀由当前项目决定,只回显不可删除;扫码时命中任一前缀即通过。<br>"
|
|
|
|
|
+ + "某一类全部为空时,回退到 station.yaml 里配置的前缀。</font></html>");
|
|
|
|
|
+
|
|
|
|
|
+ JPanel root = new JPanel(new BorderLayout(5, 8));
|
|
|
|
|
+ root.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10));
|
|
|
|
|
+ root.add(head, BorderLayout.NORTH);
|
|
|
|
|
+ root.add(grid, BorderLayout.CENTER);
|
|
|
|
|
+ root.add(hint, BorderLayout.SOUTH);
|
|
|
|
|
+
|
|
|
|
|
+ int result = JOptionPane.showConfirmDialog(this, root,
|
|
|
|
|
+ "前缀白名单", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
|
|
+ if (result != JOptionPane.OK_OPTION) return;
|
|
|
|
|
+
|
|
|
|
|
+ for (PrefixSection s : sections) {
|
|
|
|
|
+ pc.setExtraPrefixes(s.getKind(), s.collectExtras());
|
|
|
|
|
+ }
|
|
|
|
|
+ refreshMenuTexts();
|
|
|
|
|
+
|
|
|
|
|
+ StringBuilder sb = new StringBuilder("前缀白名单已保存,下次扫码生效\n\n");
|
|
|
|
|
+ sb.append("工件码:").append(joinOrNone(pc.getEffectivePrefixes(
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind.PRODUCT))).append('\n');
|
|
|
|
|
+ sb.append("冷板码:").append(joinOrNone(pc.getEffectivePrefixes(
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind.COLD_PLATE))).append('\n');
|
|
|
|
|
+ sb.append("底护板码:").append(joinOrNone(pc.getEffectivePrefixes(
|
|
|
|
|
+ com.mes.core.ProjectConfigManager.PrefixKind.BOTTOM_PLATE)));
|
|
|
|
|
+ JOptionPane.showMessageDialog(this, sb.toString(), "保存成功", JOptionPane.INFORMATION_MESSAGE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String joinOrNone(List<String> list) {
|
|
|
|
|
+ return (list == null || list.isEmpty()) ? "(不校验/走yaml)" : String.join(" / ", list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 弹出修改拉铆设备IP对话框
|
|
* 弹出修改拉铆设备IP对话框
|
|
|
*/
|
|
*/
|