comparison src/name/blackcap/clipman/Main.kt @ 7:fbb3a6999590

More border tweaks, etc.
author David Barts <n5jrn@me.com>
date Sun, 19 Jan 2020 12:46:42 -0800
parents 0640efd6b54a
children 7715ff59f053
comparison
equal deleted inserted replaced
6:0640efd6b54a 7:fbb3a6999590
22 import javax.swing.text.JTextComponent 22 import javax.swing.text.JTextComponent
23 import kotlin.concurrent.thread 23 import kotlin.concurrent.thread
24 import org.jsoup.Jsoup 24 import org.jsoup.Jsoup
25 import org.jsoup.nodes.* 25 import org.jsoup.nodes.*
26 26
27 /* name we call ourselves */
28 val MYNAME = "ClipMan"
27 29
28 /* kills the updating thread (and does a system exit) when needed */ 30 /* kills the updating thread (and does a system exit) when needed */
29 class KillIt(val thr: Thread) : WindowListener { 31 class KillIt(val thr: Thread) : WindowListener {
30 // events we don't care about 32 // events we don't care about
31 override fun windowActivated(e: WindowEvent) {} 33 override fun windowActivated(e: WindowEvent) {}
45 47
46 /* the updating thread */ 48 /* the updating thread */
47 class UpdateIt(val queue: PasteboardQueue, val interval: Int): Thread() { 49 class UpdateIt(val queue: PasteboardQueue, val interval: Int): Thread() {
48 @Volatile var enabled = true 50 @Volatile var enabled = true
49 private val stdBorder = 51 private val stdBorder =
50 CompoundBorder(LineBorder(Color(0xeeeeee), 9), LineBorder(Color.GRAY, 1)) 52 CompoundBorder(LineBorder(queue.parent.background, 9),
53 CompoundBorder(LineBorder(Color.GRAY, 1), EmptyBorder(3, 3, 3, 3)))
51 54
52 override fun run() { 55 override fun run() {
53 var oldContents = "" 56 var oldContents = ""
54 var newContents = "" 57 var newContents = ""
55 while (true) { 58 while (true) {
107 } 110 }
108 } 111 }
109 112
110 fun main(args: Array<String>) { 113 fun main(args: Array<String>) {
111 LOGGER.log(Level.INFO, "beginning execution") 114 LOGGER.log(Level.INFO, "beginning execution")
112 val frame = JFrame("ClipMan").apply { preferredSize = Dimension(640, 480) } 115 setLookFeel()
116 val frame = JFrame(MYNAME).apply { preferredSize = Dimension(640, 480) }
113 val con = JPanel().apply { 117 val con = JPanel().apply {
114 layout = BoxLayout(this, BoxLayout.Y_AXIS) 118 layout = BoxLayout(this, BoxLayout.Y_AXIS)
115 border = EmptyBorder(9, 9, 9, 9) 119 border = EmptyBorder(9, 9, 9, 9)
116 background = frame.background 120 background = frame.background
117 } 121 }
118 inSwingThread { 122 inSwingThread {
119 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
120 frame.apply { 123 frame.apply {
121 contentPane.add( 124 contentPane.add(
122 JScrollPane(con).apply { 125 JScrollPane(con).apply {
123 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED 126 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
124 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER 127 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
132 val queue = PasteboardQueue(con, 10) 135 val queue = PasteboardQueue(con, 10)
133 val updater = UpdateIt(queue, 1000).apply { start() } 136 val updater = UpdateIt(queue, 1000).apply { start() }
134 inSwingThread { frame.addWindowListener(KillIt(updater)) } 137 inSwingThread { frame.addWindowListener(KillIt(updater)) }
135 } 138 }
136 139
140 fun setLookFeel() {
141 inSwingThread {
142 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
143 }
144 }
145
137 fun inSwingThread(block: () -> Unit) { 146 fun inSwingThread(block: () -> Unit) {
138 SwingUtilities.invokeLater(Runnable(block)) 147 SwingUtilities.invokeLater(Runnable(block))
139 } 148 }
140 149
141 fun JTextComponent.autoSize(width: Int): Unit { 150 fun JTextComponent.autoSize(width: Int): Unit {