|
|
@@ -0,0 +1,148 @@
|
|
|
+package com.mes.ui;
|
|
|
+
|
|
|
+import javax.swing.*;
|
|
|
+import javax.swing.border.EmptyBorder;
|
|
|
+import javax.swing.border.TitledBorder;
|
|
|
+import java.awt.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 漏点NG点位选择对话框:B1-B8 / C1-C21 / D1 多选 + 其它原因。
|
|
|
+ */
|
|
|
+public class LeakNgPointDialog extends JDialog {
|
|
|
+
|
|
|
+ private final List<JCheckBox> pointChecks = new ArrayList<>();
|
|
|
+ private final JTextArea otherReasonArea;
|
|
|
+ private String selectedValue;
|
|
|
+ private boolean confirmed;
|
|
|
+
|
|
|
+ public LeakNgPointDialog(Frame owner) {
|
|
|
+ super(owner, "漏点NG点位", true);
|
|
|
+ setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
|
+ setResizable(true);
|
|
|
+
|
|
|
+ JPanel root = new JPanel(new BorderLayout(10, 10));
|
|
|
+ root.setBorder(new EmptyBorder(12, 12, 12, 12));
|
|
|
+
|
|
|
+ JPanel pointsPanel = new JPanel();
|
|
|
+ pointsPanel.setLayout(new BoxLayout(pointsPanel, BoxLayout.Y_AXIS));
|
|
|
+
|
|
|
+ pointsPanel.add(buildPointGroup("B点位", "B", 8));
|
|
|
+ pointsPanel.add(Box.createVerticalStrut(8));
|
|
|
+ pointsPanel.add(buildPointGroup("C点位", "C", 21));
|
|
|
+ pointsPanel.add(Box.createVerticalStrut(8));
|
|
|
+ pointsPanel.add(buildPointGroup("D点位", "D", 1));
|
|
|
+
|
|
|
+ JScrollPane pointsScroll = new JScrollPane(pointsPanel);
|
|
|
+ pointsScroll.setBorder(null);
|
|
|
+ pointsScroll.getVerticalScrollBar().setUnitIncrement(16);
|
|
|
+
|
|
|
+ JPanel otherPanel = new JPanel(new BorderLayout(6, 6));
|
|
|
+ otherPanel.setBorder(new TitledBorder("其它原因"));
|
|
|
+ otherReasonArea = new JTextArea(3, 40);
|
|
|
+ otherReasonArea.setLineWrap(true);
|
|
|
+ otherReasonArea.setWrapStyleWord(true);
|
|
|
+ otherReasonArea.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ otherPanel.add(new JScrollPane(otherReasonArea), BorderLayout.CENTER);
|
|
|
+
|
|
|
+ JPanel center = new JPanel(new BorderLayout(8, 8));
|
|
|
+ center.add(pointsScroll, BorderLayout.CENTER);
|
|
|
+ center.add(otherPanel, BorderLayout.SOUTH);
|
|
|
+
|
|
|
+ JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 8));
|
|
|
+ JButton confirmBtn = new JButton("确认");
|
|
|
+ confirmBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ confirmBtn.setPreferredSize(new Dimension(140, 48));
|
|
|
+ confirmBtn.addActionListener(e -> onConfirm());
|
|
|
+
|
|
|
+ JButton cancelBtn = new JButton("取消");
|
|
|
+ cancelBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ cancelBtn.setPreferredSize(new Dimension(140, 48));
|
|
|
+ cancelBtn.addActionListener(e -> {
|
|
|
+ confirmed = false;
|
|
|
+ selectedValue = null;
|
|
|
+ dispose();
|
|
|
+ });
|
|
|
+
|
|
|
+ buttons.add(confirmBtn);
|
|
|
+ buttons.add(cancelBtn);
|
|
|
+
|
|
|
+ JLabel tip = new JLabel("请至少勾选一个点位,或填写其它原因(可多选)");
|
|
|
+ tip.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
+ tip.setForeground(new Color(120, 120, 120));
|
|
|
+
|
|
|
+ root.add(tip, BorderLayout.NORTH);
|
|
|
+ root.add(center, BorderLayout.CENTER);
|
|
|
+ root.add(buttons, BorderLayout.SOUTH);
|
|
|
+
|
|
|
+ setContentPane(root);
|
|
|
+ setSize(780, 640);
|
|
|
+ setLocationRelativeTo(owner);
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel buildPointGroup(String title, String prefix, int count) {
|
|
|
+ JPanel group = new JPanel(new BorderLayout());
|
|
|
+ group.setBorder(new TitledBorder(title));
|
|
|
+
|
|
|
+ JPanel grid = new JPanel(new GridLayout(0, 7, 8, 6));
|
|
|
+ for (int i = 1; i <= count; i++) {
|
|
|
+ String label = prefix + i;
|
|
|
+ JCheckBox checkBox = new JCheckBox(label);
|
|
|
+ checkBox.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ checkBox.setActionCommand(label);
|
|
|
+ pointChecks.add(checkBox);
|
|
|
+ grid.add(checkBox);
|
|
|
+ }
|
|
|
+ group.add(grid, BorderLayout.CENTER);
|
|
|
+ return group;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onConfirm() {
|
|
|
+ List<String> points = new ArrayList<>();
|
|
|
+ for (JCheckBox checkBox : pointChecks) {
|
|
|
+ if (checkBox.isSelected()) {
|
|
|
+ points.add(checkBox.getActionCommand());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String other = otherReasonArea.getText() == null ? "" : otherReasonArea.getText().trim();
|
|
|
+ if (points.isEmpty() && other.isEmpty()) {
|
|
|
+ JOptionPane.showMessageDialog(this, "请至少勾选一个点位,或填写其它原因", "提示",
|
|
|
+ JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (!points.isEmpty()) {
|
|
|
+ sb.append(String.join(",", points));
|
|
|
+ }
|
|
|
+ if (!other.isEmpty()) {
|
|
|
+ if (sb.length() > 0) {
|
|
|
+ sb.append("|");
|
|
|
+ }
|
|
|
+ sb.append(other);
|
|
|
+ }
|
|
|
+ selectedValue = sb.toString();
|
|
|
+ confirmed = true;
|
|
|
+ dispose();
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isConfirmed() {
|
|
|
+ return confirmed;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getSelectedValue() {
|
|
|
+ return selectedValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 弹出对话框;确认返回拼好的漏点字符串,取消返回 null。
|
|
|
+ */
|
|
|
+ public static String showDialog(Frame owner) {
|
|
|
+ LeakNgPointDialog dialog = new LeakNgPointDialog(owner);
|
|
|
+ dialog.setVisible(true);
|
|
|
+ if (dialog.isConfirmed()) {
|
|
|
+ return dialog.getSelectedValue();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|