From 1bda9524add969e315d870f284046ecf1097f956 Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期日, 24 八月 2025 18:01:25 +0800
Subject: [PATCH] 修改

---
 src/dell_anchor/BaseStationManagementPanel.java |  186 +++++++++++++++++++++++++---------------------
 1 files changed, 100 insertions(+), 86 deletions(-)

diff --git a/src/dell_anchor/BaseStationManagementPanel.java b/src/dell_anchor/BaseStationManagementPanel.java
index c9625ad..9f6cbd6 100644
--- a/src/dell_anchor/BaseStationManagementPanel.java
+++ b/src/dell_anchor/BaseStationManagementPanel.java
@@ -1,11 +1,13 @@
 package dell_anchor;
 
 import databases.DBConnector;
+import dell_targets.Dell_BaseStation;
+import publicsWay.ButtonUtils;
+import publicsWay.TableUtils;
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;
 import javax.swing.table.*;
 import java.awt.*;
-import java.awt.event.*;
 import java.sql.SQLException;
 import java.util.*;
 import java.util.List;
@@ -26,49 +28,56 @@
         setLayout(new BorderLayout());
         setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
         
-        // 创建搜索面板
-        JPanel searchPanel = new JPanel(new BorderLayout(5, 5));
-        searchPanel.setBorder(BorderFactory.createTitledBorder(getMessage("SEARCH")));
+        // 顶部操作面板
+        JPanel topPanel = new JPanel(new BorderLayout(5, 5));
+        topPanel.setBorder(BorderFactory.createTitledBorder(messages.getString("QUICK_OPERATION")));
         
-        // 创建搜索组件
+        // 搜索面板
+        JPanel searchInputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
+        JLabel searchLabel = new JLabel(messages.getString("BASE_STATION_ID") + ":");
         searchField = new JTextField(15);
-        JButton searchButton = new JButton(getMessage("SEARCH"));
-        JButton refreshButton = new JButton(getMessage("REFRESH"));
-        JButton addButton = new JButton(getMessage("ADD"));
-        JButton editButton = new JButton(getMessage("EDIT"));
-        JButton deleteButton = new JButton(getMessage("DELETE"));
-        refreshButton.addActionListener(e -> loadBaseStationData());
-
-        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
-        buttonPanel.add(searchButton);
-        buttonPanel.add(refreshButton);
-        buttonPanel.add(addButton);
-        buttonPanel.add(editButton);
-        buttonPanel.add(deleteButton);
-
-        searchPanel.add(searchField, BorderLayout.CENTER);
-        searchPanel.add(buttonPanel, BorderLayout.EAST);
         
-        // 添加按钮事件监听器
-        addButton.addActionListener(e -> addNewBaseStation());
-        editButton.addActionListener(e -> editSelectedBaseStation());
-        deleteButton.addActionListener(e -> deleteSelectedBaseStations());
-        searchButton.addActionListener(new SearchAction());
-       
+        // 使用ButtonUtils创建蓝色按钮
+        JButton searchButton = ButtonUtils.createBlueButton(messages.getString("SEARCH"));
+        JButton resetButton = ButtonUtils.createBlueButton(messages.getString("RESET"));
+        JButton refreshButton = ButtonUtils.createBlueButton(messages.getString("REFRESH"));
+        JButton addButton = ButtonUtils.createBlueButton(messages.getString("ADD"));
+        JButton editButton = ButtonUtils.createBlueButton(messages.getString("EDIT"));
+        JButton deleteButton = ButtonUtils.createBlueButton(messages.getString("DELETE"));
+
+        searchInputPanel.add(searchLabel);
+        searchInputPanel.add(searchField);
+        searchInputPanel.add(searchButton);
+        searchInputPanel.add(resetButton);
+        searchInputPanel.add(refreshButton);
+        
+        // 操作按钮面板
+        JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
+        actionPanel.add(addButton);
+        actionPanel.add(editButton);
+        actionPanel.add(deleteButton);
+
+        // 将搜索面板和操作按钮面板放在一行
+        JPanel rowPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
+        rowPanel.add(searchInputPanel);
+        rowPanel.add(actionPanel);
+
+        topPanel.add(rowPanel, BorderLayout.CENTER);
+        
         // 创建表格列名
         String[] columnNames = {
-            getMessage("INDEX"),
-            getMessage("BASE_STATION_ID"), 
-            getMessage("BASE_STATION_STATUS"), 
-            getMessage("X_COORD"), 
-            getMessage("Y_COORD"), 
-            getMessage("Z_COORD"), 
-            getMessage("LAYER"), 
-            getMessage("GROUP"), 
-            getMessage("PORT"), 
-            getMessage("FIRMWARE_VERSION"), 
-            getMessage("ONLINE_TIME"), 
-            getMessage("COMPANY")
+            messages.getString("INDEX"),
+            messages.getString("BASE_STATION_ID"), 
+            messages.getString("BASE_STATION_STATUS"), 
+            messages.getString("X_COORD"), 
+            messages.getString("Y_COORD"), 
+            messages.getString("Z_COORD"), 
+            messages.getString("LAYER"), 
+            messages.getString("GROUP"), 
+            messages.getString("PORT"), 
+            messages.getString("FIRMWARE_VERSION"), 
+            messages.getString("ONLINE_TIME"), 
+            messages.getString("COMPANY")
         };
         
         // 创建表格模型
@@ -79,14 +88,16 @@
             }
         };
         
-        // 创建表格
+        // 创建表格 - 使用TableUtils中的方法
         baseStationTable = new JTable(tableModel);
+        TableUtils.setupTableStyle(baseStationTable);
+        TableUtils.setupTableHeaderStyle(baseStationTable);
         baseStationTable.setAutoCreateRowSorter(true);
         baseStationTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
         
         // 设置列宽
         TableColumnModel columnModel = baseStationTable.getColumnModel();
-        columnModel.getColumn(0).setPreferredWidth(30);  // 序号
+        columnModel.getColumn(0).setPreferredWidth(30);  // 索引
         columnModel.getColumn(1).setPreferredWidth(100); // 基站编号
         columnModel.getColumn(2).setPreferredWidth(70);  // 状态
         columnModel.getColumn(3).setPreferredWidth(70);  // X坐标
@@ -99,31 +110,30 @@
         columnModel.getColumn(10).setPreferredWidth(120); // 上线时间
         columnModel.getColumn(11).setPreferredWidth(100); // 所属公司
         
-        // 设置表头样式
-        JTableHeader header = baseStationTable.getTableHeader();
-        // 设置表头左对齐
-        header.setDefaultRenderer(new DefaultTableCellRenderer() {
-            @Override
-            public Component getTableCellRendererComponent(JTable table, Object value,
-                    boolean isSelected, boolean hasFocus, int row, int column) {
-                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-                setHorizontalAlignment(SwingConstants.LEFT);
-                setBackground(Color.GRAY);
-                setForeground(Color.WHITE);
-                setFont(getFont().deriveFont(Font.BOLD));
-                return this;
-            }
-        });
+        // 应用单元格渲染器到所有列 - 使用TableUtils中的方法
+        DefaultTableCellRenderer cellRenderer = TableUtils.createCenteredCellRenderer();
+        for (int i = 0; i < baseStationTable.getColumnCount(); i++) {
+            baseStationTable.getColumnModel().getColumn(i).setCellRenderer(cellRenderer);
+        }
         
         JScrollPane scrollPane = new JScrollPane(baseStationTable);
         scrollPane.setPreferredSize(new Dimension(1200, 500));
+        scrollPane.setBorder(BorderFactory.createEmptyBorder()); // 移除滚动面板边框
         
         // 添加组件
-        add(searchPanel, BorderLayout.NORTH);
+        add(topPanel, BorderLayout.NORTH);
         add(scrollPane, BorderLayout.CENTER);
         
         // 加载数据
         loadBaseStationData();
+        
+        // 添加事件监听器
+        searchButton.addActionListener(e -> searchBaseStations());
+        resetButton.addActionListener(e -> resetSearch());
+        refreshButton.addActionListener(e -> loadBaseStationData());
+        addButton.addActionListener(e -> addNewBaseStation());
+        editButton.addActionListener(e -> editSelectedBaseStation());
+        deleteButton.addActionListener(e -> deleteSelectedBaseStations());
     }
     
     private void loadBaseStationData() {
@@ -161,6 +171,36 @@
                 bs.getCompany()
             });
         }
+    }
+    
+    // 搜索基站
+    private void searchBaseStations() {
+        String keyword = searchField.getText().trim();
+        if (keyword.isEmpty()) {
+            updateTable(allBaseStations);
+            return;
+        }
+
+        List<LocationBaseStation> filtered = new ArrayList<>();
+        for (LocationBaseStation bs : allBaseStations) {
+            if ((bs.getCode() != null && bs.getCode().toLowerCase().contains(keyword.toLowerCase())) ||
+                (bs.getCompany() != null && bs.getCompany().toLowerCase().contains(keyword.toLowerCase()))) {
+                filtered.add(bs);
+            }
+        }
+
+        if (filtered.isEmpty()) {
+            JOptionPane.showMessageDialog(this, getMessage("SEARCH_NO_RESULTS"),
+                    getMessage("INFO"), JOptionPane.INFORMATION_MESSAGE);
+        }
+
+        updateTable(filtered);
+    }
+    
+    // 重置搜索
+    private void resetSearch() {
+        searchField.setText("");
+        updateTable(allBaseStations);
     }
     
     // 添加新基站
@@ -270,7 +310,7 @@
             return false;
         }
         
-        // HEX格式验证(0-9, A-F)
+        // HEX格式验证(0-9, A-F)
         if (!Pattern.matches("[0-9A-Fa-f]+", bs.getCode())) {
             JOptionPane.showMessageDialog(this, getMessage("INVALID_HEX_FORMAT"),
                                         getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);
@@ -444,32 +484,6 @@
         return result > 0;
     }
     
-    // 搜索功能
-    private class SearchAction implements ActionListener {
-        @Override
-        public void actionPerformed(ActionEvent e) {
-            String keyword = searchField.getText().trim();
-            if (keyword.isEmpty()) {
-                updateTable(allBaseStations);
-                return;
-            }
-            
-            List<LocationBaseStation> filteredList = new ArrayList<>();
-            for (LocationBaseStation bs : allBaseStations) {
-                if (matchesKeyword(bs, keyword)) {
-                    filteredList.add(bs);
-                }
-            }
-            
-            updateTable(filteredList);
-        }
-        
-        private boolean matchesKeyword(LocationBaseStation bs, String keyword) {
-            return (bs.getCode() != null && bs.getCode().contains(keyword)) ||
-                   (bs.getCompany() != null && bs.getCompany().contains(keyword));
-        }
-    }
-    
     private String getMessage(String key) {
         try {
             return messages.getString(key);
@@ -578,8 +592,8 @@
 
         // 按钮面板
         JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        JButton okButton = new JButton(messages.getString("OK"));
-        JButton cancelButton = new JButton(messages.getString("CANCEL"));
+        JButton okButton = ButtonUtils.createBlueButton(messages.getString("OK"));
+        JButton cancelButton = ButtonUtils.createBlueButton(messages.getString("CANCEL"));
 
         okButton.addActionListener(e -> {
             confirmed = true;

--
Gitblit v1.9.3