Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison src/name/blackcap/clipman/Main.kt @ 14:0cd912d29184
Better cope with Swing's idiosyncrasies.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 20 Jan 2020 22:59:04 -0800 |
parents | fe0fcfc8b2aa |
children | 732f92dc3bc6 |
comparison
equal
deleted
inserted
replaced
13:fe0fcfc8b2aa | 14:0cd912d29184 |
---|---|
113 } | 113 } |
114 is PasteboardItem.HTML -> widget.run { | 114 is PasteboardItem.HTML -> widget.run { |
115 add(stdLabel("Styled text")) | 115 add(stdLabel("Styled text")) |
116 val (html, style) = preproc(contents.html) | 116 val (html, style) = preproc(contents.html) |
117 val hek = HTMLEditorKit().apply { | 117 val hek = HTMLEditorKit().apply { |
118 style.addStyleSheet(styleSheet) | |
118 styleSheet = style | 119 styleSheet = style |
119 } | 120 } |
120 add(ClipText().apply { | 121 add(ClipText().apply { |
121 editorKit = hek | 122 editorKit = hek |
122 text = html | 123 text = html |
148 alignmentX = JLabel.LEFT_ALIGNMENT | 149 alignmentX = JLabel.LEFT_ALIGNMENT |
149 } | 150 } |
150 | 151 |
151 private fun preproc(html: String): Pair<String, StyleSheet> { | 152 private fun preproc(html: String): Pair<String, StyleSheet> { |
152 val sty = StyleSheet().apply { | 153 val sty = StyleSheet().apply { |
153 addRule("html { font-family: serif; font-size: %d; }".format(PROP_SIZE)) | 154 addRule("head, body { font-family: serif; font-size: %d; }".format(PROP_SIZE)) |
154 addRule("code, kbd, pre, samp { font-family: monospace; font-size: %d; }".format(MONO_SIZE)) | 155 addRule("code, kbd, pre, samp, tt { font-family: monospace; font-size: %d; }".format(MONO_SIZE)) |
155 } | 156 } |
156 val scrubbed = Jsoup.parse(html).run { | 157 val scrubbed = Jsoup.parse(html).run { |
157 select("style").forEach { | 158 select("style").forEach { |
158 it.dataNodes().forEach { sty.addRule(it.wholeData) } | 159 it.dataNodes().forEach { sty.addRule(it.wholeData) } |
159 } | 160 } |