张世豪
4 小时以前 d22349714c8d199c02f336f90fba841ef8f5cd39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
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);
        
        // 添加版权信息在底部
        mainPanel.add(createCopyrightPanel(), BorderLayout.SOUTH);
        
        getContentPane().add(mainPanel);
    }
    
 // 创建版权信息面板
    private JPanel createCopyrightPanel() {
        JPanel copyrightPanel = new JPanel();
        copyrightPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        copyrightPanel.setOpaque(true);
        copyrightPanel.setBackground(DARK_COLOR);
        copyrightPanel.setBorder(new EmptyBorder(10, 0, 5, 0));
        
        JLabel copyrightLabel = new JLabel("北京华星北斗智控技术有限公司 版权所有 2025");
        copyrightLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12));
        copyrightLabel.setForeground(new Color(160, 160, 160));
        
        copyrightPanel.add(copyrightLabel);
        return copyrightPanel;
    }
    
    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.addActionListener(e -> {
            // 强制开启轮询查询功能
            forceStartPolling();
            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;
    }
    
   
    
    @Override
    public void dispose() {
        // 退出设置页面时恢复轮询控制
        SystemDebugDialog.setPollingControlEnabled(true);
        
        // 退出设置页面时恢复轮询
        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);
        });
    }    
    /**
     * 强制开启轮询查询功能(无论当前状态如何)
     */
    private void forceStartPolling() {
        try {
            // 如果轮询未运行,则启动轮询
            if (!lunxun.isPolling()) {
                boolean started = lunxun.startPolling();
                if (started) {
                    //System.out.println("强制开启:轮询查询已启动");
                } else {
                    System.err.println("强制开启:启动轮询查询失败");
                }
            } 
            // 如果轮询已运行但处于暂停状态,则恢复轮询
            else if (lunxun.isPaused()) {
                boolean resumed = lunxun.resumePolling();
                if (resumed) {
                    //System.out.println("强制开启:轮询查询已恢复");
                } else {
                    System.err.println("强制开启:恢复轮询查询失败");
                }
            }
            // 如果轮询已运行且未暂停,则无需操作
            else {
                //System.out.println("强制开启:轮询查询已在运行中");
            }
            
        } catch (Exception e) {
            System.err.println("强制开启轮询查询时发生异常: " + e.getMessage());
        }
    }
    
 // 在 showSystemDebugDialog 方法中添加
    private void showSystemDebugDialog() {
        // 在打开调试对话框时禁用轮询控制
        SystemDebugDialog.setPollingControlEnabled(false);
        SystemDebugDialog.showSystemDebugDialog((JFrame) getParent());
    }
}