From ef78717c5b956a26b360de44f774fc2b804296c2 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 20 十一月 2025 20:56:36 +0800
Subject: [PATCH] 修改20251120
---
src/xitongshezhi/lishijilu.java | 699 ++++++++++++++-------------------------------------------
1 files changed, 175 insertions(+), 524 deletions(-)
diff --git a/src/xitongshezhi/lishijilu.java b/src/xitongshezhi/lishijilu.java
index 4765bc8..77cb8ae 100644
--- a/src/xitongshezhi/lishijilu.java
+++ b/src/xitongshezhi/lishijilu.java
@@ -1,379 +1,175 @@
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 JPanel mainPanel;
private JLabel titleLabel;
private JButton backButton;
- // 鎺у埗闈㈡澘缁勪欢
- 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 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.setFont(new Font("Microsoft YaHei", Font.BOLD, 22));
titleLabel.setForeground(TEXT_COLOR);
- titleLabel.setIcon(createIcon("馃摐", 20));
- // 杩斿洖鎸夐挳
- 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);
-
- return panel;
- }
-
- 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; // 琛ㄦ牸涓嶅彲缂栬緫
+ // 杩斿洖鎸夐挳鎮仠鏁堟灉
+ 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);
+ }
+ });
- 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));
+ JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ titlePanel.setOpaque(false);
+ titlePanel.add(titleLabel);
- // 璁剧疆琛ㄥご
- 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)));
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+ buttonPanel.setOpaque(false);
+ buttonPanel.add(backButton);
- // 璁剧疆鍒楀
- historyTable.getColumnModel().getColumn(0).setPreferredWidth(150); // 鏃堕棿
- historyTable.getColumnModel().getColumn(1).setPreferredWidth(80); // 鍗℃Ы缂栧彿
- historyTable.getColumnModel().getColumn(2).setPreferredWidth(60); // 鎿嶄綔
- historyTable.getColumnModel().getColumn(3).setPreferredWidth(80); // 鎿嶄綔瀵硅薄
+ headerPanel.add(titlePanel, BorderLayout.WEST);
+ headerPanel.add(buttonPanel, BorderLayout.EAST);
- // 鑷畾涔夋覆鏌撳櫒
- historyTable.setDefaultRenderer(Object.class, new HistoryTableCellRenderer());
+ return headerPanel;
+ }
+
+ 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)
+ ));
- // 婊氬姩闈㈡澘
- tableScrollPane = new JScrollPane(historyTable);
- tableScrollPane.setBorder(BorderFactory.createEmptyBorder());
- tableScrollPane.getViewport().setBackground(new Color(26, 43, 68, 200));
+ // 鍐呭鏍囬
+ 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)
+ ));
- // 鑷畾涔夋粴鍔ㄦ潯
- JScrollBar verticalScrollBar = tableScrollPane.getVerticalScrollBar();
- verticalScrollBar.setBackground(CARD_COLOR);
- verticalScrollBar.setUnitIncrement(16);
+ JLabel contentTitle = new JLabel("鏃ュ織鍐呭");
+ contentTitle.setFont(new Font("Microsoft YaHei", Font.BOLD, 14));
+ contentTitle.setForeground(TEXT_COLOR);
+
+ 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() {
@@ -381,225 +177,80 @@
backButton.addActionListener(e -> {
dispose();
});
-
- // 鍒锋柊鎸夐挳
- refreshButton.addActionListener(e -> {
- refreshData();
- });
-
- // 娓呯┖鎸夐挳
- clearButton.addActionListener(e -> {
- clearAllRecords();
- });
}
- // 鍘嗗彶璁板綍绫�
- private static class HistoryRecord {
- long id;
- String timestamp;
- int slotId;
- String operation; // "pickup" 鎴� "return"
- int operator; // 0=绯荤粺, 1=绠$悊鍛�
+ // 鍔犺浇鏃ュ織鍐呭
+ private void loadLogContent() {
+ File logFile = new File("log.properties");
- 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;
+ if (!logFile.exists()) {
+ contentTextArea.setText("鏃ュ織鏂囦欢涓嶅瓨鍦ㄣ��");
+ return;
}
- }
-
- // 鍔犺浇婕旂ず鏁版嵁
- 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);
+ Properties logProps = new Properties();
+ try (FileInputStream in = new FileInputStream(logFile)) {
+ logProps.load(in);
- historyRecords.add(new HistoryRecord(
- randomTime,
- new Date(randomTime).toInstant().toString(),
- randomSlot,
- randomOperation,
- randomOperator
- ));
- }
-
- // 鎸夋椂闂存帓搴忥紙鏈�鏂扮殑鍦ㄥ墠闈級
- historyRecords.sort((a, b) -> Long.compare(b.id, a.id));
-
- // 闄愬埗涓烘渶澶ц褰曟暟
- 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)
- });
- }
-
- // 鏇存柊缁熻淇℃伅
- updateStats();
- }
-
- // 鏇存柊缁熻淇℃伅
- 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() {
- int result = JOptionPane.showConfirmDialog(
- this,
- "纭畾瑕佹竻绌烘墍鏈夊巻鍙茶褰曞悧锛熸鎿嶄綔涓嶅彲鎭㈠銆�",
- "纭娓呯┖",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.WARNING_MESSAGE
- );
-
- if (result == JOptionPane.YES_OPTION) {
- historyRecords.clear();
- updateDisplay();
- }
- }
-
- // 娣诲姞娴嬭瘯璁板綍锛堢敤浜庢紨绀猴級
- 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%姒傜巼涓虹鐞嗗憳鎿嶄綔
-
- historyRecords.add(0, new HistoryRecord(
- System.currentTimeMillis(),
- new Date().toInstant().toString(),
- randomSlot,
- randomOperation,
- randomOperator
- ));
-
- // 闄愬埗涓烘渶澶ц褰曟暟
- if (historyRecords.size() > MAX_RECORDS) {
- historyRecords.remove(historyRecords.size() - 1);
- }
-
- 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);
+ // 妫�鏌ヨ褰曟暟閲忥紝濡傛灉瓒呰繃1000鏉″垯鍒犻櫎鏃ц褰�
+ if (logProps.size() > 1000) {
+ trimLogProperties(logProps);
}
- @Override
- public int getIconWidth() {
- return size;
- }
+ // 鏋勫缓鏄剧ず鍐呭
+ StringBuilder content = new StringBuilder();
+ content.append("鏃ュ織鏂囦欢鍐呭 (").append(logProps.size()).append(" 鏉¤褰�):\n\n");
- @Override
- public int getIconHeight() {
- return size;
- }
- };
+ // 鎸夋椂闂存埑鎺掑簭鏄剧ず
+ logProps.stringPropertyNames().stream()
+ .sorted((a, b) -> Long.compare(Long.parseLong(b), Long.parseLong(a)))
+ .forEach(key -> {
+ String value = logProps.getProperty(key);
+ content.append("鏃堕棿鎴�: ").append(key).append("\n");
+ content.append("鍐呭: ").append(value).append("\n");
+ content.append("----------------------------------------\n");
+ });
+
+ contentTextArea.setText(content.toString());
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ contentTextArea.setText("鍔犺浇鏃ュ織鏂囦欢鏃跺嚭閿�: " + e.getMessage());
+ } catch (NumberFormatException e) {
+ contentTextArea.setText("鏃ュ織鏂囦欢鏍煎紡閿欒銆�");
+ }
}
- // 涓绘柟娉曟祴璇�
- public static void main(String[] args) {
- // 璁剧疆绯荤粺澶栬
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeel());
- } catch (Exception e) {
+ // 淇壀鏃ュ織灞炴�э紝鍙繚鐣欐渶鏂扮殑1000鏉¤褰�
+ private void trimLogProperties(Properties logProps) {
+ // 鎸夋椂闂存埑鎺掑簭锛屼繚鐣欐渶鏂扮殑1000鏉�
+ logProps.stringPropertyNames().stream()
+ .sorted((a, b) -> Long.compare(Long.parseLong(b), Long.parseLong(a)))
+ .skip(1000)
+ .forEach(logProps::remove);
+
+ // 淇濆瓨淇壀鍚庣殑灞炴��
+ try (FileOutputStream out = new FileOutputStream("log.properties")) {
+ logProps.store(out, "UWB浜哄憳瀹氫綅鍗″彂鍗℃満鍘嗗彶璁板綍 - 鑷姩淇壀鑷�1000鏉¤褰�");
+ } catch (IOException e) {
e.printStackTrace();
}
-
- SwingUtilities.invokeLater(() -> {
- lishijilu frame = new lishijilu();
- frame.setVisible(true);
- });
}
+
+ // 鏂板杈呭姪鏂规硶锛氫娇棰滆壊鏇翠寒
+ 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