From 41181616eed98dfc1489d0d6a653830d428207bd Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 4 Jul 2019 17:59:53 +0100 Subject: [PATCH] compact display of incoming searches, thanks Aegon --- .../com/muwire/gui/MainFrameModel.groovy | 39 ++++++++++++++++++- .../views/com/muwire/gui/MainFrameView.groovy | 8 ++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 60fc5d36..02eb6ffa 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -1,6 +1,8 @@ package com.muwire.gui import java.util.concurrent.ConcurrentHashMap +import java.util.Calendar +import java.util.UUID import javax.annotation.Nonnull import javax.inject.Inject @@ -360,10 +362,31 @@ class MainFrameModel { return } runInsideUIAsync { - searches.addFirst(new IncomingSearch(search : search, replyTo : e.replyTo, originator : e.originator)) + JTable table = builder.getVariable("searches-table") + + Boolean searchFound = false + Iterator searchIter = searches.iterator() + while ( searchIter.hasNext() ) { + IncomingSearch searchEle = searchIter.next() + if ( searchEle.search == search + && searchEle.originator == e.originator + && searchEle.uuid == e.searchEvent.getUuid() ) { + searchIter.remove() + table.model.fireTableDataChanged() + searchFound = true + searchEle.count++ + searchEle.timestamp = Calendar.getInstance() + searches.addFirst(searchEle) + } + } + + if (!searchFound) { + searches.addFirst(new IncomingSearch(search, e.replyTo, e.originator, e.searchEvent.getUuid())) + } + while(searches.size() > 200) searches.removeLast() - JTable table = builder.getVariable("searches-table") + table.model.fireTableDataChanged() } } @@ -372,6 +395,18 @@ class MainFrameModel { String search Destination replyTo Persona originator + long count + UUID uuid + Calendar timestamp + + IncomingSearch( String search, Destination replyTo, Persona originator, UUID uuid ) { + this.search = search + this.replyTo = replyTo + this.originator = originator + this.uuid = uuid + this.count = 1 + this.timestamp = Calendar.getInstance() + } } void onUpdateAvailableEvent(UpdateAvailableEvent e) { diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 9c751b67..48a771c8 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -265,6 +265,14 @@ class MainFrameView { return it.replyTo.toBase32() } }) + closureColumn(header : "Count", type : String, read : { + it.count.toString() + }) + closureColumn(header : "Timestamp", type : String, read : { + String.format("%02d", it.timestamp.get(Calendar.HOUR_OF_DAY)) + ":" + + String.format("%02d", it.timestamp.get(Calendar.MINUTE)) + ":" + + String.format("%02d", it.timestamp.get(Calendar.SECOND)) + }) } } }