add block height to terminal connected label

This commit is contained in:
Craig Raw 2022-11-28 09:43:08 +02:00
parent 3cbe8d1537
commit ff90a2c3e6

View file

@ -67,9 +67,13 @@ public class SparrowTextGui extends MultiWindowTextGUI {
return mainWindow; return mainWindow;
} }
private void setConnectedLabel(boolean connected) { private void setDisconnectedLabel() {
setConnectedLabel(null);
}
private void setConnectedLabel(Integer height) {
getGUIThread().invokeLater(() -> { getGUIThread().invokeLater(() -> {
connectedLabel.setText(connected ? "Connected" : "Disconnected"); connectedLabel.setText(height == null ? "Disconnected" : "Connected at " + height);
}); });
} }
@ -80,24 +84,29 @@ public class SparrowTextGui extends MultiWindowTextGUI {
@Subscribe @Subscribe
public void connectionFailed(ConnectionFailedEvent event) { public void connectionFailed(ConnectionFailedEvent event) {
setConnectedLabel(false); setDisconnectedLabel();
statusUpdated(new StatusEvent("Connection failed: " + event.getMessage())); statusUpdated(new StatusEvent("Connection failed: " + event.getMessage()));
} }
@Subscribe @Subscribe
public void connection(ConnectionEvent event) { public void connection(ConnectionEvent event) {
setConnectedLabel(true); setConnectedLabel(event.getBlockHeight());
statusUpdated(new StatusEvent("Connected to " + Config.get().getServerDisplayName() + " at height " + event.getBlockHeight())); statusUpdated(new StatusEvent("Connected to " + Config.get().getServerDisplayName() + " at height " + event.getBlockHeight()));
} }
@Subscribe @Subscribe
public void disconnection(DisconnectionEvent event) { public void disconnection(DisconnectionEvent event) {
if(!AppServices.isConnecting() && !AppServices.isConnected()) { if(!AppServices.isConnecting() && !AppServices.isConnected()) {
setConnectedLabel(false); setDisconnectedLabel();
statusUpdated(new StatusEvent("Disconnected")); statusUpdated(new StatusEvent("Disconnected"));
} }
} }
@Subscribe
public void newBlock(NewBlockEvent event) {
setConnectedLabel(event.getHeight());
}
@Subscribe @Subscribe
public void statusUpdated(StatusEvent event) { public void statusUpdated(StatusEvent event) {
getGUIThread().invokeLater(() -> statusLabel.setText(event.getStatus())); getGUIThread().invokeLater(() -> statusLabel.setText(event.getStatus()));