annotate src/name/blackcap/clipman/Main.kt @ 9:8fcff14defa2

Stomp out race conditions and set width adaptively.
author David Barts <n5jrn@me.com>
date Sun, 19 Jan 2020 15:43:01 -0800
parents 7715ff59f053
children e7e067f5b649
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 /*
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 * The entry point and most of the view logic is here.
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 */
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 package name.blackcap.clipman
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
5
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import java.awt.BorderLayout
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import java.awt.Color
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.Container
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.Dimension
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.awt.Font
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.awt.Toolkit;
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.awt.datatransfer.*
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.awt.event.WindowEvent
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import java.awt.event.WindowListener
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 import java.util.Date
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import java.util.logging.Level
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 import java.util.logging.Logger
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
18 import java.util.concurrent.Semaphore
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 import javax.swing.*
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
20 import javax.swing.border.*
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 import javax.swing.text.JTextComponent
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 import kotlin.concurrent.thread
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 import org.jsoup.Jsoup
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 import org.jsoup.nodes.*
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
25
7
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
26 /* name we call ourselves */
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
27 val MYNAME = "ClipMan"
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
28
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
29 /* default sizes */
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
30 val CPWIDTH = 640
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
31 val CPHEIGHT = 480
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
32
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
33 /* border widths */
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
34 val PANEL_BORDER = 9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
35 val OUTER_BORDER = 9 /* must be 6 or more */
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
36 val INNER_BORDER = 1
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
37 val MARGIN_BORDER = 3
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
38
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 /* kills the updating thread (and does a system exit) when needed */
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 class KillIt(val thr: Thread) : WindowListener {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 // events we don't care about
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 override fun windowActivated(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 override fun windowClosed(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 override fun windowDeactivated(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 override fun windowDeiconified(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 override fun windowIconified(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 override fun windowOpened(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
48
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 // and the one we do
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 override fun windowClosing(e: WindowEvent) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 thr.run { interrupt(); join() }
6
0640efd6b54a Tweak borders (incomplete).
David Barts <n5jrn@me.com>
parents: 4
diff changeset
52 LOGGER.log(Level.INFO, "execution complete")
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 System.exit(0)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
56
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 /* the updating thread */
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 class UpdateIt(val queue: PasteboardQueue, val interval: Int): Thread() {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
59 @Volatile var enabled = true
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
60 private val outerBorder =
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
61 MatteBorder(OUTER_BORDER-6, OUTER_BORDER, OUTER_BORDER, OUTER_BORDER,
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
62 queue.parent.background)
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
63 private val stdBorder =
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
64 CompoundBorder(LineBorder(Color.GRAY, INNER_BORDER),
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
65 EmptyBorder(MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER, MARGIN_BORDER))
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
66
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 override fun run() {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 var oldContents = ""
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 var newContents = ""
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 while (true) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 if (enabled) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 var contents = PasteboardItem.read()
3
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
73 if (contents != null) {
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
74 newContents = when (contents) {
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
75 is PasteboardItem.Plain -> contents.plain
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
76 is PasteboardItem.HTML -> contents.plain
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
77 }
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
78 if (oldContents != newContents) {
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
79 var stdWidth: Int? = null
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
80 inSynSwingThread {
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
81 stdWidth = queue.parent.size.width - 2 * (PANEL_BORDER+OUTER_BORDER+INNER_BORDER+MARGIN_BORDER)
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
82 }
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
83 var widget = JPanel().apply {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
84 layout = BoxLayout(this, BoxLayout.Y_AXIS)
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
85 background = queue.parent.background
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
86 border = outerBorder
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
87 }
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
88 when (contents) {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
89 is PasteboardItem.Plain -> widget.run {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
90 add(stdLabel("Plain text"))
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
91 add(JTextPane().apply {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
92 contentType = "text/plain"
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
93 text = contents.plain
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
94 font = Font(Font.MONOSPACED, Font.PLAIN, 14)
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
95 border = stdBorder
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
96 autoSize(stdWidth!!)
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
97 setEditable(false)
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
98 alignmentX = JTextPane.LEFT_ALIGNMENT
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
99 })
3
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
100 }
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
101 is PasteboardItem.HTML -> widget.run {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
102 add(stdLabel("Styled text"))
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
103 add(JTextPane().apply {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
104 contentType = "text/html"
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
105 toolTipText = "Styled text"
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
106 text = scrub(contents.html)
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
107 border = stdBorder
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
108 autoSize(stdWidth!!)
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
109 setEditable(false)
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
110 alignmentX = JTextPane.LEFT_ALIGNMENT
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
111 })
3
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
112 }
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
113 }
3
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
114 queue.add(QueueItem(widget, contents))
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
115 oldContents = newContents
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
116 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
117 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
118 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
119 if (Thread.interrupted()) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
120 return
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
121 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 try {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 Thread.sleep(interval - System.currentTimeMillis() % interval)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 } catch (e: InterruptedException) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 return
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
127 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
129
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
130 private fun stdLabel(text: String) = JLabel(text).apply {
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
131 horizontalAlignment = JLabel.LEFT
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
132 alignmentX = JLabel.LEFT_ALIGNMENT
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
133 }
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
134
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
135 private fun scrub(html: String): String {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 return Jsoup.parse(html).run {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
137 select(":root>head>meta").remove()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
138 outputSettings()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 .charset(CHARSET_NAME)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 .syntax(Document.OutputSettings.Syntax.xml)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
141 outerHtml()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
145
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 fun main(args: Array<String>) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 LOGGER.log(Level.INFO, "beginning execution")
7
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
148 setLookFeel()
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
149 val frame = JFrame(MYNAME)
4
debe0413280f Use JPanel.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
150 val con = JPanel().apply {
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
151 layout = BoxLayout(this, BoxLayout.Y_AXIS)
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
152 border = EmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER)
6
0640efd6b54a Tweak borders (incomplete).
David Barts <n5jrn@me.com>
parents: 4
diff changeset
153 background = frame.background
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
154 }
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
155 inSynSwingThread {
6
0640efd6b54a Tweak borders (incomplete).
David Barts <n5jrn@me.com>
parents: 4
diff changeset
156 frame.apply {
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
157 contentPane.add(
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
158 JScrollPane(con).apply {
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
159 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
160 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
161 preferredSize = Dimension(CPWIDTH, CPHEIGHT)
6
0640efd6b54a Tweak borders (incomplete).
David Barts <n5jrn@me.com>
parents: 4
diff changeset
162 background = frame.background
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
163 }, BorderLayout.CENTER)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
164 pack()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 setVisible(true)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
166 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
167 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
168 val queue = PasteboardQueue(con, 10)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
169 val updater = UpdateIt(queue, 1000).apply { start() }
6
0640efd6b54a Tweak borders (incomplete).
David Barts <n5jrn@me.com>
parents: 4
diff changeset
170 inSwingThread { frame.addWindowListener(KillIt(updater)) }
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
171 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
172
7
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
173 fun setLookFeel() {
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
174 inSwingThread {
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
175 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
176 }
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
177 }
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
178
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
179 fun inSwingThread(block: () -> Unit) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
180 SwingUtilities.invokeLater(Runnable(block))
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
181 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
182
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
183 fun inSynSwingThread(block: () -> Unit) {
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
184 val ready = Semaphore(0)
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
185 inSwingThread {
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
186 block()
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
187 ready.release()
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
188 }
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
189 ready.acquire()
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
190 }
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
191
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
192 fun JTextComponent.autoSize(width: Int): Unit {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
193 val SLOP = 10
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
194 val dim = Dimension(width, width)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
195 preferredSize = dim
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
196 size = dim
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
197 val r = modelToView(document.length)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
198 preferredSize = Dimension(width, r.y + r.height + SLOP)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
199 }