Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison src/name/blackcap/clipman/CoerceDialog.kt @ 56:22725d4d7849
An attempt to get it to troff-ize styled text.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 19 Mar 2022 23:04:40 -0700 |
parents | 19d9da731c43 |
children | 88056f373a94 |
comparison
equal
deleted
inserted
replaced
55:7ad2b29a7f60 | 56:22725d4d7849 |
---|---|
160 alignmentX = JLabel.LEFT_ALIGNMENT | 160 alignmentX = JLabel.LEFT_ALIGNMENT |
161 } | 161 } |
162 | 162 |
163 private fun coerce() { | 163 private fun coerce() { |
164 val selected = Application.queue.getSelected() | 164 val selected = Application.queue.getSelected() |
165 if (!suitedForCoercing(selected)) { | |
166 return | |
167 } | |
165 if (selected == null) { | 168 if (selected == null) { |
166 JOptionPane.showMessageDialog(Application.frame, | 169 return /* redundant, but makes kotlinc happy */ |
167 "No item selected.", | 170 } |
168 "Error", | 171 if (badSize(_pSize, PROP_SIZE, "proportionally-spaced") || badSize(_mSize, MONO_SIZE, "monospaced")) { |
169 JOptionPane.ERROR_MESSAGE) | 172 return |
170 } else { | 173 } |
171 val (plain, html) = when (selected.contents) { | 174 val (plain, html) = when (selected.contents) { |
172 is PasteboardItem.Plain -> | 175 is PasteboardItem.Plain -> |
173 Pair(selected.contents.plain, null) | 176 Pair(selected.contents.plain, null) |
174 is PasteboardItem.HTML -> | 177 is PasteboardItem.HTML -> |
175 Pair(selected.contents.plain, selected.contents.html) | 178 Pair(selected.contents.plain, selected.contents.html) |
176 is PasteboardItem.RTF -> | 179 is PasteboardItem.RTF -> |
177 Pair(selected.contents.plain, selected.contents.html) | 180 Pair(selected.contents.plain, selected.contents.html) |
178 } | 181 } |
179 if (html == null) { | 182 PasteboardItem.write( |
180 JOptionPane.showMessageDialog(Application.frame, | 183 PasteboardItem.HTML( |
181 "Only styled texts may be coerced.", | 184 plain, |
182 "Error", | 185 coerceHTML(html!!, normalizeFont(pFamily), pSize, |
183 JOptionPane.ERROR_MESSAGE) | 186 normalizeFont(mFamily), mSize))) |
184 } else { | |
185 if (badSize(_pSize, PROP_SIZE, "proportionally-spaced") || badSize(_mSize, MONO_SIZE, "monospaced")) { | |
186 return | |
187 } | |
188 PasteboardItem.write( | |
189 PasteboardItem.HTML( | |
190 plain, | |
191 coerceHTML(html, normalizeFont(pFamily), pSize, | |
192 normalizeFont(mFamily), mSize))) | |
193 } | |
194 } | |
195 } | 187 } |
196 | 188 |
197 private fun badSize(control: JComboBox<Float>, default: Int, fontType: String): Boolean { | 189 private fun badSize(control: JComboBox<Float>, default: Int, fontType: String): Boolean { |
198 val size = control.selectedItem as? Float | 190 val size = control.selectedItem as? Float |
199 if (size == null || size < 1.0f) { | 191 if (size == null || size < 1.0f) { |
224 "sansserif" -> "sans-serif" | 216 "sansserif" -> "sans-serif" |
225 else -> font | 217 else -> font |
226 } | 218 } |
227 } | 219 } |
228 } | 220 } |
221 | |
222 /** | |
223 * See if the selected pasteboard item is suitable for coercing. If not, | |
224 * issue an error dialog. | |
225 */ | |
226 fun suitedForCoercing(selected: QueueItem?): Boolean { | |
227 if (selected == null) { | |
228 JOptionPane.showMessageDialog(Application.frame, | |
229 "No item selected.", | |
230 "Error", | |
231 JOptionPane.ERROR_MESSAGE) | |
232 return false | |
233 } | |
234 if (selected.contents is PasteboardItem.Plain) { | |
235 JOptionPane.showMessageDialog(Application.frame, | |
236 "Only styled texts may be coerced.", | |
237 "Error", | |
238 JOptionPane.ERROR_MESSAGE) | |
239 return false | |
240 } | |
241 return true | |
242 } |