package xitongshezhi;
|
|
import javax.swing.*;
|
import javax.swing.border.EmptyBorder;
|
|
import chushihua.Chushihua;
|
import chushihua.lunxun;
|
|
import java.awt.*;
|
import java.awt.image.BufferedImage;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
public class ConfigSet extends JDialog {
|
private static final long serialVersionUID = 1L;
|
|
// 屏幕尺寸常量 - 适配7寸竖屏
|
private static final int DIALOG_WIDTH = 580;
|
private static final int DIALOG_HEIGHT = 900;
|
// 新增:记录进入设置页面前的轮询状态
|
private boolean wasPollingRunning = false;
|
private boolean wasPollingPaused = false;
|
|
// 颜色常量
|
private static final Color PRIMARY_COLOR = new Color(52, 152, 219);
|
private static final Color SECONDARY_COLOR = new Color(46, 204, 113);
|
private static final Color DANGER_COLOR = new Color(231, 76, 60);
|
private static final Color DARK_COLOR = new Color(15, 28, 48);
|
private static final Color DARK_LIGHT_COLOR = new Color(26, 43, 68);
|
private static final Color TEXT_COLOR = new Color(224, 224, 224);
|
private static final Color TEXT_LIGHT_COLOR = new Color(160, 200, 255);
|
private static final Color CARD_BG_COLOR = new Color(30, 60, 114, 255); // 改为不透明
|
|
// 优化的颜色常量
|
private static final Color CARD_HOVER_COLOR = new Color(40, 70, 124, 255); // 改为不透明
|
|
// 图标缓存
|
private static final Map<String, ImageIcon> ICON_CACHE = new HashMap<>();
|
|
// 菜单项列表
|
private List<JPanel> menuItems;
|
|
// 配置管理器
|
private Chushihua configManager;
|
|
// 可重用的对话框
|
private JDialog faceRegisterDialog;
|
private JDialog faceManagementDialog;
|
private JDialog slotManagementDialog;
|
|
// 共享的事件监听器
|
private final MenuItemListener menuItemListener;
|
|
public ConfigSet(JFrame parent) {
|
super(parent, "设置", true);
|
configManager = Chushihua.getInstance();
|
menuItemListener = new MenuItemListener();
|
// 记录进入设置页面前的轮询状态
|
recordPollingStateBeforeEntering();
|
initializeUI();
|
// 进入设置页面时暂停轮询
|
pausePollingWhenEntering();
|
}
|
|
/**
|
* 记录进入设置页面前的轮询状态
|
*/
|
private void recordPollingStateBeforeEntering() {
|
wasPollingRunning = lunxun.isPolling();
|
wasPollingPaused = lunxun.isPaused();
|
}
|
|
/**
|
* 进入设置页面时暂停轮询
|
*/
|
private void pausePollingWhenEntering() {
|
if (lunxun.isPolling() && !lunxun.isPaused()) {
|
boolean paused = lunxun.setPollingPaused(true);
|
if (paused) {
|
//System.out.println("进入设置页面,轮询已暂停");
|
} else {
|
System.err.println("进入设置页面,暂停轮询失败");
|
}
|
}
|
}
|
|
|
/**
|
* 退出设置页面时恢复轮询
|
*/
|
private void resumePollingWhenExiting() {
|
// 只有进入设置页面时轮询是运行状态且未被暂停,才恢复轮询
|
if (wasPollingRunning && !wasPollingPaused) {
|
if (lunxun.isPolling() && lunxun.isPaused()) {
|
// 恢复前检查串口连接状态
|
if (lunxun.checkSerialConnection()) {
|
boolean resumed = lunxun.setPollingPaused(false);
|
if (resumed) {
|
//System.out.println("退出设置页面,轮询已恢复");
|
} else {
|
System.err.println("退出设置页面,恢复轮询失败");
|
}
|
} else {
|
System.err.println("退出设置页面,串口未连接,保持轮询暂停状态");
|
}
|
}
|
} else {
|
//System.out.println("退出设置页面,保持原有轮询状态 - 运行: " + wasPollingRunning + ", 暂停: " + wasPollingPaused);
|
}
|
}
|
|
private void initializeUI() {
|
setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
setLocationRelativeTo(getParent());
|
setResizable(false);
|
|
// 设置深色主题
|
try {
|
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
// 创建主面板
|
JPanel mainPanel = new JPanel();
|
mainPanel.setLayout(new BorderLayout());
|
mainPanel.setBackground(DARK_COLOR);
|
mainPanel.setOpaque(true); // 确保不透明
|
mainPanel.setBorder(new EmptyBorder(15, 15, 15, 15));
|
|
// 添加设置菜单面板
|
mainPanel.add(createHeaderPanel(), BorderLayout.NORTH);
|
mainPanel.add(createMenuGridPanel(), BorderLayout.CENTER);
|
|
getContentPane().add(mainPanel);
|
}
|
|
private JPanel createHeaderPanel() {
|
JPanel headerPanel = new JPanel(new BorderLayout());
|
headerPanel.setOpaque(true); // 改为不透明
|
headerPanel.setBackground(DARK_COLOR); // 设置背景色
|
headerPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(52, 152, 219, 77)));
|
|
// 标题
|
JLabel titleLabel = new JLabel("系统设置");
|
titleLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 22));
|
titleLabel.setForeground(TEXT_COLOR);
|
titleLabel.setIcon(getCachedIcon("⚙️", 24));
|
|
// 关闭按钮
|
JButton closeButton = new JButton("关闭");
|
closeButton.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
closeButton.setBackground(DANGER_COLOR);
|
closeButton.setForeground(Color.WHITE);
|
closeButton.setOpaque(true); // 确保不透明
|
closeButton.setFocusPainted(false);
|
closeButton.setBorder(BorderFactory.createEmptyBorder(10, 18, 10, 18));
|
closeButton.setIcon(getCachedIcon("✕", 16));
|
closeButton.addActionListener(e -> dispose());
|
|
// 添加悬停效果
|
closeButton.addMouseListener(new java.awt.event.MouseAdapter() {
|
public void mouseEntered(java.awt.event.MouseEvent evt) {
|
closeButton.setBackground(brighterColor(DANGER_COLOR));
|
}
|
|
public void mouseExited(java.awt.event.MouseEvent evt) {
|
closeButton.setBackground(DANGER_COLOR);
|
}
|
});
|
|
JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
titlePanel.setOpaque(true); // 改为不透明
|
titlePanel.setBackground(DARK_COLOR); // 设置背景色
|
titlePanel.add(titleLabel);
|
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
buttonPanel.setOpaque(true); // 改为不透明
|
buttonPanel.setBackground(DARK_COLOR); // 设置背景色
|
buttonPanel.add(closeButton);
|
|
headerPanel.add(titlePanel, BorderLayout.WEST);
|
headerPanel.add(buttonPanel, BorderLayout.EAST);
|
|
// 添加装饰线
|
JPanel decorLine = new JPanel();
|
decorLine.setBackground(PRIMARY_COLOR);
|
decorLine.setOpaque(true); // 确保不透明
|
decorLine.setPreferredSize(new Dimension(120, 3));
|
|
JPanel headerWrapper = new JPanel(new BorderLayout());
|
headerWrapper.setOpaque(true); // 改为不透明
|
headerWrapper.setBackground(DARK_COLOR); // 设置背景色
|
headerWrapper.add(headerPanel, BorderLayout.CENTER);
|
headerWrapper.add(decorLine, BorderLayout.SOUTH);
|
|
return headerWrapper;
|
}
|
|
private JPanel createMenuGridPanel() {
|
JPanel menuPanel = new JPanel(new GridLayout(5, 2, 12, 12));
|
menuPanel.setOpaque(true); // 改为不透明
|
menuPanel.setBackground(DARK_COLOR); // 设置背景色
|
menuPanel.setBorder(new EmptyBorder(20, 0, 0, 0));
|
|
menuItems = new ArrayList<>();
|
|
// 创建菜单项
|
String[][] menuData = {
|
{"快速取卡", "⚡", "一键快速取卡操作"},
|
{"人脸注册", "👤", "注册新用户人脸信息"},
|
{"人脸管理", "👥", "管理已注册人脸数据"},
|
{"卡槽管理", "📦", "查看和管理卡槽状态"},
|
{"历史记录", "📊", "查看系统操作记录"},
|
{"参数设置", "⚙️", "调整系统运行参数"},
|
{"系统调试", "🛠️", "发卡机串口调试"},
|
{"密码管理", "🔑", "修改系统访问密码"},
|
{"版本管理", "🔄", "查看和更新系统版本"},
|
{"语言设置", "🌐", "切换系统显示语言"}
|
};
|
|
for (String[] itemData : menuData) {
|
JPanel menuItem = createMenuItem(itemData[0], itemData[1], itemData[2]);
|
menuItems.add(menuItem);
|
menuPanel.add(menuItem);
|
}
|
|
// 包装在滚动面板中
|
JScrollPane scrollPane = new JScrollPane(menuPanel);
|
scrollPane.setBorder(BorderFactory.createEmptyBorder());
|
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
|
scrollPane.setOpaque(true); // 确保不透明
|
scrollPane.getViewport().setOpaque(true); // 确保不透明
|
scrollPane.getViewport().setBackground(DARK_COLOR); // 设置背景色
|
|
JPanel wrapper = new JPanel(new BorderLayout());
|
wrapper.setOpaque(true); // 改为不透明
|
wrapper.setBackground(DARK_COLOR); // 设置背景色
|
wrapper.add(scrollPane, BorderLayout.CENTER);
|
|
return wrapper;
|
}
|
|
private JPanel createMenuItem(String title, String icon, String description) {
|
JPanel menuItem = new JPanel();
|
menuItem.setLayout(new BorderLayout());
|
menuItem.setBackground(CARD_BG_COLOR);
|
menuItem.setOpaque(true); // 确保不透明
|
menuItem.setBorder(BorderFactory.createEmptyBorder(18, 12, 18, 12));
|
menuItem.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
|
// 添加鼠标悬停效果
|
menuItem.addMouseListener(new java.awt.event.MouseAdapter() {
|
public void mouseEntered(java.awt.event.MouseEvent evt) {
|
menuItem.setBackground(CARD_HOVER_COLOR);
|
menuItem.setOpaque(true); // 确保不透明
|
menuItem.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
|
BorderFactory.createEmptyBorder(16, 10, 16, 10)
|
));
|
}
|
|
public void mouseExited(java.awt.event.MouseEvent evt) {
|
menuItem.setBackground(CARD_BG_COLOR);
|
menuItem.setOpaque(true); // 确保不透明
|
menuItem.setBorder(BorderFactory.createEmptyBorder(18, 12, 18, 12));
|
}
|
});
|
|
// 图标
|
JLabel iconLabel = new JLabel(icon);
|
iconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 28));
|
iconLabel.setForeground(PRIMARY_COLOR);
|
iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
iconLabel.setOpaque(false); // 标签通常透明
|
|
// 标题
|
JLabel titleLabel = new JLabel(title);
|
titleLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
titleLabel.setForeground(TEXT_COLOR);
|
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
titleLabel.setOpaque(false); // 标签通常透明
|
|
// 描述
|
JLabel descLabel = new JLabel(description);
|
descLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 10));
|
descLabel.setForeground(TEXT_LIGHT_COLOR);
|
descLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
descLabel.setOpaque(false); // 标签通常透明
|
|
// 内容面板
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
contentPanel.setOpaque(false); // 内容面板透明以显示菜单项背景
|
contentPanel.add(iconLabel);
|
contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
|
contentPanel.add(titleLabel);
|
contentPanel.add(Box.createRigidArea(new Dimension(0, 4)));
|
contentPanel.add(descLabel);
|
|
menuItem.add(contentPanel, BorderLayout.CENTER);
|
|
// 使用共享的监听器
|
menuItem.addMouseListener(menuItemListener);
|
|
return menuItem;
|
}
|
|
// 共享的菜单项监听器
|
private class MenuItemListener extends java.awt.event.MouseAdapter {
|
@Override
|
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
JPanel source = (JPanel) evt.getSource();
|
// 从菜单项中获取标题
|
Component[] components = ((JPanel)source.getComponent(0)).getComponents();
|
for (Component comp : components) {
|
if (comp instanceof JLabel) {
|
JLabel label = (JLabel) comp;
|
// 找到标题标签(较大的字体)
|
if (label.getFont().getSize() == 14 && label.getFont().getStyle() == Font.BOLD) {
|
handleMenuItemClick(label.getText());
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
private void handleMenuItemClick(String menuTitle) {
|
switch (menuTitle) {
|
case "快速取卡":
|
showQuickPickupDialog();
|
break;
|
case "人脸注册":
|
showFaceRegisterDialog();
|
break;
|
case "人脸管理":
|
showFaceManagementDialog();
|
break;
|
case "卡槽管理":
|
kacaoguanli.showSlotManagementDialog((JFrame) getParent());
|
break;
|
case "历史记录":
|
lishijilu.showHistoryDialog((JFrame) getParent());
|
break;
|
case "参数设置":
|
canshushezhi.showSettingsDialog((JFrame) getParent());
|
break;
|
case "系统调试":
|
showSystemDebugDialog();
|
break;
|
case "密码管理":
|
mimaguanli.showPasswordManagementDialog((JFrame) getParent(), configManager);
|
break;
|
case "版本管理":
|
banbenguanli.showVersionManagementDialog((JFrame) getParent());
|
break;
|
case "语言设置":
|
showMessageDialog("语言设置不可选择");
|
break;
|
}
|
}
|
|
private void showQuickPickupDialog() {
|
kuaisuquka.showQuickPickupDialog((JFrame) getParent());
|
}
|
|
private void showFaceRegisterDialog() {
|
if (faceRegisterDialog == null) {
|
createFaceRegisterDialog();
|
}
|
faceRegisterDialog.setVisible(true);
|
}
|
|
private void createFaceRegisterDialog() {
|
faceRegisterDialog = new JDialog(this, "人脸注册", true);
|
faceRegisterDialog.setSize(450, 320);
|
faceRegisterDialog.setLocationRelativeTo(this);
|
faceRegisterDialog.setResizable(false);
|
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(new BorderLayout());
|
contentPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
contentPanel.setBackground(DARK_LIGHT_COLOR);
|
contentPanel.setOpaque(true); // 确保不透明
|
|
JLabel infoLabel = new JLabel("请将人脸对准摄像头,并填写用户信息");
|
infoLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
infoLabel.setForeground(TEXT_COLOR);
|
infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
infoLabel.setOpaque(false); // 标签透明
|
|
// 表单面板
|
JPanel formPanel = new JPanel(new GridLayout(2, 2, 10, 10));
|
formPanel.setOpaque(true); // 改为不透明
|
formPanel.setBackground(DARK_LIGHT_COLOR); // 设置背景色
|
formPanel.setBorder(new EmptyBorder(15, 0, 15, 0));
|
|
JLabel nameLabel = new JLabel("姓名:");
|
nameLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
nameLabel.setForeground(TEXT_COLOR);
|
nameLabel.setOpaque(false); // 标签透明
|
|
JTextField nameField = new JTextField();
|
nameField.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
nameField.setOpaque(true); // 文本框不透明
|
|
JLabel idLabel = new JLabel("工号:");
|
idLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
idLabel.setForeground(TEXT_COLOR);
|
idLabel.setOpaque(false); // 标签透明
|
|
JTextField idField = new JTextField();
|
idField.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
idField.setOpaque(true); // 文本框不透明
|
|
formPanel.add(nameLabel);
|
formPanel.add(nameField);
|
formPanel.add(idLabel);
|
formPanel.add(idField);
|
|
// 按钮面板
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
|
buttonPanel.setOpaque(true); // 改为不透明
|
buttonPanel.setBackground(DARK_LIGHT_COLOR); // 设置背景色
|
|
JButton registerButton = createDialogButton("开始注册", SECONDARY_COLOR);
|
registerButton.addActionListener(e -> {
|
String name = nameField.getText();
|
String id = idField.getText();
|
|
if (name.isEmpty() || id.isEmpty()) {
|
JOptionPane.showMessageDialog(faceRegisterDialog, "请填写姓名和工号", "错误", JOptionPane.ERROR_MESSAGE);
|
return;
|
}
|
|
JOptionPane.showMessageDialog(faceRegisterDialog,
|
"开始为 " + name + " (" + id + ") 注册人脸,请保持面对摄像头",
|
"提示", JOptionPane.INFORMATION_MESSAGE);
|
faceRegisterDialog.setVisible(false);
|
});
|
|
JButton cancelButton = createDialogButton("取消", DANGER_COLOR);
|
cancelButton.addActionListener(e -> faceRegisterDialog.setVisible(false));
|
|
buttonPanel.add(registerButton);
|
buttonPanel.add(cancelButton);
|
|
contentPanel.add(infoLabel, BorderLayout.NORTH);
|
contentPanel.add(formPanel, BorderLayout.CENTER);
|
contentPanel.add(buttonPanel, BorderLayout.SOUTH);
|
|
faceRegisterDialog.add(contentPanel);
|
}
|
|
private void showFaceManagementDialog() {
|
if (faceManagementDialog == null) {
|
createFaceManagementDialog();
|
}
|
faceManagementDialog.setVisible(true);
|
}
|
|
private void createFaceManagementDialog() {
|
faceManagementDialog = new JDialog(this, "人脸管理", true);
|
faceManagementDialog.setSize(500, 400);
|
faceManagementDialog.setLocationRelativeTo(this);
|
faceManagementDialog.setResizable(false);
|
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(new BorderLayout());
|
contentPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
contentPanel.setBackground(DARK_LIGHT_COLOR);
|
contentPanel.setOpaque(true); // 确保不透明
|
|
JLabel infoLabel = new JLabel("已注册人脸信息列表");
|
infoLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
infoLabel.setForeground(TEXT_COLOR);
|
infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
infoLabel.setOpaque(false); // 标签透明
|
|
// 人脸列表
|
String[] columnNames = {"姓名", "工号", "注册日期", "状态"};
|
Object[][] data = {
|
{"张三", "001", "2023-10-15", "已激活"},
|
{"李四", "002", "2023-10-16", "已激活"},
|
{"王五", "003", "2023-10-17", "未激活"},
|
{"赵六", "004", "2023-10-18", "已激活"}
|
};
|
|
JTable faceTable = new JTable(data, columnNames);
|
faceTable.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12));
|
faceTable.setRowHeight(30);
|
faceTable.setEnabled(false); // 只读
|
faceTable.setOpaque(true); // 确保不透明
|
|
JScrollPane scrollPane = new JScrollPane(faceTable);
|
scrollPane.setBorder(BorderFactory.createLineBorder(new Color(255, 255, 255, 50)));
|
scrollPane.setOpaque(true); // 确保不透明
|
scrollPane.getViewport().setOpaque(true); // 确保不透明
|
scrollPane.getViewport().setBackground(Color.WHITE); // 设置表格背景色
|
|
// 按钮面板
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 0));
|
buttonPanel.setOpaque(true); // 改为不透明
|
buttonPanel.setBackground(DARK_LIGHT_COLOR); // 设置背景色
|
buttonPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
|
|
JButton refreshButton = createDialogButton("刷新", PRIMARY_COLOR);
|
refreshButton.addActionListener(e ->
|
showMessageDialog("人脸列表已刷新"));
|
|
JButton closeButton = createDialogButton("关闭", DANGER_COLOR);
|
closeButton.addActionListener(e -> faceManagementDialog.setVisible(false));
|
|
buttonPanel.add(refreshButton);
|
buttonPanel.add(closeButton);
|
|
contentPanel.add(infoLabel, BorderLayout.NORTH);
|
contentPanel.add(scrollPane, BorderLayout.CENTER);
|
contentPanel.add(buttonPanel, BorderLayout.SOUTH);
|
|
faceManagementDialog.add(contentPanel);
|
}
|
|
|
|
private JButton createDialogButton(String text, Color bgColor) {
|
JButton button = new JButton(text);
|
button.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
|
button.setBackground(bgColor);
|
button.setOpaque(true); // 确保不透明
|
button.setForeground(Color.WHITE);
|
button.setFocusPainted(false);
|
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
|
|
// 添加悬停效果
|
button.addMouseListener(new java.awt.event.MouseAdapter() {
|
public void mouseEntered(java.awt.event.MouseEvent evt) {
|
button.setBackground(brighterColor(bgColor));
|
button.setOpaque(true); // 确保不透明
|
}
|
|
public void mouseExited(java.awt.event.MouseEvent evt) {
|
button.setBackground(bgColor);
|
button.setOpaque(true); // 确保不透明
|
}
|
});
|
|
return button;
|
}
|
|
private void showMessageDialog(String message) {
|
JOptionPane.showMessageDialog(this, message, "提示", JOptionPane.INFORMATION_MESSAGE);
|
}
|
|
private Color brighterColor(Color color) {
|
int r = Math.min(255, color.getRed() + 30);
|
int g = Math.min(255, color.getGreen() + 30);
|
int b = Math.min(255, color.getBlue() + 30);
|
return new Color(r, g, b);
|
}
|
|
// 优化的图标创建方法
|
private ImageIcon getCachedIcon(String emoji, int size) {
|
String cacheKey = emoji + "_" + size;
|
if (ICON_CACHE.containsKey(cacheKey)) {
|
return ICON_CACHE.get(cacheKey);
|
}
|
|
JLabel label = new JLabel(emoji);
|
label.setFont(new Font("Segoe UI Emoji", Font.PLAIN, size));
|
label.setSize(size, size);
|
|
// 创建一个图像
|
BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
|
Graphics2D g2 = image.createGraphics();
|
|
// 启用抗锯齿
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
label.print(g2);
|
g2.dispose();
|
|
ImageIcon icon = new ImageIcon(image);
|
ICON_CACHE.put(cacheKey, icon);
|
return icon;
|
}
|
|
private void showSystemDebugDialog() {
|
SystemDebugDialog.showSystemDebugDialog((JFrame) getParent());
|
}
|
|
@Override
|
public void dispose() {
|
// 退出设置页面时恢复轮询
|
resumePollingWhenExiting();
|
|
// 清理资源
|
if (faceRegisterDialog != null) {
|
faceRegisterDialog.dispose();
|
faceRegisterDialog = null;
|
}
|
if (faceManagementDialog != null) {
|
faceManagementDialog.dispose();
|
faceManagementDialog = null;
|
}
|
if (slotManagementDialog != null) {
|
slotManagementDialog.dispose();
|
slotManagementDialog = null;
|
}
|
|
if (menuItems != null) {
|
menuItems.clear();
|
}
|
|
super.dispose();
|
}
|
|
// 静态方法:显示密码验证对话框
|
public static boolean showPasswordVerification(JFrame parent) {
|
JPanel panel = new JPanel(new BorderLayout());
|
panel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
panel.setOpaque(true); // 确保不透明
|
panel.setBackground(DARK_LIGHT_COLOR); // 设置背景色
|
|
JLabel label = new JLabel("管理员身份验证");
|
label.setFont(new Font("Microsoft YaHei", Font.BOLD, 18));
|
label.setHorizontalAlignment(SwingConstants.CENTER);
|
label.setOpaque(false); // 标签透明
|
|
JPasswordField passwordField = new JPasswordField(15);
|
passwordField.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
|
passwordField.setOpaque(true); // 文本框不透明
|
|
JPanel inputPanel = new JPanel(new FlowLayout());
|
inputPanel.setOpaque(true); // 改为不透明
|
inputPanel.setBackground(DARK_LIGHT_COLOR); // 设置背景色
|
inputPanel.add(new JLabel("请输入密码:"));
|
inputPanel.add(passwordField);
|
|
panel.add(label, BorderLayout.NORTH);
|
panel.add(inputPanel, BorderLayout.CENTER);
|
|
int result = JOptionPane.showConfirmDialog(
|
parent,
|
panel,
|
"管理员登录",
|
JOptionPane.OK_CANCEL_OPTION,
|
JOptionPane.PLAIN_MESSAGE
|
);
|
|
if (result == JOptionPane.OK_OPTION) {
|
String password = new String(passwordField.getPassword());
|
// 从配置中获取管理员密码
|
Chushihua config = Chushihua.getInstance();
|
if (!config.isInitialized()) {
|
config.initialize();
|
}
|
String adminPassword = config.getMachineConfig().getAdminPassword();
|
|
return password.equals(adminPassword);
|
}
|
|
return false;
|
}
|
|
// 静态方法:从主界面调用
|
public static void showConfigDialog(JFrame parent) {
|
SwingUtilities.invokeLater(() -> {
|
ConfigSet configDialog = new ConfigSet(parent);
|
configDialog.setVisible(true);
|
});
|
}
|
|
}
|