comparison 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
comparison
equal deleted inserted replaced
59:4997ae108653 60:d0b83fc1d62a
4 package name.blackcap.exifwasher 4 package name.blackcap.exifwasher
5 5
6 import java.awt.event.ActionEvent 6 import java.awt.event.ActionEvent
7 import java.awt.event.ActionListener 7 import java.awt.event.ActionListener
8 import java.awt.event.KeyEvent 8 import java.awt.event.KeyEvent
9 import java.io.File
9 import java.util.logging.Level 10 import java.util.logging.Level
10 import java.util.logging.Logger 11 import java.util.logging.Logger
11 import javax.swing.* 12 import javax.swing.*
13 import javax.swing.filechooser.FileNameExtensionFilter
12 14
13 /** 15 /**
14 * Our menu bar. What we display depends somewhat on the system type, as 16 * Our menu bar. What we display depends somewhat on the system type, as
15 * the Mac gives us a gratuitous menu bar entry for handling some stuff. 17 * the Mac gives us a gratuitous menu bar entry for handling some stuff.
16 */ 18 */
17 class MyMenuBar: JMenuBar() { 19 class MyMenuBar: JMenuBar() {
20 private var currentInputDirectory = File(System.getProperty("user.home"))
21
18 init { 22 init {
19 add(JMenu("File").apply { 23 add(JMenu("File").apply {
20 add(JMenuItem("Wash…").apply { 24 add(JMenuItem("Wash…").apply {
21 addActionListener(ActionListener { doWash() }) 25 addActionListener(ActionListener { doWash() })
22 makeShortcut(KeyEvent.VK_W) 26 makeShortcut(KeyEvent.VK_W)
59 return null 63 return null
60 } 64 }
61 65
62 fun doWash() { 66 fun doWash() {
63 val fc = JFileChooser().apply { 67 val fc = JFileChooser().apply {
68 currentDirectory = currentInputDirectory
69 fileFilter = FileNameExtensionFilter("JPEG Files", "jpg", "jpeg")
64 setMultiSelectionEnabled(true) 70 setMultiSelectionEnabled(true)
65 } 71 }
66 val status = fc.showOpenDialog(Application.mainFrame) 72 val status = fc.showOpenDialog(Application.mainFrame)
67 if (status == JFileChooser.APPROVE_OPTION) { 73 if (status == JFileChooser.APPROVE_OPTION) {
68 for (file in fc.getSelectedFiles()) { 74 val files = fc.getSelectedFiles()
75 if (files.size > 0)
76 currentInputDirectory = files[0].canonicalFile.parentFile
77 for (file in files) {
69 WashDialog().wash(file) 78 WashDialog().wash(file)
70 } 79 }
71 } 80 }
72 } 81 }
73 } 82 }