Mercurial > cgi-bin > hgweb.cgi > ClipMan
annotate src/name/blackcap/clipman/Pasteboard.kt @ 28:f1fcc1281dad
Use BorderFactory; clean up Find dialog.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 29 Jan 2020 13:39:14 -0800 |
parents | 8aa2dfac27eb |
children | 0c6c18a733b7 |
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 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
|
26 * write it. |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 */ |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 sealed class PasteboardItem { |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
29 /* 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
|
30 |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
31 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
|
32 |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
33 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
|
34 |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
35 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
|
36 private var failed = false |
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 /* lazy conversion to HTML */ |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
39 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
|
40 val html: String? |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
41 get() { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
42 if (failed || _html != null) { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
43 return _html |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
44 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
45 _html = htmlFromRTF() |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
46 failed = _html == null |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
47 return _html |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
48 } |
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 private fun htmlFromRTF(): String? { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
51 ByteArrayInputStream(rtf).use { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
52 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
|
53 if (errors != null) { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
54 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
|
55 return null |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
56 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
57 return html |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
58 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
59 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
60 } |
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 /* 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
|
63 |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 private class PasteboardData(val item: PasteboardItem): |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 Transferable, ClipboardOwner { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 private val CHARSET = Charset.forName(CHARSET_NAME) |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 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
|
68 private val _data: HashMap<DataFlavor, Any> |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 private val flavors: Array<DataFlavor> |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 init { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 _data = HashMap<DataFlavor, Any>().apply { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
73 when (item) { |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
74 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
|
75 is HTML -> { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 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
|
77 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
|
78 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
79 is RTF -> { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
80 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
|
81 if (item.html != null) { |
18 | 82 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
|
83 } |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
84 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
86 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
87 _data.keys.asIterable().run { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 flavors = Array<DataFlavor>(count()) { elementAt(it) } |
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 override fun getTransferData(flavor: DataFlavor): Any { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 return _data.get(flavor) ?: throw UnsupportedFlavorException(flavor) |
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 override fun getTransferDataFlavors(): Array<DataFlavor> = flavors |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 override fun isDataFlavorSupported(flavor: DataFlavor) = _data.containsKey(flavor) |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
98 override fun lostOwnership(clipboard: Clipboard, contents: Transferable) {} |
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 |
18 | 101 /** |
102 * Compare this PasteboardItem with another object. | |
103 * @param other object | |
104 * @return true iff this item's type and native content match the other's | |
105 */ | |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
106 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
|
107 return when (this) { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
112 } |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
113 |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 companion object { |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
115 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
|
116 private val CLIPBOARD = Toolkit.getDefaultToolkit().systemClipboard |
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 * Read the item in the pasteboard. |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 * @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
|
121 */ |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 fun read() : PasteboardItem? { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 check() |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
124 val plain = getClipboardData(DataFlavor.stringFlavor) as String? |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 if (plain == null) { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 return null |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 } |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
128 val html = getClipboardData(DataFlavor.allHtmlFlavor) as String? |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 if (html == null) { |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
130 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
|
131 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
|
132 } else { |
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
133 return HTML(plain, html) |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
135 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 /** |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
138 * Write an item to the pasteboard. |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
139 * @param item a PasteboardItem to write |
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 fun write(item: PasteboardItem) { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
142 check() |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
143 val pbdata = PasteboardData(item) |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
144 CLIPBOARD.setContents(pbdata, pbdata) |
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 |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 private fun check() { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
148 if (CLIPBOARD == null) { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 throw RuntimeException("no clipboard available!") |
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 |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
153 private fun getClipboardData(flavor: DataFlavor): Any? { |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
154 try { |
17
9dd58db4d15a
Only convert RTF to HTML if needed. Much more efficient.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
155 return CLIPBOARD.getData(flavor) |
0
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 } catch (e: IOException) { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 return null |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
158 } catch (e: UnsupportedFlavorException) { |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 return null |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
161 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
162 } |
be282c48010a
Incomplete; checking it in as a backup.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
163 } |