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.UDPPortBReceiver;
|
import dell_targets.Dell_BaseStation;
|
import dell_targets.Dell_tag;
|
import publicsWay.UDPPortAReceiver;
|
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();
|
}
|
}
|
}
|