import nxt.http.API; //导入依赖的package包/类
private void displayStatus() {
Block lastBlock = Nxt.getBlockchain().getLastBlock();
Collection<Generator> allGenerators = Generator.getAllGenerators();
StringBuilder generators = new StringBuilder();
for (Generator generator : allGenerators) {
generators.append(Convert.rsAccount(generator.getAccountId())).append(' ');
}
Object optionPaneBackground = UIManager.get("OptionPane.background");
UIManager.put("OptionPane.background", Color.WHITE);
Object panelBackground = UIManager.get("Panel.background");
UIManager.put("Panel.background", Color.WHITE);
Object textFieldBackground = UIManager.get("TextField.background");
UIManager.put("TextField.background", Color.WHITE);
Container statusPanelParent = null;
if (statusDialog != null && statusPanel != null) {
statusPanelParent = statusPanel.getParent();
statusPanelParent.remove(statusPanel);
}
statusPanel = new JPanel();
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.Y_AXIS));
addLabelRow(statusPanel, "Installation");
addDataRow(statusPanel, "Application", Nxt.APPLICATION);
addDataRow(statusPanel, "Version", Nxt.VERSION);
addDataRow(statusPanel, "Network", (Constants.isTestnet) ? "TestNet" : "MainNet");
addDataRow(statusPanel, "Working offline", "" + Constants.isOffline);
addDataRow(statusPanel, "Wallet", String.valueOf(API.getBrowserUri()));
addDataRow(statusPanel, "Peer port", String.valueOf(Peers.getDefaultPeerPort()));
addDataRow(statusPanel, "Program folder", String.valueOf(Paths.get(".").toAbsolutePath().getParent()));
addDataRow(statusPanel, "User folder", String.valueOf(Paths.get(Nxt.getUserHomeDir()).toAbsolutePath()));
addDataRow(statusPanel, "Database URL", Db.db == null ? "unavailable" : Db.db.getUrl());
addEmptyRow(statusPanel);
if (lastBlock != null) {
addLabelRow(statusPanel, "Last Block");
addDataRow(statusPanel, "Height", String.valueOf(lastBlock.getHeight()));
addDataRow(statusPanel, "Timestamp", String.valueOf(lastBlock.getTimestamp()));
addDataRow(statusPanel, "Time", String.valueOf(new Date(Convert.fromEpochTime(lastBlock.getTimestamp()))));
addDataRow(statusPanel, "Seconds passed", String.valueOf(Nxt.getEpochTime() - lastBlock.getTimestamp()));
addDataRow(statusPanel, "Forging", String.valueOf(allGenerators.size() > 0));
if (allGenerators.size() > 0) {
addDataRow(statusPanel, "Forging accounts", generators.toString());
}
}
addEmptyRow(statusPanel);
addLabelRow(statusPanel, "Environment");
addDataRow(statusPanel, "Number of peers", String.valueOf(Peers.getAllPeers().size()));
addDataRow(statusPanel, "Available processors", String.valueOf(Runtime.getRuntime().availableProcessors()));
addDataRow(statusPanel, "Max memory", humanReadableByteCount(Runtime.getRuntime().maxMemory()));
addDataRow(statusPanel, "Total memory", humanReadableByteCount(Runtime.getRuntime().totalMemory()));
addDataRow(statusPanel, "Free memory", humanReadableByteCount(Runtime.getRuntime().freeMemory()));
addDataRow(statusPanel, "Process id", Nxt.getProcessId());
addEmptyRow(statusPanel);
addDataRow(statusPanel, "Updated", dateFormat.format(new Date()));
if (statusDialog == null || !statusDialog.isVisible()) {
JOptionPane pane = new JOptionPane(statusPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, imageIcon);
statusDialog = pane.createDialog(wrapper, "Horizon Server Status");
statusDialog.setVisible(true);
statusDialog.dispose();
} else {
if (statusPanelParent != null) {
statusPanelParent.add(statusPanel);
statusPanelParent.revalidate();
}
statusDialog.getContentPane().validate();
statusDialog.getContentPane().repaint();
EventQueue.invokeLater(statusDialog::toFront);
}
UIManager.put("OptionPane.background", optionPaneBackground);
UIManager.put("Panel.background", panelBackground);
UIManager.put("TextField.background", textFieldBackground);
}
请发表评论