annotate src/name/blackcap/clipman/Pasteboard.kt @ 26:ff35fabaea3a

Added tag pre-big-reorg for changeset 3129d0e24086
author David Barts <n5jrn@me.com>
date Wed, 29 Jan 2020 10:47:46 -0800
parents 96cc73ae2904
children 8aa2dfac27eb
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 * We call the clipboard a "pasteboard" for our internal class name, not
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 * because I prefer that term (I don't) but so as to not clash with the
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 * AWT's Clipboard class.
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 package name.blackcap.clipman
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
7
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.Toolkit
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.datatransfer.Clipboard
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.awt.datatransfer.ClipboardOwner
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.awt.datatransfer.DataFlavor
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.awt.datatransfer.Transferable
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.awt.datatransfer.UnsupportedFlavorException
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import java.io.IOException
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
15 import java.io.ByteArrayInputStream
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import java.nio.charset.Charset
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 import java.util.logging.Level
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 import java.util.logging.Logger
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 import kotlin.collections.HashMap
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
20
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 /* Constants, etc. */
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 val CHARSET_NAME = "UTF-8"
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
23
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 /*
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 * Represents an error dealing with pasteboard items.
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 */
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 class PasteboardError(): Exception()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
28
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 /**
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 * Represents an item of data in the clipboard and how to read and
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 * write it.
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 */
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 sealed class PasteboardItem {
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
34 /* the three possibilities for this class */
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
35
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
36 class Plain(val plain: String): PasteboardItem()
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
37
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
38 class HTML(val plain: String, val html: String): PasteboardItem()
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
39
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
40 class RTF(val plain: String, val rtf: ByteArray): PasteboardItem() {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
41 private var failed = false
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
42
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
43 /* lazy conversion to HTML */
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
44 private var _html: String? = null
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
45 val html: String?
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
46 get() {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
47 if (failed || _html != null) {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
48 return _html
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
49 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
50 _html = htmlFromRTF()
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
51 failed = _html == null
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
52 return _html
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
53 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
54
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
55 private fun htmlFromRTF(): String? {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
56 ByteArrayInputStream(rtf).use {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
57 val (html, errors) = rtfToHtml(it)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
58 if (errors != null) {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
59 LOGGER.log(Level.WARNING, errors)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
60 return null
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
61 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
62 return html
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
63 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
64 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
65 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
66
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
67 /* we use this when writing data back to the clipboard */
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
68
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 private class PasteboardData(val item: PasteboardItem):
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 Transferable, ClipboardOwner {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 private val CHARSET = Charset.forName(CHARSET_NAME)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 private val HTML_FLAVOR = DataFlavor("text/html; document=all; class=\"[B\"; charset=" + CHARSET_NAME)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 private val _data: HashMap<DataFlavor, Any>
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 private val flavors: Array<DataFlavor>
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
75
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
76 init {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
77 _data = HashMap<DataFlavor, Any>().apply {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 when (item) {
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
79 is Plain -> put(DataFlavor.stringFlavor, item.plain as Any)
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
80 is HTML -> {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 put(DataFlavor.stringFlavor, item.plain as Any)
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
82 put(HTML_FLAVOR, item.html.toByteArray(CHARSET) as Any)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
83 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
84 is RTF -> {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
85 put(DataFlavor.stringFlavor, item.plain as Any)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
86 if (item.html != null) {
18
96cc73ae2904 Make it more fail-safe.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
87 put(HTML_FLAVOR, item.html!!.toByteArray(CHARSET) as Any)
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
88 }
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
91 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
92 _data.keys.asIterable().run {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 flavors = Array<DataFlavor>(count()) { elementAt(it) }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
95 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
96
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 override fun getTransferData(flavor: DataFlavor): Any {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
98 return _data.get(flavor) ?: throw UnsupportedFlavorException(flavor)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
100
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 override fun getTransferDataFlavors(): Array<DataFlavor> = flavors
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 override fun isDataFlavorSupported(flavor: DataFlavor) = _data.containsKey(flavor)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 override fun lostOwnership(clipboard: Clipboard, contents: Transferable) {}
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
104 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
105
18
96cc73ae2904 Make it more fail-safe.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
106 /**
96cc73ae2904 Make it more fail-safe.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
107 * Compare this PasteboardItem with another object.
96cc73ae2904 Make it more fail-safe.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
108 * @param other object
96cc73ae2904 Make it more fail-safe.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
109 * @return true iff this item's type and native content match the other's
96cc73ae2904 Make it more fail-safe.
David Barts <n5jrn@me.com>
parents: 17
diff changeset
110 */
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
111 override operator fun equals(other: Any?): Boolean {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
112 return when (this) {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
113 is Plain -> (other is Plain) && (this.plain == other.plain)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
114 is HTML -> (other is HTML) && (this.html == other.html)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
115 is RTF -> (other is RTF) && (this.rtf contentEquals other.rtf)
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
116 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
117 }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
118
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
119 companion object {
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
120 private val RTF_FLAVOR = DataFlavor("text/rtf; class=\"[B\"")
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
121 private val CLIPBOARD = Toolkit.getDefaultToolkit().systemClipboard
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
122
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 /**
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 * Read the item in the pasteboard.
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 * @return a PasteboardItem? object, null if nothing could be read
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 fun read() : PasteboardItem? {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 check()
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
129 val plain = getClipboardData(DataFlavor.stringFlavor) as String?
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
130 if (plain == null) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
131 return null
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
132 }
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
133 val html = getClipboardData(DataFlavor.allHtmlFlavor) as String?
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
134 if (html == null) {
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
135 val rtf = getClipboardData(RTF_FLAVOR) as ByteArray?
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
136 return if (rtf == null) { Plain(plain) } else { RTF(plain, rtf) }
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
137 } else {
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
138 return HTML(plain, html)
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
141
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 * Write an item to the pasteboard.
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 * @param item a PasteboardItem to write
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 write(item: PasteboardItem) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 check()
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
148 val pbdata = PasteboardData(item)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
149 CLIPBOARD.setContents(pbdata, pbdata)
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
151
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
152 private fun check() {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
153 if (CLIPBOARD == null) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
154 throw RuntimeException("no clipboard available!")
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
155 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
156 }
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
157
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
158 private fun getClipboardData(flavor: DataFlavor): Any? {
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
159 try {
17
9dd58db4d15a Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
160 return CLIPBOARD.getData(flavor)
0
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
161 } catch (e: IOException) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
162 return null
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
163 } catch (e: UnsupportedFlavorException) {
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
164 return null
be282c48010a Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 }
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 }