diff src/name/blackcap/imageprep/Menus.kt @ 19:5fa5d15b4a7b

Attempt to make it a std. app. Builds, sorta runs, needs more work.
author David Barts <n5jrn@me.com>
date Fri, 20 Nov 2020 21:38:06 -0800
parents d71523cde521
children 71029c9bf7cd
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/Menus.kt	Fri Nov 20 21:37:37 2020 -0800
+++ b/src/name/blackcap/imageprep/Menus.kt	Fri Nov 20 21:38:06 2020 -0800
@@ -29,7 +29,7 @@
  */
 class MyMenuBar: JMenuBar() {
     private var currentInputDirectory = File(System.getProperty("user.dir"))
-    private var currentOutputDirectory = File(Settings.outputTo)
+    private var currentOutputDirectory = File(Application.settingsDialog.outputTo)
 
     init {
         add(JMenu("File").apply {
@@ -45,6 +45,12 @@
                 makeShortcut(KeyEvent.VK_S)
             })
             if (OS.type != OS.MAC) {
+                add(JMenuItem("Preferences…").apply {
+                    addActionListener(ActionListener {
+                        Application.settingsDialog.setVisible(true)
+                    })
+                    makeShortcut(KeyEvent.VK_COMMA)
+                })
                 add(JMenuItem("Quit").apply {
                     addActionListener(ActionListener {
                         LOGGER.log(Level.INFO, "execution complete")
@@ -77,13 +83,20 @@
     }
 
     private fun doOpen() {
+        val maxDim = MaxDimSpinner(Application.settingsDialog.maxDimension)
+        val acc = JPanel().apply {
+            layout = BoxLayout(this, BoxLayout.X_AXIS)
+            add(JLabel("Max. dimension:"))
+            add(maxDim)
+        }
         val chooser = JFileChooser().apply {
+            accessory = acc
             currentDirectory = currentInputDirectory
             fileFilter = FileNameExtensionFilter("Image Files", *ImageIO.getReaderFileSuffixes())
         }
         if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) {
             currentInputDirectory = chooser.selectedFile.canonicalFile.parentFile
-            RotateDialog.makeDialog(chooser.selectedFile)
+            RotateDialog.makeDialog(chooser.selectedFile, maxDim.value as Int)
         }
     }
 
@@ -108,8 +121,15 @@
             Toolkit.getDefaultToolkit().beep()
             return
         }
-        val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg"
+        val outQual = OutQualSpinner(Application.settingsDialog.outputQuality)
+        val acc = JPanel().apply {
+            layout = BoxLayout(this, BoxLayout.X_AXIS)
+            add(JLabel("Quality:"))
+            add(outQual)
+        }
+        val outName = splitext(w.file.name).first + Application.settingsDialog.outputSuffix + ".jpg"
         val chooser = JFileChooser().apply {
+            accessory = acc
             currentDirectory = currentOutputDirectory
             selectedFile = File(currentOutputDirectory, outName)
         }
@@ -150,7 +170,7 @@
                         try {
                             val iwp = writer.getDefaultWriteParam().apply {
                                 setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
-                                setCompressionQuality(Settings.outputQuality.toFloat() / 100.0f)
+                                setCompressionQuality((outQual.value as Int).toFloat() / 100.0f)
                             }
                             writer.setOutput(it)
                             writer.write(null, IIOImage(w.image, null, null), iwp)