comparison src/name/blackcap/clipman/SettingsDialog.kt @ 44:d14298ef8b0a

Fix some settings/preferences issues.
author David Barts <n5jrn@me.com>
date Sun, 09 Feb 2020 22:13:26 -0700
parents 339e2da5bf83
children ca8a23bae4fa
comparison
equal deleted inserted replaced
43:339e2da5bf83 44:d14298ef8b0a
1 /* 1 /*
2 * The dialog that controls font corecion. 2 * The dialog that controls font corecion.
3 */ 3 */
4 package name.blackcap.clipman 4 package name.blackcap.clipman
5 5
6 import java.awt.Dimension
6 import java.awt.event.ActionEvent 7 import java.awt.event.ActionEvent
7 import java.awt.event.ActionListener 8 import java.awt.event.ActionListener
8 import java.io.BufferedWriter 9 import java.io.BufferedWriter
9 import java.io.FileOutputStream 10 import java.io.FileOutputStream
10 import java.io.IOException 11 import java.io.IOException
28 /* max queue length */ 29 /* max queue length */
29 private val _qLength = _PROPS.getInt("queue.length") 30 private val _qLength = _PROPS.getInt("queue.length")
30 private val _qlSlider = JSlider(10000, 30000, spinToSlide(_qLength)).also { 31 private val _qlSlider = JSlider(10000, 30000, spinToSlide(_qLength)).also {
31 it.majorTickSpacing = 10000 32 it.majorTickSpacing = 10000
32 it.paintTicks = true 33 it.paintTicks = true
33 it.labelTable = Hashtable<Int, String>().apply { 34 it.labelTable = Hashtable<Int, JComponent>().apply {
34 put(10000, "10") 35 put(10000, JLabel("10"))
35 put(20000, "100") 36 put(20000, JLabel("100"))
36 put(30000, "1000") 37 put(30000, JLabel("1000"))
37 } 38 }
39 it.paintLabels = true
38 it.addChangeListener(this) 40 it.addChangeListener(this)
39 } 41 }
40 private val _qlSpinner = JSpinner(SpinnerNumberModel(_qLength, 10, 1000, 1)).also { 42 private val _qlSpinner = JSpinner(SpinnerNumberModel(_qLength, 10, 1000, 1)).also {
41 it.addChangeListener(this) 43 it.addChangeListener(this)
44 it.maximumSize = Dimension(it.maximumSize.width, it.preferredSize.height)
45 (it.editor as? JSpinner.DefaultEditor)?.getTextField()?.setEditable(false)
42 } 46 }
43 val qLength: Int 47 val qLength: Int
44 get() { 48 get() {
45 return _qlSpinner.value as Int 49 return _qlSpinner.value as Int
46 } 50 }
109 } 113 }
110 } 114 }
111 } 115 }
112 116
113 override fun stateChanged(e: ChangeEvent) { 117 override fun stateChanged(e: ChangeEvent) {
114 when (val source = e.source) { 118 when (e.source) {
115 source === _qlSlider -> 119 is JSlider ->
116 _qlSpinner.value = (10.0).pow(_qlSlider.value.toDouble() / 10000.0).roundToInt() 120 _qlSpinner.value = (10.0).pow(_qlSlider.value.toDouble() / 10000.0).roundToInt()
117 source === _qlSpinner -> 121 is JSpinner ->
118 _qlSlider.value = spinToSlide(_qlSpinner.value as Int) 122 _qlSlider.value = spinToSlide(_qlSpinner.value as Int)
119 } 123 }
120 } 124 }
121 125
122 private fun spinToSlide(value: Int): Int = 126 private fun spinToSlide(value: Int): Int =
154 } 158 }
155 } 159 }
156 160
157 val settingsDialog = SettingsDialog() 161 val settingsDialog = SettingsDialog()
158 162
159 fun Properties.getString(key: String): String = get(key) as String 163 fun Properties.getString(key: String): String = getProperty(key) as String
160 164
161 fun Properties.getInt(key: String): Int = getString(key).toInt() 165 fun Properties.getInt(key: String): Int = getString(key).toInt()