comparison src/name/blackcap/clipman/SettingsDialog.kt @ 47:19d9da731c43

Recoded; cleaned up root namespace, removed race conditions.
author David Barts <n5jrn@me.com>
date Sun, 12 Apr 2020 14:31:06 -0700
parents ca8a23bae4fa
children
comparison
equal deleted inserted replaced
46:88066346f129 47:19d9da731c43
23 import kotlin.text.toInt 23 import kotlin.text.toInt
24 24
25 /* work around name shadowing */ 25 /* work around name shadowing */
26 private val _PROPS = PROPERTIES 26 private val _PROPS = PROPERTIES
27 27
28 class SettingsDialog: JDialog(frame.v), ActionListener, ChangeListener { 28 class SettingsDialog: JDialog(Application.frame), ActionListener, ChangeListener {
29 /* max queue length */ 29 /* max queue length */
30 private val _qLength = _PROPS.getInt("queue.length") 30 private val _qLength = _PROPS.getInt("queue.length")
31 private val _qlSlider = JSlider(10000, 30000, spinToSlide(_qLength)).also { 31 private val _qlSlider = JSlider(10000, 30000, spinToSlide(_qLength)).also {
32 it.majorTickSpacing = 10000 32 it.majorTickSpacing = 10000
33 it.paintTicks = true 33 it.paintTicks = true
102 102
103 override fun actionPerformed(e: ActionEvent) { 103 override fun actionPerformed(e: ActionEvent) {
104 when (e.actionCommand) { 104 when (e.actionCommand) {
105 "OK" -> { 105 "OK" -> {
106 writeProperties() 106 writeProperties()
107 queue.v.maxSize = qLength 107 Application.queue.maxSize = qLength
108 setVisible(false) 108 setVisible(false)
109 } 109 }
110 "Cancel" -> { 110 "Cancel" -> {
111 revertValues() 111 revertValues()
112 setVisible(false) 112 setVisible(false)
148 LOGGER.log(Level.WARNING, "IOException writing properties file") 148 LOGGER.log(Level.WARNING, "IOException writing properties file")
149 val message = e.message 149 val message = e.message
150 if (message != null && !message.isEmpty()) { 150 if (message != null && !message.isEmpty()) {
151 LOGGER.log(Level.WARNING, message) 151 LOGGER.log(Level.WARNING, message)
152 } 152 }
153 JOptionPane.showMessageDialog(frame.v, 153 JOptionPane.showMessageDialog(Application.frame,
154 "Unable to write settings.", 154 "Unable to write settings.",
155 "Error", 155 "Error",
156 JOptionPane.ERROR_MESSAGE) 156 JOptionPane.ERROR_MESSAGE)
157 } 157 }
158 } 158 }
159 } 159 }
160 160
161 val settingsDialog = SettingsDialog()
162
163 fun Properties.getString(key: String): String = getProperty(key) as String 161 fun Properties.getString(key: String): String = getProperty(key) as String
164 162
165 fun Properties.getInt(key: String): Int = getString(key).toInt() 163 fun Properties.getInt(key: String): Int = getString(key).toInt()