show persona and (atm wrong) number of connections

This commit is contained in:
Zlatin Balevsky
2019-05-31 06:08:03 +01:00
parent 1944e33e79
commit 5a2312f488
2 changed files with 28 additions and 1 deletions

View File

@@ -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<String, Object> 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--
}
}
}

View File

@@ -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})
}
}
}