changeset 18:841f711c40bd

Add new dialogs, and make NO the default for dangerous YES answers.
author David Barts <n5jrn@me.com>
date Sat, 11 Apr 2020 15:01:23 -0700
parents 0528030187e9
children 39b977021ea1
files src/name/blackcap/exifwasher/WashDialog.kt
diffstat 1 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/exifwasher/WashDialog.kt	Sat Apr 11 13:38:26 2020 -0700
+++ b/src/name/blackcap/exifwasher/WashDialog.kt	Sat Apr 11 15:01:23 2020 -0700
@@ -4,6 +4,7 @@
 package name.blackcap.exifwasher
 
 import java.awt.Color
+import java.awt.Component
 import java.awt.Dimension
 import java.awt.event.ActionEvent
 import java.awt.event.ActionListener
@@ -72,9 +73,32 @@
 
     private lateinit var washing: File
 
+    /* a yes/no dialog in which NO is the default */
+    private fun noYesDialog(parent: Component, message: String, title: String): Int {
+        val options = arrayOf<String>("No", "Yes")
+        val status = JOptionPane.showOptionDialog(parent, message, title,
+            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
+            null, options, options[0])
+        return if (status == 1) JOptionPane.YES_OPTION else JOptionPane.NO_OPTION
+    }
+
     /* initiates the washing of the Exif data */
     fun wash(dirty: File) {
         title = "Washing: ${dirty.name}"
+
+        /* warn (and allow user to back out) if not a JPEG */
+        val lcext = splitext(dirty.name).second.toLowerCase()
+        if (lcext != ".jpg" && lcext != ".jpeg") {
+            val answer = noYesDialog(Application.mainFrame,
+                "File ${dirty.name} does not appear to be a JPEG image.\n"+
+                "Washing non-JPEG images may damage them. Proceed anyway?",
+                "Non-JPEG file detected")
+            if (answer != JOptionPane.YES_OPTION) {
+                close()
+                return
+            }
+        }
+
         selectAll.setSelected(false)
         washing = dirty
         useWaitCursor()
@@ -155,11 +179,9 @@
 
         /* warn (and allow user to back out) if overwriting */
         if (newFile.exists()) {
-            val answer = JOptionPane.showConfirmDialog(Application.mainFrame,
+            val answer = noYesDialog(Application.mainFrame,
                 "File ${newFile.name} already exists. Overwrite?",
-                "Confirm overwriting file",
-                JOptionPane.YES_NO_OPTION,
-                JOptionPane.WARNING_MESSAGE)
+                "Confirm overwriting file")
             if (answer != JOptionPane.YES_OPTION) {
                 close()
                 return