Mercurial > cgi-bin > hgweb.cgi > ClipMan
annotate src/name/blackcap/clipman/SettingsDialog.kt @ 42:99220aa136d9
Add default.properties.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 08 Feb 2020 23:05:39 -0700 |
parents | 33fbe3a78d84 |
children | 339e2da5bf83 |
rev | line source |
---|---|
41
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 /* |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 * The dialog that controls font corecion. |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
3 */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
4 package name.blackcap.clipman |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
5 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
6 import java.awt.Color |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 import java.awt.Container |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
8 import java.awt.Dimension |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 import java.awt.Font |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
10 import java.awt.GraphicsEnvironment |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 import java.awt.Toolkit |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
12 import java.awt.event.ActionEvent |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 import java.awt.event.ActionListener |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 import java.io.BufferedWriter |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 import java.io.FileOutputStream |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 import java.io.IOException |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 import java.io.OutputStreamWriter |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 import java.util.Hashtable |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 import java.util.Properties |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
20 import java.util.logging.Level |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
21 import java.util.logging.Logger |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 import javax.swing.* |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 import javax.swing.event.ChangeEvent |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 import javax.swing.event.ChangeListener |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 import kotlin.math.log10 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 import kotlin.math.pow |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 import kotlin.math.roundToInt |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 import kotlin.text.toFloat |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 import kotlin.text.toInt |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
30 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
31 /* work around name shadowing */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
32 private val _PROPS = PROPERTIES |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
33 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
34 class SettingsDialog: JDialog(frame.v), ActionListener, ChangeListener { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
35 /* the proportional font family */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
36 private val _pFamily = JComboBox<String>(FONTS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
37 selectedItem = _PROPS.getString("prop.family") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
38 alignmentX = JComboBox.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 val pFamily: String |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 get() { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
42 return _pFamily.selectedItem as String |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 /* the proportional font size */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
46 private val _pSize = JComboBox<Float>(SIZES).also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
47 it.selectedItem = _PROPS.getFloat("prop.size") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 it.alignmentX = JComboBox.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 it.setEditable(true) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 val pSize: Float |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
52 get() { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 return _pSize.selectedItem as Float |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
55 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
56 /* the monospaced font family */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
57 private val _mFamily = JComboBox<String>(FONTS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
58 selectedItem = _PROPS.getString("mono.family") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
59 alignmentX = JComboBox.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
60 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
61 val mFamily: String |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
62 get() { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
63 return _mFamily.selectedItem as String |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 /* the monospaced font size */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 private val _mSize = JComboBox<Float>(SIZES).also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
68 it.selectedItem = _PROPS.getFloat("mono.size") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 it.alignmentX = JComboBox.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 it.setEditable(true) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 val mSize: Float |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
73 get() { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 return _mSize.selectedItem as Float |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
75 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
77 /* max queue length */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 private val _qLength = _PROPS.getInt("queue.length") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 private val _qlSlider = JSlider(10000, 30000, spinToSlide(_qLength)).also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 it.majorTickSpacing = 10000 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 it.paintTicks = true |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 it.labelTable = Hashtable<Int, String>().apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
83 put(10000, "10") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
84 put(20000, "100") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 put(30000, "1000") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
86 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
87 it.addChangeListener(this) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 private val _qlSpinner = JSpinner(SpinnerNumberModel(_qLength, 10, 1000, 1)).also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
90 it.addChangeListener(this) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
92 val qLength: Int |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 get() { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 return _qlSpinner.value as Int |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
95 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 /* standard spacing between elements (10 pixels ≅ 1/7") and half that */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
98 private val BW = 5 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 private val BW2 = 10 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
101 /* buttons */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 private val _ok = JButton("OK").also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 it.actionCommand = "OK" |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 it.addActionListener(this) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 private val _cancel = JButton("Cancel").also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
108 it.actionCommand = "Cancel" |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
109 it.addActionListener(this) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
110 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
111 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
112 private val _rad = JButton("Restore All Defaults").also { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 it.actionCommand = "Restore" |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 it.addActionListener(this) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
115 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
116 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
117 /* initializer */ |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
118 init { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
119 title = "Preferences" |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 contentPane.apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
124 alignmentX = Box.CENTER_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 add(leftLabel("Default proportionally-spaced font:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 add(Box.createVerticalStrut(BW)) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 add(Box(BoxLayout.X_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 alignmentX = Box.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
131 add(leftLabel("Family:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 add(_pFamily) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
135 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 add(leftLabel("Size:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 add(_pSize) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
138 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
139 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
140 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
141 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
142 add(JSeparator()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
143 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
144 alignmentX = Box.CENTER_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
145 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 add(leftLabel("Default monospaced font:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 add(Box.createVerticalStrut(BW)) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
148 add(Box(BoxLayout.X_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 alignmentX = Box.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
150 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
151 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
152 add(leftLabel("Family:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
153 add(_mFamily) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
154 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
155 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 add(leftLabel("Size:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
158 add(_mSize) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
161 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
162 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
163 add(JSeparator()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
164 add(Box(BoxLayout.Y_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
165 alignmentX = Box.CENTER_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
166 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
167 add(leftLabel("Maximum queue size:")) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
168 add(Box.createVerticalStrut(BW)) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
169 add(Box(BoxLayout.X_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
170 alignmentX = Box.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
171 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
172 add(_qlSlider) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
173 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
174 add(_qlSpinner) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
175 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
176 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
177 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
178 add(JSeparator()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
179 add(Box(BoxLayout.X_AXIS).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
180 alignmentX = Box.CENTER_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
181 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
182 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
183 add(_rad) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
184 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
185 add(_cancel) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
186 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
187 add(_ok) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
188 add(Box.createGlue()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
189 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
190 }) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
191 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
192 rootPane.setDefaultButton(_ok) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
193 pack() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
194 setResizable(false) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
195 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
196 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
197 override fun actionPerformed(e: ActionEvent) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
198 when (e.actionCommand) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
199 "OK" -> { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
200 writeProperties() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
201 queue.v.maxSize = qLength |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
202 setVisible(false) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
203 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
204 "Cancel" -> setVisible(false) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
205 "Restore" -> revertProperties() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
206 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
207 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
208 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
209 override fun stateChanged(e: ChangeEvent) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
210 when (val source = e.source) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
211 source === _qlSlider -> |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
212 _qlSpinner.value = (10.0).pow(_qlSlider.value.toDouble() / 10000.0).roundToInt() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
213 source === _qlSpinner -> |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
214 _qlSlider.value = spinToSlide(_qlSpinner.value as Int) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
215 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
216 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
217 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
218 private fun spinToSlide(value: Int): Int = |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
219 (log10(value.toDouble()) * 10000.0).roundToInt() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
220 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
221 private fun leftLabel(text: String) = JLabel(text).apply { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
222 alignmentX = JLabel.LEFT_ALIGNMENT |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
223 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
224 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
225 private fun badSize(control: JComboBox<Float>, default: Float, fontType: String): Boolean { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
226 val size = control.selectedItem as? Float |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
227 if (size == null || size < 1.0f) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
228 JOptionPane.showMessageDialog(frame.v, |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
229 "Invalid ${fontType} font size.", |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
230 "Error", |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
231 JOptionPane.ERROR_MESSAGE) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
232 control.selectedItem = default |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
233 return true |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
234 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
235 return false |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
236 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
237 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
238 private fun revertProperties() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
239 { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
240 val params = arrayOf("mono.family", "mono.size", "prop.family", "prop.size", "queue.length") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
241 for (param in params) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
242 _PROPS.put(param, DPROPERTIES.get(param)) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
243 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
244 _mFamily.selectedItem = _PROPS.getString("mono.family") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
245 _mSize.selectedItem = _PROPS.getFloat("mono.size") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
246 _pFamily.selectedItem = _PROPS.getString("prop.family") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
247 _pSize.selectedItem = _PROPS.getFloat("prop.size") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
248 val ql = _PROPS.getInt("queue.length") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
249 _qlSpinner.value = ql |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
250 _qlSlider.value = spinToSlide(ql) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
251 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
252 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
253 private fun writeProperties() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
254 { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
255 try { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
256 BufferedWriter(OutputStreamWriter(FileOutputStream(PROP_FILE), CHARSET)).use { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
257 _PROPS.put("mono.family", mFamily) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
258 _PROPS.put("mono.size", mSize.toString()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
259 _PROPS.put("prop.family", pFamily) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
260 _PROPS.put("prop.size", pSize.toString()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
261 _PROPS.put("queue.length", qLength.toString()) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
262 _PROPS.store(it, null) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
263 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
264 } catch (e: IOException) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
265 LOGGER.log(Level.WARNING, "IOException writing properties file") |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
266 val message = e.message |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
267 if (message != null && !message.isEmpty()) { |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
268 LOGGER.log(Level.WARNING, message) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
269 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
270 JOptionPane.showMessageDialog(frame.v, |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
271 "Unable to write settings.", |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
272 "Error", |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
273 JOptionPane.ERROR_MESSAGE) |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
274 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
275 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
276 } |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
277 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
278 val settingsDialog = SettingsDialog() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
279 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
280 fun Properties.getString(key: String): String = get(key) as String |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
281 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
282 fun Properties.getInt(key: String): Int = getString(key).toInt() |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
283 |
33fbe3a78d84
Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
284 fun Properties.getFloat(key: String): Float = getString(key).toFloat() |