incoming searches monitor

This commit is contained in:
Zlatin Balevsky
2019-06-01 13:44:46 +01:00
parent 9dac1891b2
commit 1996681677
2 changed files with 41 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.files.FileHashedEvent
import com.muwire.core.files.FileLoadedEvent
import com.muwire.core.files.FileSharedEvent
import com.muwire.core.search.QueryEvent
import com.muwire.core.search.UIResultEvent
import com.muwire.core.trust.TrustEvent
import com.muwire.core.trust.TrustService
@ -42,6 +43,7 @@ class MainFrameModel {
def uploads = []
def shared = []
def connectionList = []
def searches = new LinkedList()
@Observable int connections
@Observable String me
@ -65,6 +67,7 @@ class MainFrameModel {
core.eventBus.register(UploadEvent.class, this)
core.eventBus.register(UploadFinishedEvent.class, this)
core.eventBus.register(TrustEvent.class, this)
core.eventBus.register(QueryEvent.class, this)
})
Timer timer = new Timer("download-pumper", true)
timer.schedule({
@ -153,4 +156,22 @@ class MainFrameModel {
table.model.fireTableDataChanged()
}
}
void onQueryEvent(QueryEvent e) {
StringBuilder sb = new StringBuilder()
e.searchEvent.searchTerms?.each {
sb.append(it)
sb.append(" ")
}
def search = sb.toString()
if (search.trim().size() == 0)
return
runInsideUIAsync {
searches.addFirst(search)
while(searches.size() > 200)
searches.removeLast()
JTable table = builder.getVariable("searches-table")
table.model.fireTableDataChanged()
}
}
}

View File

@ -134,12 +134,26 @@ class MainFrameView {
}
}
panel (constraints: "monitor window") {
borderLayout()
label("Connections", constraints : BorderLayout.NORTH)
scrollPane(constraints : BorderLayout.CENTER) {
table(id : "connections-table") {
tableModel(list : model.connectionList) {
closureColumn(header : "Destination", type: String, read : { row -> row.toBase32() })
gridLayout(rows : 1, cols : 2)
panel {
borderLayout()
label("Connections", constraints : BorderLayout.NORTH)
scrollPane(constraints : BorderLayout.CENTER) {
table(id : "connections-table") {
tableModel(list : model.connectionList) {
closureColumn(header : "Destination", type: String, read : { row -> row.toBase32() })
}
}
}
}
panel {
borderLayout()
label("Incoming searches", constraints : BorderLayout.NORTH)
scrollPane(constraints : BorderLayout.CENTER) {
table(id : "searches-table") {
tableModel(list : model.searches) {
closureColumn(header : "Keywords", type : String, read : { it })
}
}
}
}