comparison src/name/blackcap/clipman/PasteboardQueue.kt @ 1:fb224c3aebdf

Got it auto-scrolling to the bottom.
author David Barts <n5jrn@me.com>
date Sat, 18 Jan 2020 09:12:58 -0800
parents be282c48010a
children 6fb94eae32fa
comparison
equal deleted inserted replaced
0:be282c48010a 1:fb224c3aebdf
3 * tail, and old stuff truncated off the head. 3 * tail, and old stuff truncated off the head.
4 */ 4 */
5 package name.blackcap.clipman 5 package name.blackcap.clipman
6 6
7 import java.awt.Container 7 import java.awt.Container
8 import java.awt.Rectangle
8 import java.util.Collections 9 import java.util.Collections
9 import java.util.LinkedList 10 import java.util.LinkedList
11 import java.util.logging.Level
12 import java.util.logging.Logger
10 import javax.swing.* 13 import javax.swing.*
11 14
12 /** 15 /**
13 * A queue that tracks the data we display and the widgets used to 16 * A queue that tracks the data we display and the widgets used to
14 * display them. We never explicitly remove stuff from the queue, 17 * display them. We never explicitly remove stuff from the queue,
31 _maxSize = value 34 _maxSize = value
32 truncate(false) 35 truncate(false)
33 } 36 }
34 37
35 /** 38 /**
36 * Add a JComponent to the end of the queue. 39 * Add a QueueItem to the end of the queue.
37 * @param item JComponent to add 40 * @param item QueueItem to add
38 */ 41 */
39 @Synchronized fun add(item: QueueItem) { 42 @Synchronized fun add(item: QueueItem) {
40 inSwingThread { parent.add(item.component) } 43 inSwingThread {
44 parent.add(item.component)
45 /* XXX - assumes there is a JScrollPane above us in the tree */
46 var sp = parent.parent
47 while (sp != null && !(sp is JScrollPane)) {
48 sp = sp.parent
49 }
50 (sp as JScrollPane).run {
51 revalidate()
52 verticalScrollBar.run { value = maximum }
53 }
54 }
41 queue.addLast(item) 55 queue.addLast(item)
42 truncate(true) 56 truncate(true)
43 } 57 }
44 58
45 private fun truncate(forceValidate: Boolean) { 59 private fun truncate(forceValidate: Boolean) {