annotate src/name/blackcap/clipman/Main.kt @ 41:33fbe3a78d84

Got the settings stuff compiling (untested).
author David Barts <n5jrn@me.com>
date Sat, 08 Feb 2020 22:10:01 -0700
parents 5f8475b37e23
children 339e2da5bf83
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.Container
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.Dimension
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.Font
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.awt.datatransfer.*
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
11 import java.awt.event.MouseEvent
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
12 import java.awt.event.MouseListener
0
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
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 import javax.swing.*
13
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
19 import javax.swing.text.html.StyleSheet
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 import kotlin.concurrent.thread
41
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
21 import kotlin.math.roundToInt
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 import org.jsoup.Jsoup
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 import org.jsoup.nodes.*
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
24
7
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
25 /* name we call ourselves */
fbb3a6999590 More border tweaks, etc.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
26 val MYNAME = "ClipMan"
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
27
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
28 /* default sizes */
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
29 val CPWIDTH = 640
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
30 val CPHEIGHT = 480
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
31
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
32 /* width of main panel border */
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
33 val PANEL_BORDER = 9
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
34
13
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
35 /* default font sizes in the text-display panes */
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
36 val MONO_SIZE = 14
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
37 val PROP_SIZE = 16
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
38
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
39 /* the queue of data we deal with and the main application frame */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
40 val queue = LateInit<PasteboardQueue>()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
41 val frame = LateInit<JFrame>()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
42
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 /* kills the updating thread (and does a system exit) when needed */
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
44 class KillIt() : WindowListener {
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 // events we don't care about
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 override fun windowActivated(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 override fun windowClosed(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 override fun windowDeactivated(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 override fun windowDeiconified(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 override fun windowIconified(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 override fun windowOpened(e: WindowEvent) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
52
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 // and the one we do
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 override fun windowClosing(e: WindowEvent) {
6
0640efd6b54a Tweak borders (incomplete).
David Barts <n5jrn@me.com>
parents: 4
diff changeset
55 LOGGER.log(Level.INFO, "execution complete")
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 System.exit(0)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
59
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
60 /* the updating thread */
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
61 class UpdateIt(val interval: Int): Thread(), MouseListener {
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
62 @Volatile var enabled = true
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
63
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 override fun run() {
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
65 var oldContents: PasteboardItem? = null
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 while (true) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 if (enabled) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 var contents = PasteboardItem.read()
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
69 if ((contents != null) && (contents != oldContents)) {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
70 val (plain, html) = when(contents) {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
71 is PasteboardItem.Plain -> Pair(contents.plain, null)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
72 is PasteboardItem.HTML -> Pair(null, contents.html)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
73 is PasteboardItem.RTF -> Pair(contents.plain, contents.html)
3
70caa73e32f7 Stop it from spinning on non-textual clipboard data.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
74 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
75 val piv = if (html == null) {
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
76 PasteboardItemView("Plain text", ClipText(contents).apply {
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
77 contentType = "text/plain"
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
78 text = plain
41
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
79 font = Font(settingsDialog.mFamily, Font.PLAIN, settingsDialog.mSize.roundToInt())
29
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
80 resize()
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
81 })
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
82 } else {
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
83 val (dhtml, style) = preproc(html)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
84 val hek = MyEditorKit().apply {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
85 style.addStyleSheet(defaultStyleSheet)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
86 styleSheet = style
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
87 }
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
88 PasteboardItemView("Styled text", ClipText(contents).apply {
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
89 editorKit = hek
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
90 text = dhtml
29
c4f53bc01732 Fix searching (and main display).
David Barts <n5jrn@me.com>
parents: 28
diff changeset
91 resize()
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
92 })
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
94 piv.searchable.addMouseListener(this)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
95 queue.v.add(QueueItem(contents, piv))
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 15
diff changeset
96 oldContents = contents
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
98 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 if (Thread.interrupted()) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 return
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 try {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 Thread.sleep(interval - System.currentTimeMillis() % interval)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
104 } catch (e: InterruptedException) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
105 return
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
106 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
107 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
108 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
109
13
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
110 private fun preproc(html: String): Pair<String, StyleSheet> {
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
111 val sty = StyleSheet().apply {
41
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
112 addRule("body { font-family: \"%s\"; font-size: %.2f; }".format(
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
113 settingsDialog.pFamily, settingsDialog.pSize))
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
114 addRule("code, kbd, pre, samp, tt { font-family: \"%s\"; font-size: %.2f}; }".format(
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
115 settingsDialog.mFamily, settingsDialog.mSize))
13
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
116 }
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
117 val scrubbed = Jsoup.parse(html).run {
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
118 select("style").forEach {
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
119 it.dataNodes().forEach { sty.addRule(it.wholeData) }
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
120 }
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
121 select(":root>head>meta").remove()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 outputSettings()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 .charset(CHARSET_NAME)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 .syntax(Document.OutputSettings.Syntax.xml)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 outerHtml()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 }
13
fe0fcfc8b2aa Braindead POS wasn't honoring <style> tags; fixed that.
David Barts <n5jrn@me.com>
parents: 12
diff changeset
127 return Pair(scrubbed, sty)
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
129
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
130 /* MouseListener methods */
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
131
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
132 override fun mouseClicked(e: MouseEvent) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
133 val source = e.getSource() as? ClipText
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
134 if (source == null) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
135 return
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
136 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
137 queue.v.deselectAll()
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
138 source.selected = true
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
139 source.validate()
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
140 anyRequired.enable()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
141 source.basedOn.let {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
142 if (it is PasteboardItem.HTML || it is PasteboardItem.RTF) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
143 styledRequired.enable()
35
5f8475b37e23 Got it correctly enabling and disabling menu items.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
144 } else {
5f8475b37e23 Got it correctly enabling and disabling menu items.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
145 styledRequired.disable()
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
146 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents: 29
diff changeset
147 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
148 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
149
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
150 override fun mousePressed(e: MouseEvent) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
151 maybeShowPopup(e)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
152 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
153
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
154 override fun mouseReleased(e: MouseEvent) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
155 maybeShowPopup(e)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
156 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
157
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
158 private fun maybeShowPopup(e: MouseEvent) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
159 if (e.isPopupTrigger()) {
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
160 popupMenu.show(e.component, e.x, e.y)
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
161 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
162 }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
163
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
164 override fun mouseEntered(e: MouseEvent) { }
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
165 override fun mouseExited(e: MouseEvent) { }
0
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
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
168 /* entry point */
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
169 fun main(args: Array<String>) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
170 LOGGER.log(Level.INFO, "beginning execution")
24
dac8dfb4b549 Preliminary menu bar support.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
171 if (OS.type == OS.MAC) {
dac8dfb4b549 Preliminary menu bar support.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
172 System.setProperty("apple.laf.useScreenMenuBar", "true")
dac8dfb4b549 Preliminary menu bar support.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
173 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
174 lateinit var con: JPanel
9
8fcff14defa2 Stomp out race conditions and set width adaptively.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
175 inSynSwingThread {
21
c10a447b9e1b Add some searching hooks.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
176 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
177 frame.v = JFrame(MYNAME)
21
c10a447b9e1b Add some searching hooks.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
178 con = JPanel().apply {
c10a447b9e1b Add some searching hooks.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
179 layout = BoxLayout(this, BoxLayout.Y_AXIS)
28
f1fcc1281dad Use BorderFactory; clean up Find dialog.
David Barts <n5jrn@me.com>
parents: 27
diff changeset
180 border = BorderFactory.createEmptyBorder(PANEL_BORDER, PANEL_BORDER, PANEL_BORDER, PANEL_BORDER)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
181 background = frame.v.background
21
c10a447b9e1b Add some searching hooks.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
182 }
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
183 frame.v.jMenuBar = menuBar
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
184 frame.v.apply {
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
185 contentPane.add(
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
186 JScrollPane(con).apply {
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
187 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
188 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
8
7715ff59f053 Get layout of main display non-ugly.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
189 preferredSize = Dimension(CPWIDTH, CPHEIGHT)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
190 background = frame.v.background
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
191 }, BorderLayout.CENTER)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
192 pack()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
193 setVisible(true)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
194 addWindowListener(KillIt())
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
195 }
41
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
196 setMacMenus()
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
197 }
41
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 35
diff changeset
198 queue.v = PasteboardQueue(con, settingsDialog.qLength)
27
8aa2dfac27eb Big reorg; compiled but untested.
David Barts <n5jrn@me.com>
parents: 24
diff changeset
199 UpdateIt(1000).apply { start() }
24
dac8dfb4b549 Preliminary menu bar support.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
200 }