Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Clipboard.kt @ 0:a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 11 Sep 2022 16:11:37 -0700 |
parents | |
children | 3c792ad36b3d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a6cfdffcaa94 |
---|---|
1 package name.blackcap.passman | |
2 | |
3 import java.awt.Toolkit | |
4 import java.awt.datatransfer.Clipboard | |
5 import java.awt.datatransfer.DataFlavor | |
6 import java.awt.datatransfer.Transferable | |
7 import java.awt.datatransfer.UnsupportedFlavorException | |
8 | |
9 private val CLIPBOARD = Toolkit.getDefaultToolkit().systemClipboard | |
10 | |
11 private class ClipboardData(val item: String): Transferable { | |
12 private val FLAVORS = arrayOf<DataFlavor>(DataFlavor.stringFlavor) | |
13 | |
14 override fun getTransferDataFlavors(): Array<DataFlavor> = FLAVORS | |
15 | |
16 override fun isDataFlavorSupported(flavor: DataFlavor?): Boolean = | |
17 FLAVORS.contains(flavor) | |
18 | |
19 override fun getTransferData(flavor: DataFlavor?): Any { | |
20 if (!isDataFlavorSupported(flavor)) { | |
21 throw UnsupportedFlavorException(flavor) | |
22 } | |
23 return item | |
24 } | |
25 | |
26 } | |
27 | |
28 private class ClipboardOwner(): java.awt.datatransfer.ClipboardOwner { | |
29 override fun lostOwnership(clipboard: Clipboard?, contents: Transferable?) { | |
30 /* we don't care */ | |
31 } | |
32 } | |
33 | |
34 /* xxx: this often makes a string out of a password */ | |
35 fun writeToClipboard(charArray: CharArray) { | |
36 CLIPBOARD.setContents(ClipboardData(String(charArray)), ClipboardOwner()) | |
37 } | |
38 | |
39 fun writeToClipboard(string: String) { | |
40 CLIPBOARD.setContents(ClipboardData(string), ClipboardOwner()) | |
41 } |