From cf2945630ff533951f0405c18cf3a2d9970292f5 Mon Sep 17 00:00:00 2001 From: liach Date: Mon, 20 Sep 2021 04:28:18 -0500 Subject: Update gradle and skip unnecessary swing updates (#431) update proguard to support java 17 Signed-off-by: liach Co-authored-by: liach --- .../cuchaz/enigma/gui/dialog/SearchDialog.java | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'enigma-swing/src') diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java index 053adad8..e65b661b 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/SearchDialog.java @@ -17,6 +17,7 @@ import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.*; import java.util.*; +import java.util.concurrent.ConcurrentLinkedQueue; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -207,7 +208,31 @@ public class SearchDialog { this.classListModel = classListModel; classList.setModel(classListModel); - currentSearch = su.asyncSearch(searchField.getText(), (idx, e) -> SwingUtilities.invokeLater(() -> classListModel.insertElementAt(e, idx))); + // handle these search result like minecraft scheduled tasks to prevent + // flooding swing buttons inputs etc with tons of (possibly outdated) invocations + record Order(int idx, SearchEntryImpl e) {} + Queue queue = new ConcurrentLinkedQueue<>(); + Runnable updater = new Runnable() { + @Override + public void run() { + if (SearchDialog.this.classListModel != classListModel || !SearchDialog.this.dialog.isVisible()) { + return; + } + + // too large count may increase delay for key and input handling, etc. + int count = 100; + while (count > 0 && !queue.isEmpty()) { + var o = queue.remove(); + classListModel.insertElementAt(o.e, o.idx); + count--; + } + + SwingUtilities.invokeLater(this); + } + }; + + currentSearch = su.asyncSearch(searchField.getText(), (idx, e) -> queue.add(new Order(idx, e))); + SwingUtilities.invokeLater(updater); } public void dispose() { -- cgit v1.2.3