| | |
| | | package zhuye; |
| | | |
| | | import javax.swing.BorderFactory; |
| | | import javax.swing.JButton; |
| | | import javax.swing.JDialog; |
| | | import javax.swing.JOptionPane; |
| | | import javax.swing.JLabel; |
| | | import javax.swing.JPanel; |
| | | import javax.swing.SwingUtilities; |
| | | import javax.swing.WindowConstants; |
| | | import java.awt.BorderLayout; |
| | | import java.awt.Color; |
| | | import java.awt.Component; |
| | | import java.awt.Dimension; |
| | | import java.awt.FlowLayout; |
| | | import java.awt.Dialog; |
| | | import java.awt.Toolkit; |
| | | import java.awt.Window; |
| | | |
| | |
| | | } |
| | | |
| | | private static void showSelfCheckDialog(Component anchorComponent, Runnable onSelfCheckConfirmed) { |
| | | Component parent = resolveDialogParent(anchorComponent); |
| | | Object[] options = {"立即自检", "取消"}; |
| | | String message = "<html>割草前请先完成对割草机的自检操作。<br>遥控割草机向前开约2米,然后原地转圈完成自检功能。</html>"; |
| | | Component parent = resolveDialogParent(anchorComponent); |
| | | Window owner = parent instanceof Window |
| | | ? (Window) parent |
| | | : SwingUtilities.getWindowAncestor(parent); |
| | | |
| | | JOptionPane optionPane = new JOptionPane( |
| | | message, |
| | | JOptionPane.INFORMATION_MESSAGE, |
| | | JOptionPane.DEFAULT_OPTION, |
| | | null, |
| | | options, |
| | | options[0]); |
| | | final JDialog dialog = owner != null |
| | | ? new JDialog(owner, "自检提示", Dialog.ModalityType.APPLICATION_MODAL) |
| | | : new JDialog((Window) null, "自检提示", Dialog.ModalityType.APPLICATION_MODAL); |
| | | dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
| | | dialog.setResizable(false); |
| | | |
| | | JDialog dialog = optionPane.createDialog(parent, "自检提示"); |
| | | dialog.pack(); |
| | | applyTargetWidth(anchorComponent, dialog); |
| | | dialog.setLocationRelativeTo(parent instanceof Component ? (Component) parent : null); |
| | | dialog.setVisible(true); |
| | | String message = "<html>操作割草前请先完成对割草机的自检操作。<br>遥控割草机向前开约2米,然后原地转圈完成自检功能。</html>"; |
| | | |
| | | Object selectedValue = optionPane.getValue(); |
| | | JPanel contentPanel = new JPanel(new BorderLayout(0, 20)); |
| | | contentPanel.setBorder(BorderFactory.createEmptyBorder(24, 24, 24, 24)); |
| | | contentPanel.setBackground(Color.WHITE); |
| | | |
| | | JLabel messageLabel = new JLabel(message); |
| | | messageLabel.setForeground(new Color(60, 60, 60)); |
| | | contentPanel.add(messageLabel, BorderLayout.CENTER); |
| | | |
| | | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 18, 0)); |
| | | buttonPanel.setOpaque(false); |
| | | |
| | | JButton confirmButton = buttonset.createStyledButton("立即自检", new Color(46, 139, 87)); |
| | | JButton cancelButton = buttonset.createStyledButton("取消", new Color(128, 128, 128)); |
| | | |
| | | final boolean[] confirmedHolder = {false}; |
| | | |
| | | confirmButton.addActionListener(e -> { |
| | | confirmedHolder[0] = true; |
| | | dialog.dispose(); |
| | | }); |
| | | cancelButton.addActionListener(e -> { |
| | | confirmedHolder[0] = false; |
| | | dialog.dispose(); |
| | | }); |
| | | |
| | | buttonPanel.add(confirmButton); |
| | | buttonPanel.add(cancelButton); |
| | | |
| | | contentPanel.add(buttonPanel, BorderLayout.SOUTH); |
| | | |
| | | dialog.setContentPane(contentPanel); |
| | | dialog.pack(); |
| | | applyTargetWidth(anchorComponent, dialog); |
| | | dialog.setLocationRelativeTo(owner); |
| | | dialog.setVisible(true); |
| | | dialog.dispose(); |
| | | |
| | | boolean confirmed = options[0].equals(selectedValue); |
| | | boolean confirmed = confirmedHolder[0]; |
| | | if (confirmed) { |
| | | selfCheckCompleted = true; |
| | | if (onSelfCheckConfirmed != null) { |