count hopeless and failing hosts, prettier status panel
This commit is contained in:
@@ -105,6 +105,22 @@ class HostCache extends Service {
|
|||||||
Collections.shuffle(rv)
|
Collections.shuffle(rv)
|
||||||
rv[0..n-1]
|
rv[0..n-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int countFailingHosts() {
|
||||||
|
List<Destination> rv = new ArrayList<>(hosts.keySet())
|
||||||
|
rv.retainAll {
|
||||||
|
hosts[it].isFailed()
|
||||||
|
}
|
||||||
|
rv.size()
|
||||||
|
}
|
||||||
|
|
||||||
|
int countHopelessHosts() {
|
||||||
|
List<Destination> rv = new ArrayList<>(hosts.keySet())
|
||||||
|
rv.retainAll {
|
||||||
|
hosts[it].isHopeless()
|
||||||
|
}
|
||||||
|
rv.size()
|
||||||
|
}
|
||||||
|
|
||||||
void load() {
|
void load() {
|
||||||
if (storage.exists()) {
|
if (storage.exists()) {
|
||||||
|
@@ -31,6 +31,9 @@ class MuWireStatusController {
|
|||||||
model.outgoingConnections = outgoing
|
model.outgoingConnections = outgoing
|
||||||
|
|
||||||
model.knownHosts = core.hostCache.hosts.size()
|
model.knownHosts = core.hostCache.hosts.size()
|
||||||
|
model.failingHosts = core.hostCache.countFailingHosts()
|
||||||
|
model.hopelessHosts = core.hostCache.countHopelessHosts()
|
||||||
|
|
||||||
|
|
||||||
model.sharedFiles = core.fileManager.fileToSharedFile.size()
|
model.sharedFiles = core.fileManager.fileToSharedFile.size()
|
||||||
|
|
||||||
|
@@ -16,6 +16,8 @@ class MuWireStatusModel {
|
|||||||
@Observable int incomingConnections
|
@Observable int incomingConnections
|
||||||
@Observable int outgoingConnections
|
@Observable int outgoingConnections
|
||||||
@Observable int knownHosts
|
@Observable int knownHosts
|
||||||
|
@Observable int failingHosts
|
||||||
|
@Observable int hopelessHosts
|
||||||
@Observable int sharedFiles
|
@Observable int sharedFiles
|
||||||
@Observable int downloads
|
@Observable int downloads
|
||||||
|
|
||||||
|
@@ -7,10 +7,12 @@ import griffon.metadata.ArtifactProviderFor
|
|||||||
import javax.swing.JDialog
|
import javax.swing.JDialog
|
||||||
import javax.swing.JPanel
|
import javax.swing.JPanel
|
||||||
import javax.swing.SwingConstants
|
import javax.swing.SwingConstants
|
||||||
|
import javax.swing.border.TitledBorder
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
|
import java.awt.GridBagConstraints
|
||||||
import java.awt.event.WindowAdapter
|
import java.awt.event.WindowAdapter
|
||||||
import java.awt.event.WindowEvent
|
import java.awt.event.WindowEvent
|
||||||
|
|
||||||
@@ -35,16 +37,32 @@ class MuWireStatusView {
|
|||||||
|
|
||||||
panel = builder.panel {
|
panel = builder.panel {
|
||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
label(text : "Incoming connections", constraints : gbc(gridx:0, gridy:0))
|
panel(border : titledBorder(title : "Connections", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
||||||
label(text : bind {model.incomingConnections}, constraints : gbc(gridx:1, gridy:0))
|
constraints : gbc(gridx : 0, gridy: 0, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
|
||||||
label(text : "Outgoing connections", constraints : gbc(gridx:0, gridy:1))
|
gridBagLayout()
|
||||||
label(text : bind {model.outgoingConnections}, constraints : gbc(gridx:1, gridy:1))
|
label(text : "Incoming", constraints : gbc(gridx:0, gridy:0, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
label(text : "Known hosts", constraints : gbc(gridx:0, gridy:2))
|
label(text : bind {model.incomingConnections}, constraints : gbc(gridx:1, gridy:0, anchor : GridBagConstraints.LINE_END))
|
||||||
label(text : bind {model.knownHosts}, constraints : gbc(gridx:1, gridy:2))
|
label(text : "Outgoing", constraints : gbc(gridx:0, gridy:1, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
label(text : "Shared files", constraints : gbc(gridx:0, gridy:3))
|
label(text : bind {model.outgoingConnections}, constraints : gbc(gridx:1, gridy:1, anchor : GridBagConstraints.LINE_END))
|
||||||
label(text : bind {model.sharedFiles}, constraints : gbc(gridx:1, gridy:3))
|
}
|
||||||
label(text : "Downloads", constraints : gbc(gridx:0, gridy:4))
|
panel(border : titledBorder(title : "Hosts", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
||||||
label(text : bind {model.downloads}, constraints : gbc(gridx:1, gridy:4))
|
constraints : gbc(gridx : 0, gridy : 1, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
|
||||||
|
gridBagLayout()
|
||||||
|
label(text : "Known", constraints : gbc(gridx:0, gridy:0, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
|
label(text : bind {model.knownHosts}, constraints : gbc(gridx:1, gridy:0, anchor : GridBagConstraints.LINE_END))
|
||||||
|
label(text : "Failing", constraints : gbc(gridx:0, gridy:1, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
|
label(text : bind {model.failingHosts}, constraints : gbc(gridx:1, gridy:1, anchor : GridBagConstraints.LINE_END))
|
||||||
|
label(text : "Hopeless", constraints : gbc(gridx:0, gridy:2, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
|
label(text : bind {model.hopelessHosts}, constraints : gbc(gridx:1, gridy:2, anchor : GridBagConstraints.LINE_END))
|
||||||
|
}
|
||||||
|
panel(border : titledBorder(title : "Files", border : etchedBorder(), titlePosition : TitledBorder.TOP),
|
||||||
|
constraints : gbc(gridx : 0, gridy : 2, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) {
|
||||||
|
gridBagLayout()
|
||||||
|
label(text : "Shared", constraints : gbc(gridx:0, gridy:0, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
|
label(text : bind {model.sharedFiles}, constraints : gbc(gridx:1, gridy:0, anchor : GridBagConstraints.LINE_END))
|
||||||
|
label(text : "Downloading", constraints : gbc(gridx:0, gridy:1, anchor : GridBagConstraints.LINE_START, weightx : 100))
|
||||||
|
label(text : bind {model.downloads}, constraints : gbc(gridx:1, gridy:1, anchor : GridBagConstraints.LINE_END))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buttonsPanel = builder.panel {
|
buttonsPanel = builder.panel {
|
||||||
gridBagLayout()
|
gridBagLayout()
|
||||||
@@ -60,7 +78,8 @@ class MuWireStatusView {
|
|||||||
statusPanel.add(buttonsPanel, BorderLayout.SOUTH)
|
statusPanel.add(buttonsPanel, BorderLayout.SOUTH)
|
||||||
|
|
||||||
dialog.getContentPane().add(statusPanel)
|
dialog.getContentPane().add(statusPanel)
|
||||||
dialog.pack()
|
dialog.setSize(200,300)
|
||||||
|
dialog.setResizable(false)
|
||||||
dialog.setLocationRelativeTo(mainFrame)
|
dialog.setLocationRelativeTo(mainFrame)
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||||
dialog.addWindowListener(new WindowAdapter() {
|
dialog.addWindowListener(new WindowAdapter() {
|
||||||
|
Reference in New Issue
Block a user