Mercurial > cgi-bin > hgweb.cgi > ClipMan
diff 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 |
line wrap: on
line diff
--- a/src/name/blackcap/clipman/CoerceDialog.kt Wed Feb 05 16:47:25 2020 -0800 +++ b/src/name/blackcap/clipman/CoerceDialog.kt Sat Feb 08 22:10:01 2020 -0700 @@ -17,19 +17,18 @@ import javax.swing.event.DocumentEvent import javax.swing.event.DocumentListener +val FONTS = + GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply { + sort() + } +val SIZES = + arrayOf(9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 16.0f, 18.0f, + 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 96.0f, 144.0f, 288.0f) + class CoerceDialog: JDialog(frame.v), ActionListener { - private val FONTS = - GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply { - sort() - } - private val SIZES = - arrayOf(9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 16.0f, 18.0f, - 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 96.0f, 144.0f, 288.0f) - private val DSIZEI = 6 /* SIZES[6] = 16 */ - /* the proportional font family */ private val _pFamily = JComboBox<String>(FONTS).apply { - selectedIndex = getFontIndex(Font.SERIF) + selectedItem = settingsDialog.pFamily alignmentX = JComboBox.LEFT_ALIGNMENT } val pFamily: String @@ -39,7 +38,7 @@ /* the proportional font size */ private val _pSize = JComboBox<Float>(SIZES).also { - it.selectedIndex = DSIZEI + it.selectedItem = settingsDialog.pSize it.alignmentX = JComboBox.LEFT_ALIGNMENT it.setEditable(true) } @@ -50,7 +49,7 @@ /* the monospaced font family */ private val _mFamily = JComboBox<String>(FONTS).apply { - selectedIndex = getFontIndex(Font.MONOSPACED) + selectedItem = settingsDialog.mFamily alignmentX = JComboBox.LEFT_ALIGNMENT } val mFamily: String @@ -60,7 +59,7 @@ /* the monospaced font size */ private val _mSize = JComboBox<Float>(SIZES).also { - it.selectedIndex = DSIZEI + it.selectedItem = settingsDialog.mSize it.alignmentX = JComboBox.LEFT_ALIGNMENT it.setEditable(true) } @@ -183,7 +182,7 @@ "Error", JOptionPane.ERROR_MESSAGE) } else { - if (badSize(_pSize, "proportionally-spaced") || badSize(_mSize, "monospaced")) { + if (badSize(_pSize, settingsDialog.pSize, "proportionally-spaced") || badSize(_mSize, settingsDialog.mSize, "monospaced")) { return } PasteboardItem.write( @@ -195,28 +194,19 @@ } } - private fun badSize(control: JComboBox<Float>, fontType: String): Boolean { + private fun badSize(control: JComboBox<Float>, default: Float, fontType: String): Boolean { val size = control.selectedItem as? Float if (size == null || size < 1.0f) { JOptionPane.showMessageDialog(frame.v, "Invalid ${fontType} font size.", "Error", JOptionPane.ERROR_MESSAGE) - control.selectedIndex = DSIZEI + control.selectedItem = default return true } return false } - private fun getFontIndex(font: String): Int { - val found = FONTS.indexOf(font) - if (found < 0) { - LOGGER.log(Level.WARNING, "font '${font}' not found") - return 0 - } - return found - } - private fun normalizeFont(font: String): String { val lcFont = font.toLowerCase() return when (lcFont) {