From a6077217e25f5804027194a5c2848e773eda1abd Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 21 十一月 2025 15:47:17 +0800
Subject: [PATCH] 修改
---
src/xitongshezhi/lishijilu.java | 889 +++++++++++++++++++++++++---------------------------------
1 files changed, 386 insertions(+), 503 deletions(-)
diff --git a/src/xitongshezhi/lishijilu.java b/src/xitongshezhi/lishijilu.java
index 4765bc8..29c2daf 100644
--- a/src/xitongshezhi/lishijilu.java
+++ b/src/xitongshezhi/lishijilu.java
@@ -1,379 +1,259 @@
package xitongshezhi;
import javax.swing.*;
-import javax.swing.table.DefaultTableModel;
import java.awt.*;
-import java.awt.event.*;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.util.List;
+import java.io.*;
+import java.util.Properties;
-public class lishijilu extends JFrame {
+@SuppressWarnings("serial")
+public class lishijilu extends JDialog {
+ // 灞忓箷灏哄甯搁噺 - 閫傞厤7瀵哥珫灞�
+ private static final int SCREEN_WIDTH = 480;
+ private static final int SCREEN_HEIGHT = 800;
+
+ // 棰滆壊甯搁噺 - 缁熶竴浣跨敤kacaoguanli.java涓殑棰滆壊瀹氫箟
+ private static final Color PRIMARY_COLOR = new Color(52, 152, 219);
+ 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 DELETE_COLOR = new Color(231, 76, 60); // 鍒犻櫎鎸夐挳棰滆壊
+ private static final Color ACTIVE_BUTTON_COLOR = new Color(41, 128, 185); // 婵�娲绘寜閽鑹�
+
private JPanel mainPanel;
- private JLabel titleLabel;
+ private JButton logButton; // 鏃ュ織璁板綍鎸夐挳
+ private JButton errorLogButton; // 閿欒鏃ュ織鎸夐挳
private JButton backButton;
+ private JButton deleteAllButton;
- // 鎺у埗闈㈡澘缁勪欢
- private JPanel controlPanel;
- private JLabel totalRecordsLabel;
- private JLabel pickupCountLabel;
- private JLabel returnCountLabel;
- private JLabel adminCountLabel;
- private JButton refreshButton;
- private JButton clearButton;
+ // 鏂囨湰鍩熺粍浠�
+ private JScrollPane textScrollPane;
+ private JTextArea contentTextArea;
- // 琛ㄦ牸缁勪欢
- private JScrollPane tableScrollPane;
- private JTable historyTable;
- private DefaultTableModel tableModel;
- private JLabel displayCountLabel;
+ // 褰撳墠鏄剧ず鐨勬棩蹇楃被鍨�
+ private String currentLogType = "log"; // "log" 鎴� "error"
- // 鍘嗗彶璁板綍鏁版嵁
- private List<HistoryRecord> historyRecords;
- private final int MAX_RECORDS = 100;
-
- // 棰滆壊瀹氫箟
- private final Color BACKGROUND_COLOR = new Color(15, 28, 48);
- private final Color CARD_COLOR = new Color(26, 43, 68);
- private final Color PRIMARY_COLOR = new Color(52, 152, 219);
- private final Color SECONDARY_COLOR = new Color(46, 204, 113);
- private final Color DANGER_COLOR = new Color(231, 76, 60);
- private final Color WARNING_COLOR = new Color(243, 156, 18);
- private final Color TEXT_COLOR = new Color(224, 224, 224);
- private final Color TEXT_LIGHT_COLOR = new Color(160, 200, 255);
-
- public lishijilu() {
- historyRecords = new ArrayList<>();
+ public lishijilu(JFrame parent) {
+ super(parent, "", true);
initializeUI();
setupEventListeners();
- loadDemoData(); // 鍔犺浇婕旂ず鏁版嵁
- updateDisplay();
+ loadLogContent(); // 榛樿鍔犺浇鎿嶄綔鏃ュ織
}
private void initializeUI() {
- // 璁剧疆绐楀彛灞炴�� - 7瀵哥珫灞� (480x800)
- setTitle("鍘嗗彶璁板綍 - UWB浜哄憳瀹氫綅鍗″彂鍗℃満绠$悊绯荤粺");
- setSize(480, 800);
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- setLocationRelativeTo(null);
+ // 璁剧疆瀵硅瘽妗嗗睘鎬�
+ setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
+ setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ setLocationRelativeTo(getParent());
setResizable(false);
- // 璁剧疆涓嶉�忔槑鑳屾櫙
- getContentPane().setBackground(BACKGROUND_COLOR);
+ // 璁剧疆绯荤粺澶栬
+ try {
+ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
// 涓婚潰鏉�
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
- mainPanel.setBackground(BACKGROUND_COLOR);
- mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
+ mainPanel.setBackground(DARK_COLOR);
+ mainPanel.setOpaque(true);
+ mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
// 鍒涘缓椤堕儴鏍囬鏍�
JPanel headerPanel = createHeaderPanel();
- // 鍒涘缓鎺у埗闈㈡澘
- controlPanel = createControlPanel();
-
- // 鍒涘缓琛ㄦ牸鍖哄煙
- JPanel tablePanel = createTablePanel();
+ // 鍒涘缓鏂囨湰鍖哄煙
+ JPanel contentPanel = createContentPanel();
mainPanel.add(headerPanel, BorderLayout.NORTH);
- mainPanel.add(controlPanel, BorderLayout.CENTER);
- mainPanel.add(tablePanel, BorderLayout.SOUTH);
+ mainPanel.add(contentPanel, BorderLayout.CENTER);
- add(mainPanel);
+ getContentPane().add(mainPanel);
}
private JPanel createHeaderPanel() {
- JPanel panel = new JPanel(new BorderLayout());
- panel.setBackground(BACKGROUND_COLOR);
- panel.setPreferredSize(new Dimension(464, 40));
+ JPanel headerPanel = new JPanel(new BorderLayout());
+ headerPanel.setOpaque(false);
+ headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 12, 0));
- // 鏍囬
- titleLabel = new JLabel("鍘嗗彶璁板綍");
- titleLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 18));
- titleLabel.setForeground(TEXT_COLOR);
- titleLabel.setIcon(createIcon("馃摐", 20));
+ // 鍒涘缓鏃ュ織绫诲瀷閫夋嫨鎸夐挳闈㈡澘
+ JPanel logTypePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 8, 0));
+ logTypePanel.setOpaque(false);
+
+ // 鏃ュ織璁板綍鎸夐挳
+ logButton = new JButton("鏃ュ織璁板綍");
+ logButton.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
+ logButton.setBackground(ACTIVE_BUTTON_COLOR); // 榛樿婵�娲荤姸鎬�
+ logButton.setForeground(Color.WHITE);
+ logButton.setOpaque(true);
+ logButton.setFocusPainted(false);
+ logButton.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
+ logButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
+
+ // 閿欒鏃ュ織鎸夐挳
+ errorLogButton = new JButton("閿欒鏃ュ織");
+ errorLogButton.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
+ errorLogButton.setBackground(PRIMARY_COLOR); // 榛樿闈炴縺娲荤姸鎬�
+ errorLogButton.setForeground(Color.WHITE);
+ errorLogButton.setOpaque(true);
+ errorLogButton.setFocusPainted(false);
+ errorLogButton.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
+ errorLogButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
+
+ logTypePanel.add(logButton);
+ logTypePanel.add(errorLogButton);
+
+ // 鎿嶄綔鎸夐挳闈㈡澘
+ JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0));
+ actionButtonPanel.setOpaque(false);
+
+ // 鍒犻櫎鍏ㄩ儴璁板綍鎸夐挳
+ deleteAllButton = new JButton("鍒犻櫎鍏ㄩ儴");
+ deleteAllButton.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
+ deleteAllButton.setBackground(DELETE_COLOR);
+ deleteAllButton.setForeground(Color.WHITE);
+ deleteAllButton.setOpaque(true);
+ deleteAllButton.setFocusPainted(false);
+ deleteAllButton.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
+ deleteAllButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
// 杩斿洖鎸夐挳
- backButton = new JButton("杩斿洖");
- backButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 12));
- backButton.setBackground(new Color(52, 152, 219, 50));
- backButton.setForeground(PRIMARY_COLOR);
- backButton.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(52, 152, 219, 75), 1),
- BorderFactory.createEmptyBorder(6, 12, 6, 12)
- ));
+ backButton = new JButton("鍏抽棴");
+ backButton.setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
+ backButton.setBackground(PRIMARY_COLOR);
+ backButton.setForeground(Color.WHITE);
+ backButton.setOpaque(true);
backButton.setFocusPainted(false);
+ backButton.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
backButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
- panel.add(titleLabel, BorderLayout.WEST);
- panel.add(backButton, BorderLayout.EAST);
+ actionButtonPanel.add(deleteAllButton);
+ actionButtonPanel.add(backButton);
- return panel;
+ // 鎸夐挳鎮仠鏁堟灉
+ setupButtonHoverEffects();
+
+ headerPanel.add(logTypePanel, BorderLayout.WEST);
+ headerPanel.add(actionButtonPanel, BorderLayout.EAST);
+
+ return headerPanel;
}
- private JPanel createControlPanel() {
- JPanel panel = new JPanel(new BorderLayout());
- panel.setBackground(CARD_COLOR);
- panel.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(52, 152, 219, 25), 1),
- BorderFactory.createEmptyBorder(12, 12, 12, 12)
- ));
- panel.setPreferredSize(new Dimension(464, 80));
-
- // 缁熻淇℃伅闈㈡澘
- JPanel statsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 0));
- statsPanel.setBackground(CARD_COLOR);
-
- // 鎬昏褰�
- JPanel totalPanel = createStatItem("鎬昏褰�", "0");
- totalRecordsLabel = (JLabel) ((JPanel) totalPanel.getComponent(0)).getComponent(0);
-
- // 鍙栧崱鏁伴噺
- JPanel pickupPanel = createStatItem("鍙栧崱", "0");
- pickupCountLabel = (JLabel) ((JPanel) pickupPanel.getComponent(0)).getComponent(0);
-
- // 杩樺崱鏁伴噺
- JPanel returnPanel = createStatItem("杩樺崱", "0");
- returnCountLabel = (JLabel) ((JPanel) returnPanel.getComponent(0)).getComponent(0);
-
- // 绠$悊鍛樻搷浣�
- JPanel adminPanel = createStatItem("绠$悊鍛樻搷浣�", "0");
- adminCountLabel = (JLabel) ((JPanel) adminPanel.getComponent(0)).getComponent(0);
-
- statsPanel.add(totalPanel);
- statsPanel.add(pickupPanel);
- statsPanel.add(returnPanel);
- statsPanel.add(adminPanel);
-
- // 鎸夐挳闈㈡澘
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0));
- buttonPanel.setBackground(CARD_COLOR);
-
- // 鍒锋柊鎸夐挳
- refreshButton = new JButton("鍒锋柊");
- refreshButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 12));
- refreshButton.setBackground(new Color(46, 204, 113, 50));
- refreshButton.setForeground(SECONDARY_COLOR);
- refreshButton.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(46, 204, 113, 75), 1),
- BorderFactory.createEmptyBorder(6, 12, 6, 12)
- ));
- refreshButton.setFocusPainted(false);
- refreshButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
-
- // 娓呯┖鎸夐挳
- clearButton = new JButton("娓呯┖");
- clearButton.setFont(new Font("Microsoft YaHei", Font.BOLD, 12));
- clearButton.setBackground(new Color(231, 76, 60, 50));
- clearButton.setForeground(DANGER_COLOR);
- clearButton.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(231, 76, 60, 75), 1),
- BorderFactory.createEmptyBorder(6, 12, 6, 12)
- ));
- clearButton.setFocusPainted(false);
- clearButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
-
- buttonPanel.add(refreshButton);
- buttonPanel.add(clearButton);
-
- panel.add(statsPanel, BorderLayout.WEST);
- panel.add(buttonPanel, BorderLayout.EAST);
-
- return panel;
- }
-
- private JPanel createStatItem(String label, String value) {
- JPanel panel = new JPanel();
- panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
- panel.setBackground(CARD_COLOR);
- panel.setAlignmentX(Component.CENTER_ALIGNMENT);
-
- JLabel valueLabel = new JLabel(value);
- valueLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 16));
- valueLabel.setForeground(TEXT_COLOR);
- valueLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
-
- JLabel nameLabel = new JLabel(label);
- nameLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 11));
- nameLabel.setForeground(TEXT_LIGHT_COLOR);
- nameLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
-
- panel.add(valueLabel);
- panel.add(nameLabel);
-
- return panel;
- }
-
- private JPanel createTablePanel() {
- JPanel panel = new JPanel(new BorderLayout());
- panel.setBackground(CARD_COLOR);
- panel.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(52, 152, 219, 25), 1),
- BorderFactory.createEmptyBorder(12, 12, 12, 12)
- ));
- panel.setPreferredSize(new Dimension(464, 600));
-
- // 鍒涘缓琛ㄦ牸
- String[] columnNames = {"鏃堕棿", "鍗℃Ы缂栧彿", "鎿嶄綔", "鎿嶄綔瀵硅薄"};
- tableModel = new DefaultTableModel(columnNames, 0) {
- @Override
- public boolean isCellEditable(int row, int column) {
- return false; // 琛ㄦ牸涓嶅彲缂栬緫
+ private void setupButtonHoverEffects() {
+ // 鏃ュ織鎸夐挳鎮仠鏁堟灉
+ logButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mouseEntered(java.awt.event.MouseEvent evt) {
+ if (!currentLogType.equals("log")) {
+ logButton.setBackground(brighterColor(PRIMARY_COLOR));
+ }
}
- };
+
+ public void mouseExited(java.awt.event.MouseEvent evt) {
+ if (!currentLogType.equals("log")) {
+ logButton.setBackground(PRIMARY_COLOR);
+ }
+ }
+ });
- historyTable = new JTable(tableModel);
- historyTable.setFont(new Font("Microsoft YaHei", Font.PLAIN, 11));
- historyTable.setRowHeight(25);
- historyTable.setSelectionBackground(new Color(52, 152, 219, 100));
- historyTable.setGridColor(new Color(255, 255, 255, 50));
- historyTable.setShowGrid(true);
- historyTable.setIntercellSpacing(new Dimension(1, 1));
+ // 閿欒鏃ュ織鎸夐挳鎮仠鏁堟灉
+ errorLogButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mouseEntered(java.awt.event.MouseEvent evt) {
+ if (!currentLogType.equals("error")) {
+ errorLogButton.setBackground(brighterColor(PRIMARY_COLOR));
+ }
+ }
+
+ public void mouseExited(java.awt.event.MouseEvent evt) {
+ if (!currentLogType.equals("error")) {
+ errorLogButton.setBackground(PRIMARY_COLOR);
+ }
+ }
+ });
- // 璁剧疆琛ㄥご
- historyTable.getTableHeader().setFont(new Font("Microsoft YaHei", Font.BOLD, 11));
- historyTable.getTableHeader().setBackground(new Color(15, 28, 48, 200));
- historyTable.getTableHeader().setForeground(TEXT_LIGHT_COLOR);
- historyTable.getTableHeader().setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, new Color(52, 152, 219, 75)));
+ // 鍒犻櫎鎸夐挳鎮仠鏁堟灉
+ deleteAllButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mouseEntered(java.awt.event.MouseEvent evt) {
+ deleteAllButton.setBackground(brighterColor(DELETE_COLOR));
+ }
+
+ public void mouseExited(java.awt.event.MouseEvent evt) {
+ deleteAllButton.setBackground(DELETE_COLOR);
+ }
+ });
- // 璁剧疆鍒楀
- historyTable.getColumnModel().getColumn(0).setPreferredWidth(150); // 鏃堕棿
- historyTable.getColumnModel().getColumn(1).setPreferredWidth(80); // 鍗℃Ы缂栧彿
- historyTable.getColumnModel().getColumn(2).setPreferredWidth(60); // 鎿嶄綔
- historyTable.getColumnModel().getColumn(3).setPreferredWidth(80); // 鎿嶄綔瀵硅薄
+ // 杩斿洖鎸夐挳鎮仠鏁堟灉
+ backButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mouseEntered(java.awt.event.MouseEvent evt) {
+ backButton.setBackground(brighterColor(PRIMARY_COLOR));
+ }
+
+ public void mouseExited(java.awt.event.MouseEvent evt) {
+ backButton.setBackground(PRIMARY_COLOR);
+ }
+ });
+ }
+
+ private JPanel createContentPanel() {
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.setBackground(DARK_LIGHT_COLOR);
+ panel.setOpaque(true);
+ panel.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(new Color(52, 152, 219, 26)),
+ BorderFactory.createEmptyBorder(12, 12, 12, 12)
+ ));
- // 鑷畾涔夋覆鏌撳櫒
- historyTable.setDefaultRenderer(Object.class, new HistoryTableCellRenderer());
+ // 鍐呭鏍囬
+ JPanel contentHeader = new JPanel(new BorderLayout());
+ contentHeader.setOpaque(false);
+ contentHeader.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(255, 255, 255, 26)),
+ BorderFactory.createEmptyBorder(0, 0, 8, 0)
+ ));
- // 婊氬姩闈㈡澘
- tableScrollPane = new JScrollPane(historyTable);
- tableScrollPane.setBorder(BorderFactory.createEmptyBorder());
- tableScrollPane.getViewport().setBackground(new Color(26, 43, 68, 200));
+ JLabel contentTitle = new JLabel("鏃ュ織鍐呭");
+ contentTitle.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
+ contentTitle.setForeground(TEXT_COLOR);
- // 鑷畾涔夋粴鍔ㄦ潯
- JScrollBar verticalScrollBar = tableScrollPane.getVerticalScrollBar();
- verticalScrollBar.setBackground(CARD_COLOR);
- verticalScrollBar.setUnitIncrement(16);
+ contentHeader.add(contentTitle, BorderLayout.WEST);
+
+ // 鍒涘缓鏂囨湰鍩�
+ contentTextArea = new JTextArea();
+ contentTextArea.setEditable(false);
+ contentTextArea.setBackground(DARK_LIGHT_COLOR);
+ contentTextArea.setForeground(TEXT_COLOR);
+ contentTextArea.setFont(new Font("瀹嬩綋", Font.PLAIN, 12));
+ contentTextArea.setLineWrap(true);
+ contentTextArea.setWrapStyleWord(true);
+ contentTextArea.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
+
+ // 鍒涘缓婊氬姩闈㈡澘
+ textScrollPane = new JScrollPane(contentTextArea);
+ textScrollPane.setBorder(BorderFactory.createEmptyBorder());
+ textScrollPane.getVerticalScrollBar().setUnitIncrement(16);
+ textScrollPane.setOpaque(false);
+ textScrollPane.getViewport().setOpaque(false);
// 搴曢儴淇℃伅鏍�
JPanel footerPanel = new JPanel(new BorderLayout());
- footerPanel.setBackground(CARD_COLOR);
+ footerPanel.setBackground(DARK_LIGHT_COLOR);
+ footerPanel.setOpaque(true);
footerPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(255, 255, 255, 25)));
- footerPanel.setPreferredSize(new Dimension(440, 30));
+ footerPanel.setPreferredSize(new Dimension(432, 30));
- JLabel infoLabel = new JLabel("鏄剧ず鏈�杩�");
- infoLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 11));
- infoLabel.setForeground(TEXT_LIGHT_COLOR);
-
- displayCountLabel = new JLabel("0");
- displayCountLabel.setFont(new Font("Microsoft YaHei", Font.BOLD, 11));
- displayCountLabel.setForeground(TEXT_LIGHT_COLOR);
-
- JLabel recordsLabel = new JLabel("鏉¤褰�");
- recordsLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 11));
- recordsLabel.setForeground(TEXT_LIGHT_COLOR);
-
- JPanel countPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
- countPanel.setBackground(CARD_COLOR);
- countPanel.add(infoLabel);
- countPanel.add(displayCountLabel);
- countPanel.add(recordsLabel);
-
- JLabel noteLabel = new JLabel("鏈�澶氫繚鐣欐渶杩�100鏉¤褰�");
+ JLabel noteLabel = new JLabel("鏈�澶氫繚鐣欐渶杩�1000鏉¤褰�");
noteLabel.setFont(new Font("Microsoft YaHei", Font.PLAIN, 11));
noteLabel.setForeground(TEXT_LIGHT_COLOR);
+ noteLabel.setOpaque(false);
- footerPanel.add(countPanel, BorderLayout.WEST);
footerPanel.add(noteLabel, BorderLayout.EAST);
- panel.add(tableScrollPane, BorderLayout.CENTER);
+ panel.add(contentHeader, BorderLayout.NORTH);
+ panel.add(textScrollPane, BorderLayout.CENTER);
panel.add(footerPanel, BorderLayout.SOUTH);
return panel;
- }
-
- // 鑷畾涔夎〃鏍煎崟鍏冩牸娓叉煋鍣�
- private class HistoryTableCellRenderer extends DefaultTableCellRenderer {
- @Override
- public Component getTableCellRendererComponent(JTable table, Object value,
- boolean isSelected, boolean hasFocus,
- int row, int column) {
- Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-
- // 璁剧疆鍩烘湰鏍峰紡
- comp.setBackground(row % 2 == 0 ?
- new Color(26, 43, 68, 200) :
- new Color(255, 255, 255, 10));
- comp.setForeground(TEXT_COLOR);
-
- // 璁剧疆瀛椾綋
- if (column == 0) { // 鏃堕棿鍒椾娇鐢ㄧ瓑瀹藉瓧浣�
- comp.setFont(new Font("Courier New", Font.PLAIN, 10));
- } else {
- comp.setFont(new Font("Microsoft YaHei", Font.PLAIN, 11));
- }
-
- // 鎿嶄綔鍒楃壒娈婂鐞�
- if (column == 2 && value != null) {
- JLabel label = new JLabel(value.toString());
- label.setOpaque(true);
- label.setHorizontalAlignment(SwingConstants.CENTER);
-
- if (value.toString().equals("鍙栧崱")) {
- label.setBackground(new Color(52, 152, 219, 50));
- label.setForeground(PRIMARY_COLOR);
- label.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(52, 152, 219, 75), 1),
- BorderFactory.createEmptyBorder(2, 8, 2, 8)
- ));
- } else if (value.toString().equals("杩樺崱")) {
- label.setBackground(new Color(46, 204, 113, 50));
- label.setForeground(SECONDARY_COLOR);
- label.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(46, 204, 113, 75), 1),
- BorderFactory.createEmptyBorder(2, 8, 2, 8)
- ));
- }
-
- if (isSelected) {
- label.setBackground(new Color(52, 152, 219, 100));
- }
-
- return label;
- }
-
- // 鎿嶄綔瀵硅薄鍒楃壒娈婂鐞�
- if (column == 3 && value != null) {
- JLabel label = new JLabel(value.toString());
- label.setOpaque(true);
- label.setHorizontalAlignment(SwingConstants.CENTER);
-
- if (value.toString().equals("绯荤粺")) {
- label.setBackground(new Color(149, 165, 166, 50));
- label.setForeground(new Color(149, 165, 166));
- label.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(149, 165, 166, 75), 1),
- BorderFactory.createEmptyBorder(2, 8, 2, 8)
- ));
- } else if (value.toString().equals("绠$悊鍛�")) {
- label.setBackground(new Color(243, 156, 18, 50));
- label.setForeground(WARNING_COLOR);
- label.setBorder(BorderFactory.createCompoundBorder(
- BorderFactory.createLineBorder(new Color(243, 156, 18, 75), 1),
- BorderFactory.createEmptyBorder(2, 8, 2, 8)
- ));
- }
-
- if (isSelected) {
- label.setBackground(new Color(52, 152, 219, 100));
- }
-
- return label;
- }
-
- return comp;
- }
}
private void setupEventListeners() {
@@ -382,224 +262,227 @@
dispose();
});
- // 鍒锋柊鎸夐挳
- refreshButton.addActionListener(e -> {
- refreshData();
+ // 鍒犻櫎鍏ㄩ儴璁板綍鎸夐挳
+ deleteAllButton.addActionListener(e -> {
+ deleteAllRecords();
});
- // 娓呯┖鎸夐挳
- clearButton.addActionListener(e -> {
- clearAllRecords();
+ // 鏃ュ織璁板綍鎸夐挳
+ logButton.addActionListener(e -> {
+ switchToLogType("log");
+ });
+
+ // 閿欒鏃ュ織鎸夐挳
+ errorLogButton.addActionListener(e -> {
+ switchToLogType("error");
});
}
- // 鍘嗗彶璁板綍绫�
- private static class HistoryRecord {
- long id;
- String timestamp;
- int slotId;
- String operation; // "pickup" 鎴� "return"
- int operator; // 0=绯荤粺, 1=绠$悊鍛�
-
- HistoryRecord(long id, String timestamp, int slotId, String operation, int operator) {
- this.id = id;
- this.timestamp = timestamp;
- this.slotId = slotId;
- this.operation = operation;
- this.operator = operator;
- }
- }
-
- // 鍔犺浇婕旂ず鏁版嵁
- private void loadDemoData() {
- if (historyRecords.isEmpty()) {
- generateDemoData();
- }
- }
-
- // 鐢熸垚婕旂ず鏁版嵁
- private void generateDemoData() {
- String[] operations = {"pickup", "return"};
- int[] operators = {0, 1}; // 0=绯荤粺, 1=绠$悊鍛�
- long baseTime = System.currentTimeMillis() - (30L * 24 * 60 * 60 * 1000); // 30澶╁墠寮�濮�
-
- for (int i = 0; i < 50; i++) {
- int randomSlot = (int) (Math.random() * 60) + 1;
- String randomOperation = operations[(int) (Math.random() * operations.length)];
- int randomOperator = operators[(int) (Math.random() * operators.length)];
- long randomTime = baseTime + (long) (Math.random() * 30 * 24 * 60 * 60 * 1000);
-
- historyRecords.add(new HistoryRecord(
- randomTime,
- new Date(randomTime).toInstant().toString(),
- randomSlot,
- randomOperation,
- randomOperator
- ));
+ // 鍒囨崲鏃ュ織绫诲瀷
+ private void switchToLogType(String logType) {
+ if (currentLogType.equals(logType)) {
+ return; // 宸茬粡鏄綋鍓嶇被鍨嬶紝鏃犻渶鍒囨崲
}
- // 鎸夋椂闂存帓搴忥紙鏈�鏂扮殑鍦ㄥ墠闈級
- historyRecords.sort((a, b) -> Long.compare(b.id, a.id));
+ currentLogType = logType;
- // 闄愬埗涓烘渶澶ц褰曟暟
- if (historyRecords.size() > MAX_RECORDS) {
- historyRecords = historyRecords.subList(0, MAX_RECORDS);
- }
- }
-
- // 鏍煎紡鍖栨椂闂存樉绀�
- private String formatTime(String isoString) {
- try {
- SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
- SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = inputFormat.parse(isoString);
- return outputFormat.format(date);
- } catch (Exception e) {
- return isoString;
- }
- }
-
- // 鑾峰彇鎿嶄綔鏄剧ず鏂囨湰
- private String getOperationText(String operation) {
- return "pickup".equals(operation) ? "鍙栧崱" : "杩樺崱";
- }
-
- // 鑾峰彇鎿嶄綔瀵硅薄鏄剧ず鏂囨湰
- private String getOperatorText(int operator) {
- return operator == 0 ? "绯荤粺" : "绠$悊鍛�";
- }
-
- // 鏇存柊鏄剧ず
- private void updateDisplay() {
- // 鏇存柊琛ㄦ牸
- tableModel.setRowCount(0);
-
- for (HistoryRecord record : historyRecords) {
- tableModel.addRow(new Object[]{
- formatTime(record.timestamp),
- record.slotId,
- getOperationText(record.operation),
- getOperatorText(record.operator)
- });
+ // 鏇存柊鎸夐挳鐘舵��
+ if (logType.equals("log")) {
+ logButton.setBackground(ACTIVE_BUTTON_COLOR);
+ errorLogButton.setBackground(PRIMARY_COLOR);
+ } else {
+ logButton.setBackground(PRIMARY_COLOR);
+ errorLogButton.setBackground(ACTIVE_BUTTON_COLOR);
}
- // 鏇存柊缁熻淇℃伅
- updateStats();
+ // 鍔犺浇瀵瑰簲绫诲瀷鐨勬棩蹇楀唴瀹�
+ loadLogContent();
}
- // 鏇存柊缁熻淇℃伅
- private void updateStats() {
- int total = historyRecords.size();
- int pickupCount = (int) historyRecords.stream()
- .filter(record -> "pickup".equals(record.operation))
- .count();
- int returnCount = (int) historyRecords.stream()
- .filter(record -> "return".equals(record.operation))
- .count();
- int adminCount = (int) historyRecords.stream()
- .filter(record -> record.operator == 1)
- .count();
-
- totalRecordsLabel.setText(String.valueOf(total));
- pickupCountLabel.setText(String.valueOf(pickupCount));
- returnCountLabel.setText(String.valueOf(returnCount));
- adminCountLabel.setText(String.valueOf(adminCount));
- displayCountLabel.setText(String.valueOf(total));
- }
-
- // 鍒锋柊鏁版嵁
- private void refreshData() {
- String originalText = refreshButton.getText();
-
- // 鏄剧ず鍒锋柊涓姸鎬�
- refreshButton.setText("鍒锋柊涓�...");
- refreshButton.setEnabled(false);
-
- // 妯℃嫙鏁版嵁鍒锋柊寤惰繜
- Timer timer = new Timer(800, e -> {
- updateDisplay();
-
- // 鎭㈠鎸夐挳鐘舵��
- refreshButton.setText(originalText);
- refreshButton.setEnabled(true);
- });
- timer.setRepeats(false);
- timer.start();
- }
-
- // 娓呯┖鎵�鏈夎褰�
- private void clearAllRecords() {
+ // 鍒犻櫎鍏ㄩ儴璁板綍鐨勬柟娉�
+ private void deleteAllRecords() {
+ // 纭瀵硅瘽妗�
+ String logTypeName = currentLogType.equals("log") ? "鎿嶄綔" : "閿欒";
int result = JOptionPane.showConfirmDialog(
this,
- "纭畾瑕佹竻绌烘墍鏈夊巻鍙茶褰曞悧锛熸鎿嶄綔涓嶅彲鎭㈠銆�",
- "纭娓呯┖",
+ "纭畾瑕佸垹闄ゆ墍鏈�" + logTypeName + "璁板綍鍚楋紵姝ゆ搷浣滀笉鍙仮澶嶏紒",
+ "纭鍒犻櫎",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE
);
if (result == JOptionPane.YES_OPTION) {
- historyRecords.clear();
- updateDisplay();
+ try {
+ String fileName = currentLogType.equals("log") ? "log.properties" : "err.properties";
+ File logFile = new File(fileName);
+
+ if (logFile.exists()) {
+ // 鍒涘缓绌虹殑Properties瀵硅薄骞跺啓鍏ユ枃浠�
+ Properties emptyProps = new Properties();
+ try (FileOutputStream out = new FileOutputStream(logFile);
+ OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8")) {
+ emptyProps.store(writer, "鍙戝崱鏈�" + logTypeName + "璁板綍 - 鎵�鏈夎褰曞凡娓呯┖");
+ }
+
+ // 鏇存柊鏂囨湰鍩熸樉绀�
+ contentTextArea.setText("鎵�鏈�" + logTypeName + "璁板綍宸叉垚鍔熷垹闄ゃ�俓n\n鏃ュ織鏂囦欢宸叉竻绌恒��");
+
+ // 鏄剧ず鎴愬姛娑堟伅
+ JOptionPane.showMessageDialog(
+ this,
+ "鎵�鏈�" + logTypeName + "璁板綍宸叉垚鍔熷垹闄ゃ��",
+ "鍒犻櫎鎴愬姛",
+ JOptionPane.INFORMATION_MESSAGE
+ );
+ } else {
+ contentTextArea.setText(logTypeName + "鏃ュ織鏂囦欢涓嶅瓨鍦紝鏃犻渶鍒犻櫎銆�");
+ }
+
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ JOptionPane.showMessageDialog(
+ this,
+ "鍒犻櫎璁板綍鏃跺嚭閿�: " + ex.getMessage(),
+ "閿欒",
+ JOptionPane.ERROR_MESSAGE
+ );
+ }
}
}
- // 娣诲姞娴嬭瘯璁板綍锛堢敤浜庢紨绀猴級
- private void addTestRecord() {
- int randomSlot = (int) (Math.random() * 60) + 1;
- String randomOperation = Math.random() > 0.5 ? "pickup" : "return";
- int randomOperator = Math.random() > 0.7 ? 1 : 0; // 30%姒傜巼涓虹鐞嗗憳鎿嶄綔
+ // 鍔犺浇鏃ュ織鍐呭
+ private void loadLogContent() {
+ String fileName = currentLogType.equals("log") ? "log.properties" : "err.properties";
+ String logTypeName = currentLogType.equals("log") ? "鎿嶄綔" : "閿欒";
- historyRecords.add(0, new HistoryRecord(
- System.currentTimeMillis(),
- new Date().toInstant().toString(),
- randomSlot,
- randomOperation,
- randomOperator
- ));
+ File logFile = new File(fileName);
- // 闄愬埗涓烘渶澶ц褰曟暟
- if (historyRecords.size() > MAX_RECORDS) {
- historyRecords.remove(historyRecords.size() - 1);
+ if (!logFile.exists()) {
+ contentTextArea.setText(logTypeName + "鏃ュ織鏂囦欢涓嶅瓨鍦ㄣ��");
+ return;
}
- updateDisplay();
- }
-
- // 鍒涘缓鍥炬爣锛堜娇鐢ㄦ枃鏈〃鎯呯鍙凤級
- private Icon createIcon(String emoji, int size) {
- JLabel label = new JLabel(emoji);
- label.setFont(new Font("Segoe UI Emoji", Font.PLAIN, size));
- return new Icon() {
- @Override
- public void paintIcon(Component c, Graphics g, int x, int y) {
- label.setBounds(x, y, getIconWidth(), getIconHeight());
- label.paint(g);
+ Properties logProps = new Properties();
+ try (FileInputStream in = new FileInputStream(logFile);
+ InputStreamReader reader = new InputStreamReader(in, "UTF-8")) {
+
+ logProps.load(reader);
+
+ // 妫�鏌ヨ褰曟暟閲忥紝濡傛灉瓒呰繃1000鏉″垯鍒犻櫎鏃ц褰�
+ if (logProps.size() > 1000) {
+ trimLogProperties(logProps, fileName);
}
- @Override
- public int getIconWidth() {
- return size;
- }
+ // 鏋勫缓鏄剧ず鍐呭
+ StringBuilder content = new StringBuilder();
+ content.append(logTypeName).append("鏃ュ織鍐呭 (").append(logProps.size()).append(" 鏉¤褰�):\n\n");
- @Override
- public int getIconHeight() {
- return size;
- }
- };
- }
-
- // 涓绘柟娉曟祴璇�
- public static void main(String[] args) {
- // 璁剧疆绯荤粺澶栬
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeel());
+ // 鎸夋椂闂存埑鎺掑簭鏄剧ず
+ logProps.stringPropertyNames().stream()
+ .sorted((a, b) -> {
+ try {
+ // 浠庨敭涓彁鍙栨椂闂存埑閮ㄥ垎杩涜姣旇緝
+ long timeA = extractTimestampFromKey(a);
+ long timeB = extractTimestampFromKey(b);
+ return Long.compare(timeB, timeA); // 闄嶅簭鎺掑垪锛屾渶鏂扮殑鍦ㄥ墠
+ } catch (Exception e) {
+ return b.compareTo(a); // 濡傛灉鎻愬彇澶辫触锛屼娇鐢ㄥ瓧绗︿覆姣旇緝
+ }
+ })
+ .forEach(key -> {
+ String value = logProps.getProperty(key);
+ content.append("鏃堕棿: ").append(extractTimeFromValue(value)).append("\n");
+ content.append("鍐呭: ").append(extractOperationFromValue(value)).append("\n");
+ content.append("----------------------------------------\n");
+ });
+
+ contentTextArea.setText(content.toString());
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ contentTextArea.setText("鍔犺浇" + logTypeName + "鏃ュ織鏂囦欢鏃跺嚭閿�: " + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
+ contentTextArea.setText("澶勭悊" + logTypeName + "鏃ュ織鍐呭鏃跺嚭閿�: " + e.getMessage());
}
-
- SwingUtilities.invokeLater(() -> {
- lishijilu frame = new lishijilu();
- frame.setVisible(true);
- });
}
+
+ // 浠庨敭涓彁鍙栨椂闂存埑
+ private long extractTimestampFromKey(String key) {
+ try {
+ // 閿殑鏍煎紡: log_鏃堕棿鎴砡UUID 鎴� error_鏃堕棿鎴砡UUID
+ String[] parts = key.split("_");
+ if (parts.length >= 2) {
+ return Long.parseLong(parts[1]);
+ }
+ } catch (Exception e) {
+ // 濡傛灉瑙f瀽澶辫触锛岃繑鍥�0
+ }
+ return 0L;
+ }
+
+ // 浠庡�间腑鎻愬彇鏃堕棿閮ㄥ垎
+ private String extractTimeFromValue(String value) {
+ if (value == null) return "鏈煡鏃堕棿";
+ // 鍊肩殑鏍煎紡: [2025-11-21 14:44:39] 鍙栧崱鎿嶄綔锛氬崱妲�19琚鐞嗗憳鍙栧崱
+ int start = value.indexOf('[');
+ int end = value.indexOf(']');
+ if (start >= 0 && end > start) {
+ return value.substring(start + 1, end);
+ }
+ return value;
+ }
+
+ // 浠庡�间腑鎻愬彇鎿嶄綔閮ㄥ垎
+ private String extractOperationFromValue(String value) {
+ if (value == null) return "鏈煡鍐呭";
+ // 鍊肩殑鏍煎紡: [2025-11-21 14:44:39] 鍙栧崱鎿嶄綔锛氬崱妲�19琚鐞嗗憳鍙栧崱
+ int end = value.indexOf(']');
+ if (end >= 0 && end + 1 < value.length()) {
+ return value.substring(end + 1).trim();
+ }
+ return value;
+ }
+
+ // 淇壀鏃ュ織灞炴�э紝鍙繚鐣欐渶鏂扮殑1000鏉¤褰�
+ private void trimLogProperties(Properties logProps, String fileName) {
+ // 鎸夋椂闂存埑鎺掑簭锛屼繚鐣欐渶鏂扮殑1000鏉�
+ logProps.stringPropertyNames().stream()
+ .sorted((a, b) -> {
+ try {
+ long timeA = extractTimestampFromKey(a);
+ long timeB = extractTimestampFromKey(b);
+ return Long.compare(timeB, timeA);
+ } catch (Exception e) {
+ return b.compareTo(a);
+ }
+ })
+ .skip(1000)
+ .forEach(logProps::remove);
+
+ // 淇濆瓨淇壀鍚庣殑灞炴��
+ try (FileOutputStream out = new FileOutputStream(fileName);
+ OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8")) {
+ String logTypeName = fileName.equals("log.properties") ? "鎿嶄綔" : "閿欒";
+ logProps.store(writer, "鍙戝崱鏈�" + logTypeName + "璁板綍 - 鑷姩淇壀鑷�1000鏉¤褰�");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // 鏂板杈呭姪鏂规硶锛氫娇棰滆壊鏇翠寒
+ 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);
+ }
+
+ // 闈欐�佹柟娉曪細浠庡叾浠栭〉闈㈣皟鐢�
+ public static void showHistoryDialog(JFrame parent) {
+ SwingUtilities.invokeLater(() -> {
+ lishijilu dialog = new lishijilu(parent);
+ dialog.setVisible(true);
+ });
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3