changeset 1:0bded24f746e

Compiles, still untested.
author David Barts <n5jrn@me.com>
date Thu, 16 Jul 2020 21:51:08 -0700
parents e0efe7848130
children a6f9b51d5e8d
files setup.sh src/name/blackcap/imageprep/Files.kt src/name/blackcap/imageprep/HelpDialog.kt src/name/blackcap/imageprep/Menus.kt src/name/blackcap/imageprep/Misc.kt src/name/blackcap/imageprep/Osdep.kt.default.osdep src/name/blackcap/imageprep/Osdep.kt.mac.osdep src/name/blackcap/imageprep/RotateDialog.kt src/name/blackcap/imageprep/Settings.kt
diffstat 9 files changed, 40 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/setup.sh	Thu Jul 16 19:57:23 2020 -0700
+++ b/setup.sh	Thu Jul 16 21:51:08 2020 -0700
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 export JRE_HOME="$(/usr/libexec/java_home)"
-export KOTLIN_HOME="/usr/local/Cellar/kotlin/1.3.71/libexec"
+export KOTLIN_HOME="$HOME/kotlin/1.3.72"
 export EXIV2_HOME="$HOME/temp/exiv2/exiv2-0.27.2-Source"
 export OSDEP_HOME="../Osdep"
 
--- a/src/name/blackcap/imageprep/Files.kt	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Files.kt	Thu Jul 16 21:51:08 2020 -0700
@@ -6,6 +6,7 @@
 import java.io.BufferedReader
 import java.io.File
 import java.io.FileInputStream
+import java.io.FileOutputStream
 import java.io.InputStreamReader
 import java.util.Properties
 import java.util.logging.FileHandler
--- a/src/name/blackcap/imageprep/HelpDialog.kt	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/HelpDialog.kt	Thu Jul 16 21:51:08 2020 -0700
@@ -63,9 +63,9 @@
         it.text = rawText.replace("%CONFIG_FILE_NAME%", buildString {
             for (ch in PROP_FILE.canonicalPath) {
                 append(when(ch) {
-                    "<" -> "&lt;"
-                    ">" -> "&gt;"
-                    "&" -> "&amp;"
+                    '<' -> "&lt;"
+                    '>' -> "&gt;"
+                    '&' -> "&amp;"
                     else -> ch
                 })
             }
--- a/src/name/blackcap/imageprep/Menus.kt	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Menus.kt	Thu Jul 16 21:51:08 2020 -0700
@@ -5,12 +5,14 @@
 
 import java.awt.Graphics2D
 import java.awt.RenderingHints
+import java.awt.Toolkit
 import java.awt.Window
 import java.awt.event.ActionEvent
 import java.awt.event.ActionListener
 import java.awt.event.KeyEvent
 import java.awt.image.BufferedImage
 import java.io.File
+import java.io.IOException
 import java.util.logging.Level
 import java.util.logging.Logger
 import javax.imageio.IIOImage
@@ -19,6 +21,7 @@
 import javax.imageio.ImageWriter
 import javax.imageio.stream.ImageOutputStream
 import javax.swing.*
+import javax.swing.filechooser.FileNameExtensionFilter
 
 /**
  * Our menu bar. What we display depends somewhat on the system type, as
@@ -39,12 +42,6 @@
                 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")
@@ -78,7 +75,7 @@
 
     private fun doOpen() {
         val chooser = JFileChooser().apply {
-            fileFilter = FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes())
+            fileFilter = FileNameExtensionFilter("Image files", *ImageIO.getReaderFileSuffixes())
         }
         if (chooser.showOpenDialog(Application.mainFrame) == JFileChooser.APPROVE_OPTION) {
             RotateDialog.makeDialog(chooser.selectedFile)
@@ -86,9 +83,9 @@
     }
 
     private fun doDiscard() {
-        val w = FocusManager.currentManager.activeWindow as? RotateDialog
+        val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog
         if (w == null) {
-            Toolkit.defaultToolkit.beep()
+            Toolkit.getDefaultToolkit().beep()
             return
         }
         w.setVisible(false)
@@ -96,13 +93,13 @@
     }
 
     private fun doClose() {
-        val w = FocusManager.currentManager.activeWindow as? RotateDialog
+        val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog
         if (w == null) {
-            Toolkit.defaultToolkit.beep()
+            Toolkit.getDefaultToolkit().beep()
             return
         }
         val outName = splitext(w.file.name).first + Settings.outputSuffix + ".jpg"
-        val chooser = JFileChooser(w).apply {
+        val chooser = JFileChooser().apply {
             selectedFile = File(
                 if (Settings.outputToInputDir) w.file.parent else Settings.outputTo,
                 outName)
@@ -143,7 +140,7 @@
                     w.setVisible(false)
                     w.dispose()
                 } else {
-                    ioExceptionDialog(w, file, "write", e)
+                    ioExceptionDialog(w, file, "write", error)
                 }
             }
         }
--- a/src/name/blackcap/imageprep/Misc.kt	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Misc.kt	Thu Jul 16 21:51:08 2020 -0700
@@ -234,7 +234,7 @@
 }
 
 fun ioExceptionDialog(parent: Component, file: File, op: String, e: IOException) {
-    val msg = e.getMessage()
+    val msg = e.message
     val fileName = file.getName()
     val dmsg = if (msg.isNullOrEmpty()) {
         "Unable to ${op} ${fileName}."
--- a/src/name/blackcap/imageprep/Osdep.kt.default.osdep	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Osdep.kt.default.osdep	Thu Jul 16 21:51:08 2020 -0700
@@ -1,7 +1,7 @@
 /*
  * OS-dependent code, version for all non-Mac systems.
  */
-package name.blackcap.exifwasher
+package name.blackcap.imageprep
 
 fun setMacMenus() {
     /* no-op */
--- a/src/name/blackcap/imageprep/Osdep.kt.mac.osdep	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Osdep.kt.mac.osdep	Thu Jul 16 21:51:08 2020 -0700
@@ -1,7 +1,7 @@
 /*
  * OS-dependent code, Mac version.
  */
-package name.blackcap.exifwasher
+package name.blackcap.imageprep
 
 import com.apple.eawt.AboutHandler
 import com.apple.eawt.PreferencesHandler
@@ -10,8 +10,6 @@
 fun setMacMenus() {
     com.apple.eawt.Application.getApplication().run {
         setAboutHandler(AboutHandler { showAboutDialog() })
-        setPreferencesHandler(
-            PreferencesHandler { Application.settingsDialog.setVisible(true) })
         setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS)
     }
 }
--- a/src/name/blackcap/imageprep/RotateDialog.kt	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/RotateDialog.kt	Thu Jul 16 21:51:08 2020 -0700
@@ -3,8 +3,11 @@
  */
 package name.blackcap.imageprep
 
+import java.awt.Dimension
+import java.awt.Graphics
 import java.awt.Graphics2D
 import java.awt.RenderingHints
+import java.awt.event.ActionListener
 import java.awt.image.BufferedImage
 import java.io.File
 import java.io.IOException
@@ -18,7 +21,7 @@
     private val MINWIDTH = 512
     private val MINHEIGHT = 384
 
-    private class DrawingPane() : JPanel() {
+    private class DrawingPane(initialImage: BufferedImage) : JPanel() {
         var image: BufferedImage = initialImage
         set(value) {
             field = value
@@ -26,27 +29,26 @@
             repaint()
         }
 
-        override val preferredSize
-        get { return image.preferredSize }
+        override fun getPreferredSize() = Dimension(image.width, image.height)
 
-        protected paintComponent(g: Graphics): Unit {
+        override protected fun paintComponent(g: Graphics): Unit {
             g.drawImage(image, 0, 0, null)
         }
     }
-    private val drawingPane = DrawingPane()
+    private val drawingPane = DrawingPane(initialImage)
 
     val image: BufferedImage
     get() { return drawingPane.image }
 
-    private val r90cw = JButton("90° CW").apply {
+    private val r90cw = JButton("90° CW").also {
         it.addActionListener(ActionListener { doRotate(90) })
     }
 
-    private val r180 = JButton("180°").apply {
+    private val r180 = JButton("180°").also {
         it.addActionListener(ActionListener { doRotate(180) })
     }
 
-    private val r90ccw = JButton("90° CCW").apply {
+    private val r90ccw = JButton("90° CCW").also {
         it.addActionListener(ActionListener { doRotate(270) })
     }
 
@@ -64,7 +66,7 @@
         val rotatedImage = BufferedImage(w, h, image.type)
         rotatedImage.createGraphics().run {
             translate((w - image.width) / 2, (h - image.height) / 2)
-            rotate(rad, image.width / 2, image.height / 2)
+            rotate(rad, image.width.toDouble()/2.0, image.height.toDouble()/2.0)
             drawRenderedImage(image, null)
             dispose()
         }
@@ -76,7 +78,7 @@
         title = "Untitled"
         contentPane.apply {
             layout = BoxLayout(this, BoxLayout.Y_AXIS)
-            add(JScrollpane(drawingPane).apply {
+            add(JScrollPane(drawingPane).apply {
                 alignmentX = JScrollPane.CENTER_ALIGNMENT
                 addBorder(BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2))
                 verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
@@ -106,13 +108,13 @@
          */
         fun makeDialog(input: File): Unit {
             Application.mainFrame.useWaitCursor()
-            swingWorker<Pair<BufferedImage?, IOException?> {
+            swingWorker<Pair<BufferedImage?, IOException?>> {
                 inBackground {
                     try {
                         val imageIn = ImageIO.read(input) /* IOException */
                         val ratio = Settings.maxDimension.toDouble() / max(imageIn.width, imageIn.height).toDouble()
                         if (ratio >= 1.0) {
-                            null
+                            Pair(null, null)
                         } else {
                             val nWidth = (imageIn.width * ratio).toInt()
                             val nHeight = (imageIn.height * ratio).toInt()
@@ -134,8 +136,12 @@
                     val (image, error) = get()
                     if (error != null)
                         ioExceptionDialog(Application.mainFrame, input, "read", error)
-                    if (image != null)
+                    else if (image != null)
                         RotateDialog(input, image).title = input.getName()
+                    else
+                        JOptionPane.showMessageDialog(Application.mainFrame,
+                            "Image is too small to be scaled.",
+                            "Warning", JOptionPane.WARNING_MESSAGE)
                 }
             }
         }
--- a/src/name/blackcap/imageprep/Settings.kt	Thu Jul 16 19:57:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Settings.kt	Thu Jul 16 21:51:08 2020 -0700
@@ -3,6 +3,8 @@
  */
 package name.blackcap.imageprep
 
+import java.io.File
+
 /* work around name shadowing */
 private val _PROPS = PROPERTIES
 
@@ -18,7 +20,7 @@
         if (s.isNullOrEmpty())
             return homeDir
         if (s.startsWith("~/") || s.startsWith("~\\"))
-            return File(homeDir, s.substring(1).trimStart('/', '\\')).toString()
+            return File(homeDir, s.substring(2).trimStart(s[1])).toString()
         else
             return s
     }