annotate src/name/blackcap/imageprep/SettingsDialog.kt @ 24:a4737a525af8

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