comparison src/name/blackcap/imageprep/SettingsDialog.kt @ 26:9bf3d8de6904

Fix Preferences bug, bump version number.
author David Barts <n5jrn@me.com>
date Sun, 13 Dec 2020 11:20:06 -0800
parents d3979a2155a8
children 098c4f5507c7
comparison
equal deleted inserted replaced
24:a4737a525af8 26:9bf3d8de6904
13 import java.io.OutputStreamWriter 13 import java.io.OutputStreamWriter
14 import java.util.Properties 14 import java.util.Properties
15 import java.util.logging.Level 15 import java.util.logging.Level
16 import java.util.logging.Logger 16 import java.util.logging.Logger
17 import javax.swing.* 17 import javax.swing.*
18 import javax.swing.event.ChangeEvent
19 import javax.swing.event.ChangeListener
18 import kotlin.text.toInt 20 import kotlin.text.toInt
19 21
20 /* work around name shadowing */ 22 /* work around name shadowing */
21 private val _PROPS = PROPERTIES 23 private val _PROPS = PROPERTIES
22 24
42 val outputSuffix: String 44 val outputSuffix: String
43 get() { 45 get() {
44 return _outputSuffix.text 46 return _outputSuffix.text
45 } 47 }
46 48
47 /* output to input dir? */ 49 /* button to change that other directory */
48 private val otid = _PROPS.getBoolean("outputToInputDir") 50 private val otid = _PROPS.getBoolean("outputToInputDir")
49 private val outputToInputButton = JRadioButton("Create output file in same folder as input.", otid).apply {
50 alignmentX = LEFT_ALIGNMENT
51 }
52 val outputToInputDir: Boolean
53 get() {
54 return outputToInputButton.isSelected()
55 }
56
57 /* output to some other directory */
58 private val outputToButton = JRadioButton("Create output file in:", !otid).apply {
59 alignmentX = LEFT_ALIGNMENT
60 }
61
62 /* name of the other directory */
63 private val oto = _getOutputTo()
64 protected val outputToText = JTextField(oto, 40).apply {
65 setEditable(false)
66 noTaller()
67 }
68
69 /* chooser for other directory */
70 private val _outputTo = JFileChooser(oto).apply {
71 fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
72 setMultiSelectionEnabled(false)
73 }
74 val outputTo: String
75 get() {
76 return _outputTo.selectedFile?.getCanonicalPath() ?: oto
77 }
78
79 /* button to change that other directory */
80 protected val changeOutputTo = JButton("Change").also { 51 protected val changeOutputTo = JButton("Change").also {
81 it.noTaller() 52 it.noTaller()
82 it.addActionListener(ActionListener { 53 it.addActionListener(ActionListener {
83 val status = _outputTo.showOpenDialog(this) 54 val status = _outputTo.showOpenDialog(this)
84 if (status == JFileChooser.APPROVE_OPTION) { 55 if (status == JFileChooser.APPROVE_OPTION) {
85 val path = outputTo 56 val path = outputTo
86 outputToText.text = path 57 outputToText.text = path
87 } 58 }
88 }) 59 })
89 it.setEnabled(!otid) 60 it.setEnabled(!otid)
61 }
62
63 /* output to input dir? */
64 private val outputToInputButton = JRadioButton("Create output file in same folder as input.", otid).apply {
65 alignmentX = LEFT_ALIGNMENT
66 }
67 val outputToInputDir: Boolean
68 get() {
69 return outputToInputButton.isSelected()
70 }
71
72 /* output to some other directory */
73 private val outputToButton = JRadioButton("Create output file in:", !otid).apply {
74 alignmentX = LEFT_ALIGNMENT
75 addChangeListener(ChangeListener {
76 changeOutputTo.setEnabled(isSelected())
77 })
78 }
79
80 /* name of the other directory */
81 private val oto = _getOutputTo()
82 protected val outputToText = JTextField(oto, 40).apply {
83 setEditable(false)
84 noTaller()
85 }
86
87 /* chooser for other directory */
88 private val _outputTo = JFileChooser(oto).apply {
89 fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
90 setMultiSelectionEnabled(false)
91 }
92 val outputTo: String
93 get() {
94 return _outputTo.selectedFile?.getCanonicalPath() ?: oto
90 } 95 }
91 96
92 /* radio button group */ 97 /* radio button group */
93 protected val buttonGroup = ButtonGroup().apply { 98 protected val buttonGroup = ButtonGroup().apply {
94 add(outputToButton) 99 add(outputToButton)