comparison src/name/blackcap/clipman/Main.kt @ 43:339e2da5bf83

Simplified the settings. Compiles, not tested.
author David Barts <n5jrn@me.com>
date Sun, 09 Feb 2020 19:23:16 -0700
parents 33fbe3a78d84
children 19d9da731c43
comparison
equal deleted inserted replaced
42:99220aa136d9 43:339e2da5bf83
16 import java.util.logging.Level 16 import java.util.logging.Level
17 import java.util.logging.Logger 17 import java.util.logging.Logger
18 import javax.swing.* 18 import javax.swing.*
19 import javax.swing.text.html.StyleSheet 19 import javax.swing.text.html.StyleSheet
20 import kotlin.concurrent.thread 20 import kotlin.concurrent.thread
21 import kotlin.math.roundToInt
22 import org.jsoup.Jsoup 21 import org.jsoup.Jsoup
23 import org.jsoup.nodes.* 22 import org.jsoup.nodes.*
24 23
25 /* name we call ourselves */ 24 /* name we call ourselves */
26 val MYNAME = "ClipMan" 25 val MYNAME = "ClipMan"
74 } 73 }
75 val piv = if (html == null) { 74 val piv = if (html == null) {
76 PasteboardItemView("Plain text", ClipText(contents).apply { 75 PasteboardItemView("Plain text", ClipText(contents).apply {
77 contentType = "text/plain" 76 contentType = "text/plain"
78 text = plain 77 text = plain
79 font = Font(settingsDialog.mFamily, Font.PLAIN, settingsDialog.mSize.roundToInt()) 78 font = Font(Font.MONOSPACED, Font.PLAIN, MONO_SIZE)
80 resize() 79 resize()
81 }) 80 })
82 } else { 81 } else {
83 val (dhtml, style) = preproc(html) 82 val (dhtml, style) = preproc(html)
84 val hek = MyEditorKit().apply { 83 val hek = MyEditorKit().apply {
107 } 106 }
108 } 107 }
109 108
110 private fun preproc(html: String): Pair<String, StyleSheet> { 109 private fun preproc(html: String): Pair<String, StyleSheet> {
111 val sty = StyleSheet().apply { 110 val sty = StyleSheet().apply {
112 addRule("body { font-family: \"%s\"; font-size: %.2f; }".format( 111 addRule("body { font-family: serif; font-size: ${PROP_SIZE}; }")
113 settingsDialog.pFamily, settingsDialog.pSize)) 112 addRule("code, kbd, pre, samp, tt { font-family: monospace; font-size: ${MONO_SIZE}; }")
114 addRule("code, kbd, pre, samp, tt { font-family: \"%s\"; font-size: %.2f}; }".format(
115 settingsDialog.mFamily, settingsDialog.mSize))
116 } 113 }
117 val scrubbed = Jsoup.parse(html).run { 114 val scrubbed = Jsoup.parse(html).run {
118 select("style").forEach { 115 select("style").forEach {
119 it.dataNodes().forEach { sty.addRule(it.wholeData) } 116 it.dataNodes().forEach { sty.addRule(it.wholeData) }
120 } 117 }