diff src/name/blackcap/clipman/PasteboardQueue.kt @ 16:88703ca72fc3

Make an efficiency improvement: cache the scrollPane.
author David Barts <n5jrn@me.com>
date Tue, 21 Jan 2020 13:07:35 -0800
parents d832c7b2bfd0
children c10a447b9e1b
line wrap: on
line diff
--- a/src/name/blackcap/clipman/PasteboardQueue.kt	Mon Jan 20 23:02:51 2020 -0800
+++ b/src/name/blackcap/clipman/PasteboardQueue.kt	Tue Jan 21 13:07:35 2020 -0800
@@ -21,6 +21,17 @@
 class PasteboardQueue(val parent: Container, maxSize: Int) {
     private val queue = LinkedList<QueueItem>()
     private var _maxSize = maxSize
+    private var scrollPane: JScrollPane? = null
+    init {
+        var sp: Container? = parent
+        while (sp != null) {
+            if (sp is JScrollPane) {
+                scrollPane = sp
+                break
+            }
+            sp = sp.parent
+        }
+    }
 
     /**
      * The maximum allowed size of this queue. Attempts to make the queue
@@ -42,12 +53,7 @@
     @Synchronized fun add(item: QueueItem) {
         inSwingThread {
             parent.add(item.component)
-            /* XXX - assumes there is a JScrollPane above us in the tree */
-            var sp = parent.parent
-            while (sp != null && !(sp is JScrollPane)) {
-                sp = sp.parent
-            }
-            (sp as JScrollPane).run {
+            scrollPane?.run {
                 validate()
                 verticalScrollBar.run { value = maximum + 1 }
             }