Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:732f92dc3bc6 | 16:88703ca72fc3 |
---|---|
19 * exceeding the specified maximum size. | 19 * exceeding the specified maximum size. |
20 */ | 20 */ |
21 class PasteboardQueue(val parent: Container, maxSize: Int) { | 21 class PasteboardQueue(val parent: Container, maxSize: Int) { |
22 private val queue = LinkedList<QueueItem>() | 22 private val queue = LinkedList<QueueItem>() |
23 private var _maxSize = maxSize | 23 private var _maxSize = maxSize |
24 private var scrollPane: JScrollPane? = null | |
25 init { | |
26 var sp: Container? = parent | |
27 while (sp != null) { | |
28 if (sp is JScrollPane) { | |
29 scrollPane = sp | |
30 break | |
31 } | |
32 sp = sp.parent | |
33 } | |
34 } | |
24 | 35 |
25 /** | 36 /** |
26 * The maximum allowed size of this queue. Attempts to make the queue | 37 * The maximum allowed size of this queue. Attempts to make the queue |
27 * larger than this size, or specifying a size smaller than the current | 38 * larger than this size, or specifying a size smaller than the current |
28 * size, will result in the oldest item(s) being discarded. A size less | 39 * size, will result in the oldest item(s) being discarded. A size less |
40 * @param item QueueItem to add | 51 * @param item QueueItem to add |
41 */ | 52 */ |
42 @Synchronized fun add(item: QueueItem) { | 53 @Synchronized fun add(item: QueueItem) { |
43 inSwingThread { | 54 inSwingThread { |
44 parent.add(item.component) | 55 parent.add(item.component) |
45 /* XXX - assumes there is a JScrollPane above us in the tree */ | 56 scrollPane?.run { |
46 var sp = parent.parent | |
47 while (sp != null && !(sp is JScrollPane)) { | |
48 sp = sp.parent | |
49 } | |
50 (sp as JScrollPane).run { | |
51 validate() | 57 validate() |
52 verticalScrollBar.run { value = maximum + 1 } | 58 verticalScrollBar.run { value = maximum + 1 } |
53 } | 59 } |
54 } | 60 } |
55 queue.addLast(item) | 61 queue.addLast(item) |