826220679@qq.com
9 天以前 fb883547ede83b1c758b1a9a025898ba3f83497a
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
package window;
 
import java.awt.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
 
import java.util.ResourceBundle;
 
import udptcp.UDPPortAReceiver;
import udptcp.UDPPortBReceiver;
import dell_targets.Dell_BaseStation;
import dell_targets.Dell_tag;
import dell_targets.Dell_SystemConfiguration;
 
public class WelcomeFrame extends JInternalFrame {
    private static final long serialVersionUID = 1L;
    private final ResourceBundle messages;
    private final Connection conn;
    private Timer statsTimer;
    private JLabel memoryUsageLabel;
    private JLabel threadCountLabel;
    private JLabel tagStatsLabel;
    private JLabel baseStationStatsLabel;
    private JLabel dbVersionLabel;
    private JLabel udpAInfoLabel;
    private JLabel udpBInfoLabel;
 
    public WelcomeFrame(ResourceBundle messages, Connection conn) {
        super("", true, true, true, true);
        this.messages = messages;
        this.conn = conn;
        
        initializeFrame();
        setContentPane(createWelcomePanel());
        startStatsTimer();
    }
 
    private void initializeFrame() {
        setSize(900, 700);
        setLocation(100, 100);
        setMaximizable(true);
        setIconifiable(true);
        setClosable(true);
        setBorder(null);
        
        // ÒƳý±êÌâÀ¸
        ((javax.swing.plaf.basic.BasicInternalFrameUI)this.getUI()).setNorthPane(null);
        
        try {
            setMaximum(true);
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace();
        }
        
        setVisible(true); // È·±£¿ò¼Ü¿É¼û
    }
 
    private JPanel createWelcomePanel() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(new EmptyBorder(30, 30, 30, 30));
        panel.setBackground(new Color(245, 248, 255));
        
        // ±êÌâÃæ°å
        JPanel titlePanel = new JPanel(new BorderLayout());
        titlePanel.setOpaque(false);
        titlePanel.setBorder(new EmptyBorder(0, 0, 30, 0));
        
        JLabel titleLabel = new JLabel(messages.getString("APP_NAME"), SwingConstants.CENTER);
        titleLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 42));
        titleLabel.setForeground(new Color(25, 25, 112));
        
        JLabel subtitleLabel = new JLabel(messages.getString("WELCOME_MSG"), SwingConstants.CENTER);
        subtitleLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.ITALIC, 22));
        subtitleLabel.setForeground(new Color(70, 130, 180));
        subtitleLabel.setBorder(new EmptyBorder(10, 0, 20, 0));
        
        titlePanel.add(titleLabel, BorderLayout.NORTH);
        titlePanel.add(subtitleLabel, BorderLayout.CENTER);
        
        // Ö÷ÐÅÏ¢Ãæ°å
        JPanel infoPanel = new JPanel(new GridBagLayout());
        infoPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(new Color(200, 220, 240), 2),
            new EmptyBorder(30, 40, 30, 40)
        ));
        infoPanel.setBackground(new Color(255, 255, 255, 255));
        infoPanel.setOpaque(true);
        
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(15, 15, 15, 15);
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        
        // µÚÒ»ÁÐ
        gbc.gridx = 0;
        gbc.gridy = 0;
        
        // ÐÞ¸´1: ³õʼ»¯±êÇ©²¢ÉèÖóõʼÎı¾
        tagStatsLabel = new JLabel("0 / 0");
        tagStatsLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("TAG_STATS"), tagStatsLabel, new Color(0, 100, 0)), gbc);
        
        gbc.gridy++;
        baseStationStatsLabel = new JLabel("0 / 0");
        baseStationStatsLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("BASE_STATION_STATS"), baseStationStatsLabel, new Color(0, 100, 0)), gbc);
        
        gbc.gridy++;
        udpAInfoLabel = new JLabel(Dell_SystemConfiguration.hexport + " - " + messages.getString("RECEIVED_PACKETS") + ": 0");
        udpAInfoLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("UDP_PORT_A"), udpAInfoLabel, new Color(178, 34, 34)), gbc);
        
        gbc.gridy++;
        udpBInfoLabel = new JLabel(Dell_SystemConfiguration.ascallport + " - " + messages.getString("RECEIVED_PACKETS") + ": 0");
        udpBInfoLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("UDP_PORT_B"), udpBInfoLabel, new Color(178, 34, 34)), gbc);
        
        gbc.gridy++;
        memoryUsageLabel = new JLabel("0 MB / 0 MB");
        memoryUsageLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("MEMORY_USAGE"), memoryUsageLabel, new Color(148, 0, 211)), gbc);
        
        // µÚ¶þÁÐ
        gbc.gridx = 1;
        gbc.gridy = 0;
        threadCountLabel = new JLabel("0");
        threadCountLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("THREAD_COUNT"), threadCountLabel, new Color(148, 0, 211)), gbc);
        
        gbc.gridy++;
        dbVersionLabel = new JLabel(""); // ³õʼΪ¿Õ£¬ÉÔºóÉèÖÃ
        dbVersionLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("DB_VERSION"), dbVersionLabel, new Color(25, 25, 112)), gbc);
        
        gbc.gridy++;
        JLabel dbStatusLabel = new JLabel(conn != null ? messages.getString("CONNECTED") : messages.getString("DISCONNECTED"));
        dbStatusLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        dbStatusLabel.setForeground(conn != null ? new Color(0, 100, 0) : Color.RED);
        infoPanel.add(createInfoRow(messages.getString("DB_STATUS"), dbStatusLabel, new Color(25, 25, 112)), gbc);
        
        gbc.gridy++;
        JLabel softwareVersionLabel = new JLabel(messages.getString("APP_VERSION"));
        softwareVersionLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        infoPanel.add(createInfoRow(messages.getString("SOFTWARE_VERSION"), softwareVersionLabel, new Color(25, 25, 112)), gbc);
        
        // ³õʼ»¯Êý¾Ý¿â°æ±¾
        if (conn != null && dbVersionLabel.getText().isEmpty()) {
            updateDbVersion();
        }
        
        // ×é×°Ö÷Ãæ°å
        panel.add(titlePanel, BorderLayout.NORTH);
        panel.add(infoPanel, BorderLayout.CENTER);
        
        return panel;
    }
 
    private JPanel createInfoRow(String title, JLabel valueLabel, Color color) {
        JPanel rowPanel = new JPanel(new BorderLayout(10, 0));
        rowPanel.setOpaque(false);
        
        JLabel titleLabel = new JLabel(title + ":");
        titleLabel.setFont(new Font(messages.getString("FONT_NAME"), Font.BOLD, 18));
        titleLabel.setForeground(color.darker());
        
        valueLabel.setForeground(color);
        
        rowPanel.add(titleLabel, BorderLayout.WEST);
        rowPanel.add(valueLabel, BorderLayout.CENTER);
        
        // Ìí¼Ó×°ÊÎÆ÷
        JPanel decorator = new JPanel();
        decorator.setPreferredSize(new Dimension(5, 5));
        decorator.setBackground(color);
        decorator.setOpaque(true);
        rowPanel.add(decorator, BorderLayout.EAST);
        
        return rowPanel;
    }
    
    private void updateDbVersion() {
        if (conn != null) {
            try (Statement stmt = conn.createStatement();
                 ResultSet rs = stmt.executeQuery("SELECT VERSION()")) {
                if (rs.next()) {
                    dbVersionLabel.setText(rs.getString(1));
                }
            } catch (Exception ex) {
                dbVersionLabel.setText("N/A");
            }
        }
    }
    
    private void startStatsTimer() {
        statsTimer = new Timer(1000, e -> {
            // ¸üÐÂUDP¶Ë¿ÚAÐÅÏ¢
            int packetCountA = (int) UDPPortAReceiver.getPacketCount();
            udpAInfoLabel.setText(Dell_SystemConfiguration.hexport + " - " + 
                                 messages.getString("RECEIVED_PACKETS") + ": " + packetCountA);
            
            // ¸üÐÂUDP¶Ë¿ÚBÐÅÏ¢
            int packetCountB = (int) UDPPortBReceiver.getPacketCount();
            udpBInfoLabel.setText(Dell_SystemConfiguration.ascallport + " - " + 
                                  messages.getString("RECEIVED_PACKETS") + ": " + packetCountB);
            
            // ¸üÐÂÄÚ´æÊ¹ÓÃÇé¿ö
            Runtime runtime = Runtime.getRuntime();
            long usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024);
            long maxMemory = runtime.maxMemory() / (1024 * 1024);
            memoryUsageLabel.setText(usedMemory + " " + messages.getString("MB") + " / " + 
                                    maxMemory + " " + messages.getString("MB"));
            
            // ¸üÐÂÏß³ÌÊý
            threadCountLabel.setText(String.valueOf(Thread.activeCount()));
            
            // ¸üбêǩ״̬
            int onlineTags = Dell_tag.getOnlineLocationTags().size();
            int totalTags = Dell_tag.getLocationTagCount();
            tagStatsLabel.setText(onlineTags + " / " + totalTags);
            
            // ¸üлùվ״̬
            int onlineStations = Dell_BaseStation.getOnlineBaseStations().size();
            int totalStations = Dell_BaseStation.getLocationBaseCount();
            baseStationStatsLabel.setText(onlineStations + " / " + totalStations);
        });
        statsTimer.start();
    }
    
    @Override
    public void dispose() {
        super.dispose();
        if (statsTimer != null) {
            statsTimer.stop();
        }
    }
}