comparison src/name/blackcap/clipman/Main.kt @ 3:70caa73e32f7

Stop it from spinning on non-textual clipboard data.
author David Barts <n5jrn@me.com>
date Sat, 18 Jan 2020 11:13:27 -0800
parents be282c48010a
children debe0413280f
comparison
equal deleted inserted replaced
2:6fb94eae32fa 3:70caa73e32f7
52 var oldContents = "" 52 var oldContents = ""
53 var newContents = "" 53 var newContents = ""
54 while (true) { 54 while (true) {
55 if (enabled) { 55 if (enabled) {
56 var contents = PasteboardItem.read() 56 var contents = PasteboardItem.read()
57 if (contents == null) { 57 if (contents != null) {
58 LOGGER.log(Level.WARNING, "unable to read clipboard") 58 newContents = when (contents) {
59 continue 59 is PasteboardItem.Plain -> contents.plain
60 } 60 is PasteboardItem.HTML -> contents.plain
61 newContents = when (contents) { 61 }
62 is PasteboardItem.Plain -> contents.plain 62 if (oldContents != newContents) {
63 is PasteboardItem.HTML -> contents.plain 63 var widget: JComponent = when(contents) {
64 } 64 is PasteboardItem.Plain -> JTextPane().apply {
65 if (oldContents != newContents) { 65 contentType = "text/plain"
66 var widget: JComponent = when(contents) { 66 toolTipText = "Plain text"
67 is PasteboardItem.Plain -> JTextPane().apply { 67 text = contents.plain
68 contentType = "text/plain" 68 font = Font(Font.MONOSPACED, Font.PLAIN, 14)
69 toolTipText = "Plain text" 69 border = stdBorder
70 text = contents.plain 70 autoSize(600)
71 font = Font(Font.MONOSPACED, Font.PLAIN, 14) 71 setEditable(false)
72 border = stdBorder 72 }
73 autoSize(600) 73 is PasteboardItem.HTML -> JTextPane().apply {
74 setEditable(false) 74 contentType = "text/html"
75 toolTipText = "Styled text"
76 text = scrub(contents.html)
77 border = stdBorder
78 autoSize(600)
79 setEditable(false)
80 }
75 } 81 }
76 is PasteboardItem.HTML -> JTextPane().apply { 82 queue.add(QueueItem(widget, contents))
77 contentType = "text/html" 83 oldContents = newContents
78 toolTipText = "Styled text"
79 text = scrub(contents.html)
80 border = stdBorder
81 autoSize(600)
82 setEditable(false)
83 }
84 } 84 }
85 queue.add(QueueItem(widget, contents))
86 oldContents = newContents
87 } 85 }
88 } 86 }
89 if (Thread.interrupted()) { 87 if (Thread.interrupted()) {
90 return 88 return
91 } 89 }