From 5a2312f488185c23e277db46d363cd4b986d03d6 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 31 May 2019 06:08:03 +0100 Subject: [PATCH] show persona and (atm wrong) number of connections --- .../com/muwire/gui/MainFrameModel.groovy | 23 ++++++++++++++++++- .../views/com/muwire/gui/MainFrameView.groovy | 6 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index bf56a627..30e8ba39 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -5,6 +5,9 @@ import javax.inject.Inject import javax.swing.JTable import com.muwire.core.Core +import com.muwire.core.connection.ConnectionAttemptStatus +import com.muwire.core.connection.ConnectionEvent +import com.muwire.core.connection.DisconnectionEvent import com.muwire.core.download.DownloadStartedEvent import com.muwire.core.search.UIResultEvent @@ -24,15 +27,20 @@ class MainFrameModel { @Observable def results = [] @Observable def downloads = [] + @Observable int connections + @Observable String me - private volatile Core core + volatile Core core void mvcGroupInit(Map args) { application.addPropertyChangeListener("core", {e -> coreInitialized = (e.getNewValue() != null) core = e.getNewValue() + me = core.me.getHumanReadableName() core.eventBus.register(UIResultEvent.class, this) core.eventBus.register(DownloadStartedEvent.class, this) + core.eventBus.register(ConnectionEvent.class, this) + core.eventBus.register(DisconnectionEvent.class, this) }) Timer timer = new Timer("download-pumper", true) timer.schedule({ @@ -55,4 +63,17 @@ class MainFrameModel { downloads << e } } + + void onConnectionEvent(ConnectionEvent e) { + runInsideUIAsync { + if (e.status == ConnectionAttemptStatus.SUCCESSFUL) + connections++ + } + } + + void onDisconnectionEvent(DisconnectionEvent e) { + runInsideUIAsync { + connections-- + } + } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 30207987..fef6ca04 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -101,6 +101,12 @@ class MainFrameView { } } panel (border: etchedBorder(), constraints : BorderLayout.SOUTH) { + borderLayout() + label(text : bind {model.me}, constraints: BorderLayout.CENTER) + panel (constraints : BorderLayout.EAST) { + label("Connections:") + label(text : bind {model.connections}) + } } }