annotate src/name/blackcap/imageprep/SettingsDialog.kt @ 20:71029c9bf7cd

Commit overlooked files.
author David Barts <n5jrn@me.com>
date Sat, 21 Nov 2020 10:15:35 -0800
parents
children 0f3634a0816d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 /*
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 * The dialog that controls font corecion.
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 package name.blackcap.imageprep
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
5
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import java.awt.Dimension
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import java.awt.event.ActionEvent
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.event.ActionListener
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.io.BufferedWriter
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.io.File
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.io.FileOutputStream
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.io.IOException
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.io.OutputStreamWriter
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import java.util.Hashtable
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 import java.util.Properties
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import java.util.logging.Level
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 import java.util.logging.Logger
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 import javax.swing.*
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 import javax.swing.event.ChangeEvent
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 import javax.swing.event.ChangeListener
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 import kotlin.math.log10
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 import kotlin.math.pow
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 import kotlin.math.roundToInt
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 import kotlin.text.toInt
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
25
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 /* work around name shadowing */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 private val _PROPS = PROPERTIES
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
28
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 class SettingsDialog: JDialog(Application.mainFrame) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 /* maximum allowed dimension in output */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 private val _maxDimension = MaxDimSpinner(_PROPS.getInt("maxDimension"))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 val maxDimension: Int
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 get() {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 return _maxDimension.value as Int
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
36
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 /* JPEG output quality */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
38 private val _outputQuality = OutQualSpinner(_PROPS.getInt("outputQuality"))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 val outputQuality: Int
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 get() {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 return _outputQuality.value as Int
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
43
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 /* file name output suffix */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 private val _outputSuffix = JTextField(_PROPS.getProperty("outputSuffix"), 24).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 noTaller()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 val outputSuffix: String
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 get() {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 return _outputSuffix.text
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
52
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 /* output to input dir? */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 private val otid = _PROPS.getBoolean("outputToInputDir")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 private val outputToInputButton = JRadioButton("Create output file in same folder as input.", otid)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 val outputToInputDir: Boolean
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 get() {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 return outputToInputButton.isSelected()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
59 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
60
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
61 /* output to some other directory */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
62 private val outputToButton = JRadioButton("Create output file in:", !otid)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
63
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 /* name of the other directory */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 private val oto = _getOutputTo()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 protected val outputToText = JTextField(oto, 40).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 setEditable(false)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 noTaller()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
70
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 /* chooser for other directory */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 private val _outputTo = JFileChooser(oto).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 setMultiSelectionEnabled(false)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
75 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
76 val outputTo: String
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
77 get() {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 return _outputTo.selectedFile?.getCanonicalPath() ?: oto
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
79 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
80
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 /* button to change that other directory */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 protected val changeOutputTo = JButton("Change").also {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 it.noTaller()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 it.addActionListener(ActionListener {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 val status = _outputTo.showOpenDialog(this)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
86 if (status == JFileChooser.APPROVE_OPTION) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
87 val path = outputTo
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 outputToText.text = path
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
91 it.setEnabled(!otid)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
92 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
93
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 /* radio button group */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
95 protected val buttonGroup = ButtonGroup().apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 add(outputToButton)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 add(outputToInputButton)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
98 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
99
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 /* standard spacing between elements (10 pixels ≅ 1/7") and half that */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 private val BW = 5
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 private val BW2 = 10
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
103
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
104 /* buttons */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
105 private val _ok = JButton("OK").also {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
106 it.noTaller()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
107 it.addActionListener(ActionListener {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
108 writeProperties()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
109 setVisible(false)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
110 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
111 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
112
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
113 private val _cancel = JButton("Cancel").also {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
114 it.noTaller()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
115 it.addActionListener(ActionListener {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
116 revertValues()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
117 setVisible(false)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
118 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
119 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
120
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
121 /* initializer */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 init {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 title = "Preferences"
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 contentPane.apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 layout = BoxLayout(this, BoxLayout.Y_AXIS)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 add(Box(BoxLayout.X_AXIS).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
127 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 add(leftLabel("Maximum dimension:"))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
129 add(_maxDimension)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
130 add(Box.createGlue())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
131 add(leftLabel("Output quality:"))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
132 add(_outputQuality)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
133 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
134 add(Box(BoxLayout.X_AXIS).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
135 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 add(leftLabel("Output filename suffix:"))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
137 add(_outputSuffix)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
138 add(Box.createGlue())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 add(Box(BoxLayout.Y_AXIS).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
141 border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 add(outputToInputButton)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 add(outputToButton)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 add(Box(BoxLayout.X_AXIS).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
145 add(outputToText)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 add(changeOutputTo)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 add(Box.createGlue())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
148 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
149 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 add(Box(BoxLayout.X_AXIS).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
151 add(_cancel)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
152 add(Box.createGlue())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
153 add(_ok)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
154 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
155 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
156 rootPane.setDefaultButton(_ok)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
157 pack()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
158 setResizable(false)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
159 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
160
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
161 private fun leftLabel(text: String) = JLabel(text).apply {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
162 alignmentX = JLabel.LEFT_ALIGNMENT
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
163 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
164
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 private fun revertValues()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
166 {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
167 _maxDimension.value = _PROPS.getInt("maxDimension")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
168 _outputQuality.value = _PROPS.getInt("outputQuality")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
169 _outputSuffix.text = _PROPS.getProperty("outputSuffix")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
170 val otid = _PROPS.getBoolean("outputToInputDir")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
171 outputToInputButton.setSelected(otid)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
172 outputToButton.setSelected(!otid)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
173 val oto = _getOutputTo()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
174 outputToText.text = oto
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
175 _outputTo.selectedFile = File(oto)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
176 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
177
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
178 private fun writeProperties()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
179 {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
180 _PROPS.setInt("maxDimension", maxDimension)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
181 _PROPS.setInt("outputQuality", outputQuality)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
182 _PROPS.setProperty("outputSuffix", outputSuffix)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
183 _PROPS.setBoolean("outputToInputDir", outputToInputDir)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
184 _PROPS.setProperty("outputTo", outputTo)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
185 try {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
186 BufferedWriter(OutputStreamWriter(FileOutputStream(PROP_FILE), CHARSET)).use {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
187 _PROPS.store(it, " -*- coding: ${CHARSET} -*-")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
188 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
189 } catch (e: IOException) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
190 LOGGER.log(Level.WARNING, "IOException writing properties file")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
191 val message = e.message
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
192 if (message != null && !message.isEmpty()) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
193 LOGGER.log(Level.WARNING, message)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
194 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
195 JOptionPane.showMessageDialog(Application.mainFrame,
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
196 "Unable to write settings.",
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
197 "Error",
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
198 JOptionPane.ERROR_MESSAGE)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
199 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
200 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
201
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
202 private fun _getOutputTo(): String = _PROPS.getProperty("outputTo") ?: System.getProperty("user.dir")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
203 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
204
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
205 fun Properties.getString(key: String): String = getProperty(key) as String
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
206
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
207 fun Properties.getInt(key: String): Int = getString(key).toInt()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
208
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
209 fun Properties.setInt(key: String, value: Int): Unit {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
210 setProperty(key, value.toString())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
211 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
212
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
213 fun Properties.getBoolean(key: String): Boolean {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
214 val raw = getProperty(key)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
215 if (raw.isNullOrEmpty())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
216 return false
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
217 val c1 = raw[0].toLowerCase()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
218 return c1 == 't' || c1 == 'y'
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
219 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
220
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
221 fun Properties.setBoolean(key: String, value: Boolean): Unit {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
222 setProperty(key, value.toString())
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
223 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
224
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
225 fun JComponent.noTaller() {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
226 maximumSize = Dimension(maximumSize.width, preferredSize.height)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
227 }