Mercurial > cgi-bin > hgweb.cgi > JpegWasher
annotate src/name/blackcap/exifwasher/SettingsDialog.kt @ 16:304492a6b72b
Add a Readme file.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sat, 11 Apr 2020 11:24:25 -0700 |
parents | aafc9c127c7b |
children | 40911898ed23 |
rev | line source |
---|---|
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 /* |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 * The dialog that controls our settings. |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
3 */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
4 package name.blackcap.exifwasher |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
5 |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
6 import java.awt.Dimension |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 import java.awt.Toolkit |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
8 import java.awt.event.ActionEvent |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 import java.awt.event.ActionListener |
5 | 10 import java.io.BufferedWriter |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 import java.io.File |
5 | 12 import java.io.FileOutputStream |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 import java.io.IOException |
5 | 14 import java.io.OutputStreamWriter |
15 import java.util.Properties | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 import java.util.logging.Level |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 import java.util.logging.Logger |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 import javax.swing.* |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 import javax.swing.event.ListDataEvent |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
20 import javax.swing.event.ListDataListener |
5 | 21 import javax.swing.event.ListSelectionListener |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 import kotlin.text.toBoolean |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 import name.blackcap.exifwasher.exiv2.* |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 |
5 | 26 /* work around name shadowing */ |
27 private val _PROPS = PROPERTIES | |
28 | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 class SettingsDialog : JDialog(Application.mainFrame) { |
5 | 30 protected val BW = 9 |
31 protected val BW2 = BW * 2 | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
32 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
33 /* where to send output, if not outputToInputDir */ |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
34 private var homeDir = System.getProperty("user.home") |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
35 protected var _outputTo = _PROPS.getNotEmpty("outputTo", homeDir) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
36 protected var _dOutputTo = DPROPERTIES.getNotEmpty("outputTo", homeDir) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
37 val outputTo: String |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
38 get() = _outputTo |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 /* make output where input was found */ |
5 | 41 protected var _outputToInputDir = _PROPS.getProperty("outputToInputDir", "false").toBoolean() |
42 protected var _dOutputToInputDir = DPROPERTIES.getProperty("outputToInputDir", "false").toBoolean() | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 val outputToInputDir: Boolean |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 get() = _outputToInputDir |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
46 /* the whitelist of allowed Exif tags */ |
5 | 47 protected var _whitelist = Whitelist.parse(_PROPS.getProperty("whitelist", "")) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 val whitelist: Whitelist |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 get() = _whitelist |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 /* the default whitelist, for factory resets */ |
5 | 52 protected val _oWhitelist = _whitelist.clone() |
53 protected val _dWhitelist = Whitelist.parse(DPROPERTIES.getProperty("whitelist", "")) | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
55 /* radio buttons to choose output directory policy */ |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
56 protected val outputToButton = JRadioButton("Output to:", !outputToInputDir).also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
57 it.addActionListener(ActionListener { _ -> setOutputOpts(it.isSelected()) }) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
58 it.noTaller() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
59 } |
5 | 60 protected val outputToInputButton = JRadioButton( |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
61 "Output to directory containing input file.", outputToInputDir).also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
62 it.addActionListener(ActionListener { _ -> setOutputOpts(!it.isSelected()) }) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
63 it.noTaller() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 } |
5 | 65 protected val buttonGroup = ButtonGroup().apply { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 add(outputToButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 add(outputToInputButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
68 } |
5 | 69 protected fun setOutputOpts(toSpecific: Boolean) { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 _outputToInputDir = !toSpecific |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 changeOutputTo.setEnabled(toSpecific) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
73 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 /* displays the OutputTo directory */ |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
75 protected val outputToText = JTextField(outputTo, 40).apply { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 setEditable(false) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
77 noTaller() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 /* pops up to change the above directory */ |
5 | 81 protected val outputToChooser = JFileChooser(outputToText.text).apply { |
82 fileSelectionMode = JFileChooser.DIRECTORIES_ONLY | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
83 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
84 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 /* requests the OutputTo directory be changed */ |
5 | 86 protected val changeOutputTo = JButton("Change").also { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
87 it.addActionListener(ActionListener { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 val status = outputToChooser.showOpenDialog(this) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 if (status == JFileChooser.APPROVE_OPTION) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
90 _outputTo = outputToChooser.selectedFile.canonicalPath |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 outputToText.text = _outputTo |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
92 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 it.setEnabled(!outputToInputDir) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
95 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 /* bottom buttons to restore defaults, cancel, save */ |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
98 protected val restoreButton = JButton("Restore All Defaults").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
99 it.addActionListener(ActionListener { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 restore(_dOutputToInputDir, _dOutputTo, _dWhitelist) |
5 | 101 }) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 } |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
103 protected val cancelButton = JButton("Cancel").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
104 it.addActionListener(ActionListener { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 setVisible(false) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 restore(outputToInputDir, outputTo, whitelist) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
108 } |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
109 protected val saveButton = JButton("Save").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
110 it.addActionListener(ActionListener { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
111 setVisible(false) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
112 writeProperties() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
115 |
5 | 116 protected fun writeProperties() { |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
117 _whitelist = Whitelist().apply { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
118 wlSelectorModel.toList().forEach { add(it) } |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
119 } |
5 | 120 _PROPS.run { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 setProperty("outputTo", outputTo) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 setProperty("outputToInputDir", outputToInputDir.toString()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 setProperty("whitelist", whitelist.toString()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
124 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 try { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 BufferedWriter(OutputStreamWriter(FileOutputStream(PROP_FILE), CHARSET)).use { |
5 | 127 _PROPS.store(it, null) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 } catch (e: IOException) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 LOGGER.log(Level.SEVERE, "unable to write settings", e) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
131 JOptionPane.showMessageDialog(Application.mainFrame, |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 "Unable to write settings.", |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 "Error", |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 JOptionPane.ERROR_MESSAGE) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
135 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 |
5 | 138 protected fun restore(outputToInput: Boolean, output: String, wl: Whitelist) { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
139 outputToButton.setSelected(!outputToInput) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
140 changeOutputTo.setEnabled(!outputToInput) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
141 outputToText.text = output |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
142 outputToInputButton.setSelected(outputToInput) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
143 wlSelectorModel.reset(wl.toList()) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
144 validate() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
145 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 /* so we can present a list of strings that is always sorted */ |
5 | 148 protected class WhiteListModel(basedOn: Collection<String>): ListModel<String> { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 private val storage = ArrayList<String>(basedOn).apply { sort() } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
150 private val listeners = mutableListOf<ListDataListener>() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
151 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
152 /* so we can mutate the list */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
153 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
154 fun add(newItem: String): Unit { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
155 var index = storage.binarySearch(newItem) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 if (index < 0) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 index = -(index + 1) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
158 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 storage.add(index, newItem) |
5 | 160 notifyAll(ListDataEvent.INTERVAL_ADDED, index, index) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
161 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
162 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
163 fun removeAt(index: Int): Unit { |
5 | 164 storage.removeAt(index) |
165 notifyAll(ListDataEvent.INTERVAL_REMOVED, index, index) | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
166 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
167 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
168 fun remove(oldItem: String): Unit { |
5 | 169 val index: Int = storage.binarySearch(oldItem) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
170 if (index < 0) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
171 return |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
172 } |
5 | 173 storage.removeAt(index) |
174 notifyAll(ListDataEvent.INTERVAL_REMOVED, index, index) | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
175 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
176 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
177 fun reset(basedOn: Collection<String>): Unit { |
5 | 178 val oldSize = storage.size |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
179 storage.clear() |
5 | 180 notifyAll(ListDataEvent.INTERVAL_REMOVED, 0, oldSize) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
181 storage.addAll(basedOn) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
182 storage.sort() |
5 | 183 notifyAll(ListDataEvent.INTERVAL_ADDED, 0, storage.size) |
184 } | |
185 | |
186 /* misc. */ | |
187 | |
188 fun toList(): List<String> = storage | |
189 | |
190 private fun notifyAll(eType: Int, index0: Int, index1: Int): Unit { | |
191 val event = ListDataEvent(this, eType, index0, index1) | |
192 when (eType) { | |
193 ListDataEvent.CONTENTS_CHANGED -> listeners.forEach { it.contentsChanged(event) } | |
194 ListDataEvent.INTERVAL_ADDED -> listeners.forEach { it.intervalAdded(event) } | |
195 ListDataEvent.INTERVAL_REMOVED -> listeners.forEach { it.intervalRemoved(event) } | |
196 else -> throw RuntimeException("unexpected event type!") | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
197 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
198 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
199 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
200 /* so we are a proper ListModel */ |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
201 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
202 override fun addListDataListener(l: ListDataListener): Unit { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
203 listeners.add(l) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
204 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
205 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
206 override fun removeListDataListener(l: ListDataListener): Unit { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
207 listeners.remove(l) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
208 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
209 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
210 override fun getElementAt(index: Int): String = storage[index] |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
211 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
212 override fun getSize(): Int = storage.size |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
213 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
214 |
5 | 215 protected class WLAddDialog(parent: SettingsDialog): JDialog(parent) { |
216 private val BW = parent.BW | |
217 private val BW2 = parent.BW2 | |
218 | |
219 private val toAdd = JTextField(40).apply { | |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
220 alignmentX = CENTER_ALIGNMENT |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
221 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
222 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
223 |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
224 private val cancelButton = JButton("Cancel").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
225 it.addActionListener(ActionListener { |
5 | 226 toAdd.text = "" |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
227 setVisible(false) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
228 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
229 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
230 |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
231 private val addButton = JButton("Add").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
232 it.addActionListener(ActionListener { |
5 | 233 val newItem = toAdd.text?.trim() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
234 if (newItem.isNullOrEmpty()) { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
235 Toolkit.getDefaultToolkit().beep() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
236 } else { |
5 | 237 parent.wlSelectorModel.add(newItem) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
238 } |
5 | 239 toAdd.text = "" |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
240 setVisible(false) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
241 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
242 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
243 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
244 init { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
245 title = "Add Item to Whitelist" |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
246 contentPane.apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
247 layout = BoxLayout(this, BoxLayout.Y_AXIS) |
5 | 248 add(toAdd) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
249 add(Box(BoxLayout.X_AXIS).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
250 alignmentX = CENTER_ALIGNMENT |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
251 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
252 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
253 add(cancelButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
254 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
255 add(addButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
256 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
257 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
258 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
259 pack() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
260 setResizable(false) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
261 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
262 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
263 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
264 /* the JList that holds our whitelist */ |
5 | 265 protected val wlSelectorModel = WhiteListModel(whitelist.toList()) |
266 protected val wlSelector: JList<String> = JList<String>().apply { | |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
267 visibleRowCount = 6 |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
268 model = wlSelectorModel |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
269 clearSelection() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
270 addListSelectionListener(ListSelectionListener { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
271 wlDeleteButton.setEnabled(!isSelectionEmpty()) |
5 | 272 }) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
273 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
274 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
275 /* buttons for managing the whitelist */ |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
276 protected val wlAddButton = JButton("Add").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
277 it.addActionListener(ActionListener { wlAddDialog.setVisible(true) }) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
278 } |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
279 protected val wlDeleteButton = JButton("Delete").also { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
280 it.addActionListener(ActionListener { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
281 wlSelector.selectedIndices.forEach { wlSelectorModel.removeAt(it) } |
5 | 282 setEnabled(false) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
283 }) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
284 it.setEnabled(false) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
285 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
286 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
287 /* the dialog that the Add button pops up */ |
5 | 288 protected val wlAddDialog = WLAddDialog(this) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
289 |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
290 init { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
291 title = "Settings" |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
292 contentPane.apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
293 layout = BoxLayout(this, BoxLayout.Y_AXIS) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
294 add(JTabbedPane().apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
295 addTab("Folders", JPanel().apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
296 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
297 layout = BoxLayout(this, BoxLayout.Y_AXIS) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
298 // yes, a one-item box. POS mis-aligns things if only |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
299 // some stuff is boxed, border widths be damned. sigh. |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
300 add(Box(BoxLayout.X_AXIS).apply { |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
301 alignmentX = LEFT_ALIGNMENT |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
302 border = BorderFactory.createEmptyBorder(BW, BW, 0, BW) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
303 add(outputToInputButton) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
304 add(Box.createHorizontalGlue()) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
305 pack() |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
306 noTaller() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
307 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
308 add(Box(BoxLayout.X_AXIS).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
309 alignmentX = LEFT_ALIGNMENT |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
310 border = BorderFactory.createEmptyBorder(BW, BW, 0, BW) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
311 add(outputToButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
312 add(Box.createHorizontalStrut(BW2)) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
313 add(outputToText) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
314 add(Box.createHorizontalGlue()) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
315 pack() |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
316 noTaller() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
317 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
318 add(Box(BoxLayout.X_AXIS).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
319 alignmentX = LEFT_ALIGNMENT |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
320 border = BorderFactory.createEmptyBorder(0, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
321 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
322 add(changeOutputTo) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
323 pack() |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
324 noTaller() |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
325 }) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
326 add(Box.createVerticalGlue()) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
327 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
328 addTab("Whitelist", JPanel().apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
329 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
330 layout = BoxLayout(this, BoxLayout.Y_AXIS) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
331 add(JScrollPane(wlSelector).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
332 alignmentX = CENTER_ALIGNMENT |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
333 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
334 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
335 horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
336 }) |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
337 add(Box.createVerticalGlue()) |
3
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
338 add(Box(BoxLayout.X_AXIS).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
339 alignmentX = CENTER_ALIGNMENT |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
340 border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
341 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
342 add(wlAddButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
343 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
344 add(wlDeleteButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
345 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
346 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
347 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
348 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
349 add(Box(BoxLayout.X_AXIS).apply { |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
350 border = BorderFactory.createEmptyBorder(BW, BW2, BW2, BW2) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
351 add(restoreButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
352 add(Box.createHorizontalGlue()) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
353 add(cancelButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
354 add(Box.createHorizontalStrut(BW2)) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
355 add(saveButton) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
356 }) |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
357 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
358 pack() |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
359 minimumSize = size |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
360 } |
19c381c536ec
Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
361 } |
6
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
362 |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
363 fun Properties.getNotEmpty(key: String, default: String): String { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
364 val ret = getProperty(key) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
365 return if (ret.isNullOrEmpty()) default else ret |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
366 } |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
367 |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
368 fun JComponent.noTaller() { |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
369 maximumSize = Dimension(maximumSize.width, preferredSize.height) |
aafc9c127c7b
Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents:
5
diff
changeset
|
370 } |