Mercurial > cgi-bin > hgweb.cgi > JpegWasher
comparison src/name/blackcap/exifwasher/Menus.kt @ 3:19c381c536ec
Code to make it a proper Mac GUI app. Untested!
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 08 Apr 2020 20:29:12 -0700 |
parents | |
children | dc1f4359659d |
comparison
equal
deleted
inserted
replaced
2:efd9fe2d70d7 | 3:19c381c536ec |
---|---|
1 /* | |
2 * Menus. | |
3 */ | |
4 package name.blackcap.exifwasher | |
5 | |
6 import java.awt.event.ActionEvent | |
7 import java.awt.event.ActionListener | |
8 import java.awt.event.KeyEvent | |
9 import javax.swing.* | |
10 | |
11 /** | |
12 * Our menu bar. What we display depends somewhat on the system type, as | |
13 * the Mac gives us a gratuitous menu bar entry for handling some stuff. | |
14 */ | |
15 class MyMenuBar: JMenuBar() { | |
16 init { | |
17 add(JMenu("File").apply { | |
18 add(JMenuItem("Wash…").apply { | |
19 addActionListener(ActionListener { doWash() }) | |
20 makeShortcut(KeyEvent.VK_W) | |
21 }) | |
22 if (OS.type != OS.MAC) { | |
23 add(JMenuItem("Preferences…").apply { | |
24 addActionListener(ActionListener { | |
25 Application.settingsDialog.setVisible(true) | |
26 }) | |
27 makeShortcut(KeyEvent.VK_COMMA) | |
28 }) | |
29 add(JMenuItem("Quit").apply { | |
30 addActionListener(ActionListener { System.exit(0) }) | |
31 makeShortcut(KeyEvent.VK_Q) | |
32 }) | |
33 } | |
34 }) | |
35 if (OS.type != OS.MAC) { | |
36 add(JMenu("Help").apply { | |
37 add(JMenuItem("About ClipMan…").apply { | |
38 addActionListener(ActionListener { showAboutDialog() }) | |
39 }) | |
40 }) | |
41 } | |
42 } | |
43 | |
44 fun getMenu(name: String): JMenu? { | |
45 subElements.forEach { | |
46 val jmenu = it.component as? JMenu | |
47 if (jmenu?.text == name) { | |
48 return jmenu | |
49 } | |
50 } | |
51 return null | |
52 } | |
53 | |
54 fun doWash() { | |
55 val fc = JFileChooser().apply { | |
56 setMultiSelectionEnabled(true) | |
57 } | |
58 val status = fc.showOpenDialog(Application.mainFrame) | |
59 if (status == JFileChooser.APPROVE_OPTION) { | |
60 for (file in fc.getSelectedFiles()) { | |
61 WashDialog().wash(file) | |
62 } | |
63 } | |
64 } | |
65 } | |
66 | |
67 /** | |
68 * Show an About dialog. | |
69 */ | |
70 fun showAboutDialog() { | |
71 JOptionPane.showMessageDialog(frame.v, | |
72 "ExifWasher—Privacy for your photos.\n" | |
73 + "© MMXX, David W. Barts", | |
74 "About ExifWasher", | |
75 JOptionPane.PLAIN_MESSAGE) | |
76 } |