annotate src/name/blackcap/exifwasher/Menus.kt @ 60:d0b83fc1d62a default tip

Remember our input directory on a per-invocation basis.
author David Barts <n5jrn@me.com>
date Sun, 26 Jul 2020 15:14:03 -0700
parents 39895d44a287
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 * Menus.
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
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import java.awt.event.ActionEvent
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import java.awt.event.ActionListener
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.event.KeyEvent
60
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
9 import java.io.File
9
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
10 import java.util.logging.Level
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
11 import java.util.logging.Logger
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import javax.swing.*
60
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
13 import javax.swing.filechooser.FileNameExtensionFilter
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
14
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
15 /**
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
16 * Our menu bar. What we display depends somewhat on the system type, as
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
17 * the Mac gives us a gratuitous menu bar entry for handling some stuff.
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
18 */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
19 class MyMenuBar: JMenuBar() {
60
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
20 private var currentInputDirectory = File(System.getProperty("user.home"))
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
21
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
22 init {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
23 add(JMenu("File").apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
24 add(JMenuItem("Wash…").apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
25 addActionListener(ActionListener { doWash() })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
26 makeShortcut(KeyEvent.VK_W)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
27 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
28 if (OS.type != OS.MAC) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
29 add(JMenuItem("Preferences…").apply {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
30 addActionListener(ActionListener {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
31 Application.settingsDialog.setVisible(true)
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 makeShortcut(KeyEvent.VK_COMMA)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
34 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
35 add(JMenuItem("Quit").apply {
9
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
36 addActionListener(ActionListener {
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
37 LOGGER.log(Level.INFO, "execution complete")
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
38 System.exit(0)
0a106e9b91b4 Fix table layout; fix "select all for deletion" feature.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
39 })
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
40 makeShortcut(KeyEvent.VK_Q)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
41 })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
42 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
43 })
50
fb407182ba76 Add help menu item, UNTESTED.
David Barts <davidb@stashtea.com>
parents: 27
diff changeset
44 add(JMenu("Help").apply {
fb407182ba76 Add help menu item, UNTESTED.
David Barts <davidb@stashtea.com>
parents: 27
diff changeset
45 if (OS.type != OS.MAC) {
23
5cac95c17fef More Windows stuff. Attempts to get Windows packages working.
davidb
parents: 9
diff changeset
46 add(JMenuItem("About ${Application.MYNAME}…").apply {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
47 addActionListener(ActionListener { showAboutDialog() })
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
48 })
50
fb407182ba76 Add help menu item, UNTESTED.
David Barts <davidb@stashtea.com>
parents: 27
diff changeset
49 }
fb407182ba76 Add help menu item, UNTESTED.
David Barts <davidb@stashtea.com>
parents: 27
diff changeset
50 add(JMenuItem("${Application.MYNAME} Help…").apply {
fb407182ba76 Add help menu item, UNTESTED.
David Barts <davidb@stashtea.com>
parents: 27
diff changeset
51 addActionListener(ActionListener { Application.helpDialog.setVisible(true) })
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
52 })
52
39895d44a287 Get help working on Linux.
David Barts <n5jrn@me.com>
parents: 50
diff changeset
53 })
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
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
56 fun getMenu(name: String): JMenu? {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
57 subElements.forEach {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
58 val jmenu = it.component as? JMenu
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
59 if (jmenu?.text == name) {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
60 return jmenu
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
61 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
62 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
63 return null
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
64 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
65
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
66 fun doWash() {
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
67 val fc = JFileChooser().apply {
60
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
68 currentDirectory = currentInputDirectory
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
69 fileFilter = FileNameExtensionFilter("JPEG Files", "jpg", "jpeg")
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
70 setMultiSelectionEnabled(true)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
71 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
72 val status = fc.showOpenDialog(Application.mainFrame)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
73 if (status == JFileChooser.APPROVE_OPTION) {
60
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
74 val files = fc.getSelectedFiles()
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
75 if (files.size > 0)
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
76 currentInputDirectory = files[0].canonicalFile.parentFile
d0b83fc1d62a Remember our input directory on a per-invocation basis.
David Barts <n5jrn@me.com>
parents: 52
diff changeset
77 for (file in files) {
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
78 WashDialog().wash(file)
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 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
81 }
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
82 }
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 * Show an About dialog.
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
86 */
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
87 fun showAboutDialog() {
5
dc1f4359659d Got it compiling.
David Barts <n5jrn@me.com>
parents: 3
diff changeset
88 JOptionPane.showMessageDialog(Application.mainFrame,
27
ee580450d45a More of the Great Renaming.
davidb
parents: 23
diff changeset
89 "\nJpegWasher—Privacy for your photos.\n"
6
aafc9c127c7b Fix many bugs; get settings (apparently) working.
David Barts <n5jrn@me.com>
parents: 5
diff changeset
90 + "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0© MMXX, David W. Barts\n",
27
ee580450d45a More of the Great Renaming.
davidb
parents: 23
diff changeset
91 "About JpegWasher",
3
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
92 JOptionPane.PLAIN_MESSAGE)
19c381c536ec Code to make it a proper Mac GUI app. Untested!
David Barts <n5jrn@me.com>
parents:
diff changeset
93 }