Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison src/name/blackcap/clipman/CoerceDialog.kt @ 41:33fbe3a78d84
Got the settings stuff compiling (untested).
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 08 Feb 2020 22:10:01 -0700 |
parents | 08eaae2aaf76 |
children | 339e2da5bf83 |
comparison
equal
deleted
inserted
replaced
40:c803a2c89ea0 | 41:33fbe3a78d84 |
---|---|
15 import java.util.logging.Logger | 15 import java.util.logging.Logger |
16 import javax.swing.* | 16 import javax.swing.* |
17 import javax.swing.event.DocumentEvent | 17 import javax.swing.event.DocumentEvent |
18 import javax.swing.event.DocumentListener | 18 import javax.swing.event.DocumentListener |
19 | 19 |
20 val FONTS = | |
21 GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply { | |
22 sort() | |
23 } | |
24 val SIZES = | |
25 arrayOf(9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 16.0f, 18.0f, | |
26 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 96.0f, 144.0f, 288.0f) | |
27 | |
20 class CoerceDialog: JDialog(frame.v), ActionListener { | 28 class CoerceDialog: JDialog(frame.v), ActionListener { |
21 private val FONTS = | |
22 GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply { | |
23 sort() | |
24 } | |
25 private val SIZES = | |
26 arrayOf(9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 16.0f, 18.0f, | |
27 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 96.0f, 144.0f, 288.0f) | |
28 private val DSIZEI = 6 /* SIZES[6] = 16 */ | |
29 | |
30 /* the proportional font family */ | 29 /* the proportional font family */ |
31 private val _pFamily = JComboBox<String>(FONTS).apply { | 30 private val _pFamily = JComboBox<String>(FONTS).apply { |
32 selectedIndex = getFontIndex(Font.SERIF) | 31 selectedItem = settingsDialog.pFamily |
33 alignmentX = JComboBox.LEFT_ALIGNMENT | 32 alignmentX = JComboBox.LEFT_ALIGNMENT |
34 } | 33 } |
35 val pFamily: String | 34 val pFamily: String |
36 get() { | 35 get() { |
37 return _pFamily.selectedItem as String | 36 return _pFamily.selectedItem as String |
38 } | 37 } |
39 | 38 |
40 /* the proportional font size */ | 39 /* the proportional font size */ |
41 private val _pSize = JComboBox<Float>(SIZES).also { | 40 private val _pSize = JComboBox<Float>(SIZES).also { |
42 it.selectedIndex = DSIZEI | 41 it.selectedItem = settingsDialog.pSize |
43 it.alignmentX = JComboBox.LEFT_ALIGNMENT | 42 it.alignmentX = JComboBox.LEFT_ALIGNMENT |
44 it.setEditable(true) | 43 it.setEditable(true) |
45 } | 44 } |
46 val pSize: Float | 45 val pSize: Float |
47 get() { | 46 get() { |
48 return _pSize.selectedItem as Float | 47 return _pSize.selectedItem as Float |
49 } | 48 } |
50 | 49 |
51 /* the monospaced font family */ | 50 /* the monospaced font family */ |
52 private val _mFamily = JComboBox<String>(FONTS).apply { | 51 private val _mFamily = JComboBox<String>(FONTS).apply { |
53 selectedIndex = getFontIndex(Font.MONOSPACED) | 52 selectedItem = settingsDialog.mFamily |
54 alignmentX = JComboBox.LEFT_ALIGNMENT | 53 alignmentX = JComboBox.LEFT_ALIGNMENT |
55 } | 54 } |
56 val mFamily: String | 55 val mFamily: String |
57 get() { | 56 get() { |
58 return _mFamily.selectedItem as String | 57 return _mFamily.selectedItem as String |
59 } | 58 } |
60 | 59 |
61 /* the monospaced font size */ | 60 /* the monospaced font size */ |
62 private val _mSize = JComboBox<Float>(SIZES).also { | 61 private val _mSize = JComboBox<Float>(SIZES).also { |
63 it.selectedIndex = DSIZEI | 62 it.selectedItem = settingsDialog.mSize |
64 it.alignmentX = JComboBox.LEFT_ALIGNMENT | 63 it.alignmentX = JComboBox.LEFT_ALIGNMENT |
65 it.setEditable(true) | 64 it.setEditable(true) |
66 } | 65 } |
67 val mSize: Float | 66 val mSize: Float |
68 get() { | 67 get() { |
181 JOptionPane.showMessageDialog(frame.v, | 180 JOptionPane.showMessageDialog(frame.v, |
182 "Only styled texts may be coerced.", | 181 "Only styled texts may be coerced.", |
183 "Error", | 182 "Error", |
184 JOptionPane.ERROR_MESSAGE) | 183 JOptionPane.ERROR_MESSAGE) |
185 } else { | 184 } else { |
186 if (badSize(_pSize, "proportionally-spaced") || badSize(_mSize, "monospaced")) { | 185 if (badSize(_pSize, settingsDialog.pSize, "proportionally-spaced") || badSize(_mSize, settingsDialog.mSize, "monospaced")) { |
187 return | 186 return |
188 } | 187 } |
189 PasteboardItem.write( | 188 PasteboardItem.write( |
190 PasteboardItem.HTML( | 189 PasteboardItem.HTML( |
191 plain, | 190 plain, |
193 normalizeFont(mFamily), mSize))) | 192 normalizeFont(mFamily), mSize))) |
194 } | 193 } |
195 } | 194 } |
196 } | 195 } |
197 | 196 |
198 private fun badSize(control: JComboBox<Float>, fontType: String): Boolean { | 197 private fun badSize(control: JComboBox<Float>, default: Float, fontType: String): Boolean { |
199 val size = control.selectedItem as? Float | 198 val size = control.selectedItem as? Float |
200 if (size == null || size < 1.0f) { | 199 if (size == null || size < 1.0f) { |
201 JOptionPane.showMessageDialog(frame.v, | 200 JOptionPane.showMessageDialog(frame.v, |
202 "Invalid ${fontType} font size.", | 201 "Invalid ${fontType} font size.", |
203 "Error", | 202 "Error", |
204 JOptionPane.ERROR_MESSAGE) | 203 JOptionPane.ERROR_MESSAGE) |
205 control.selectedIndex = DSIZEI | 204 control.selectedItem = default |
206 return true | 205 return true |
207 } | 206 } |
208 return false | 207 return false |
209 } | |
210 | |
211 private fun getFontIndex(font: String): Int { | |
212 val found = FONTS.indexOf(font) | |
213 if (found < 0) { | |
214 LOGGER.log(Level.WARNING, "font '${font}' not found") | |
215 return 0 | |
216 } | |
217 return found | |
218 } | 208 } |
219 | 209 |
220 private fun normalizeFont(font: String): String { | 210 private fun normalizeFont(font: String): String { |
221 val lcFont = font.toLowerCase() | 211 val lcFont = font.toLowerCase() |
222 return when (lcFont) { | 212 return when (lcFont) { |