changeset 9:0a106e9b91b4

Fix table layout; fix "select all for deletion" feature.
author David Barts <n5jrn@me.com>
date Fri, 10 Apr 2020 19:17:09 -0700
parents 88d02fa97d78
children 9bbe6d803eba
files src/name/blackcap/exifwasher/Menus.kt src/name/blackcap/exifwasher/Misc.kt src/name/blackcap/exifwasher/Osdep.kt.mac.osdep src/name/blackcap/exifwasher/ShowDialog.kt src/name/blackcap/exifwasher/WashDialog.kt
diffstat 5 files changed, 45 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/exifwasher/Menus.kt	Fri Apr 10 15:09:36 2020 -0700
+++ b/src/name/blackcap/exifwasher/Menus.kt	Fri Apr 10 19:17:09 2020 -0700
@@ -6,6 +6,8 @@
 import java.awt.event.ActionEvent
 import java.awt.event.ActionListener
 import java.awt.event.KeyEvent
+import java.util.logging.Level
+import java.util.logging.Logger
 import javax.swing.*
 
 /**
@@ -27,7 +29,10 @@
                     makeShortcut(KeyEvent.VK_COMMA)
                 })
                 add(JMenuItem("Quit").apply {
-                    addActionListener(ActionListener { System.exit(0) })
+                    addActionListener(ActionListener {
+                        LOGGER.log(Level.INFO, "execution complete")
+                        System.exit(0)
+                    })
                     makeShortcut(KeyEvent.VK_Q)
                 })
             }
--- a/src/name/blackcap/exifwasher/Misc.kt	Fri Apr 10 15:09:36 2020 -0700
+++ b/src/name/blackcap/exifwasher/Misc.kt	Fri Apr 10 19:17:09 2020 -0700
@@ -175,9 +175,9 @@
 fun JTable.setColWidth(col: Int, width: Int, string: String?) {
     val FUZZ = 4
     columnModel.getColumn(col).preferredWidth = if (string.isNullOrEmpty()) {
-        width + FUZZ
+        width
     } else {
-        maxOf(width, graphics.fontMetrics.stringWidth(string)) + FUZZ
+        maxOf(width, graphics.fontMetrics.stringWidth(string) + FUZZ)
     }
 }
 
@@ -186,8 +186,9 @@
  */
 fun JTable.setOverallWidth() {
     val tcm = columnModel
+    val limit = tcm.columnCount - 1
     var total = 0
-    for (i in 0 .. tcm.columnCount - 1) {
+    for (i in 0 .. limit) {
         total += tcm.getColumn(i).preferredWidth
     }
     preferredSize = Dimension(total, preferredSize.height)
--- a/src/name/blackcap/exifwasher/Osdep.kt.mac.osdep	Fri Apr 10 15:09:36 2020 -0700
+++ b/src/name/blackcap/exifwasher/Osdep.kt.mac.osdep	Fri Apr 10 19:17:09 2020 -0700
@@ -5,11 +5,13 @@
 
 import com.apple.eawt.AboutHandler
 import com.apple.eawt.PreferencesHandler
+import com.apple.eawt.QuitStrategy
 
 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/exifwasher/ShowDialog.kt	Fri Apr 10 15:09:36 2020 -0700
+++ b/src/name/blackcap/exifwasher/ShowDialog.kt	Fri Apr 10 19:17:09 2020 -0700
@@ -28,11 +28,6 @@
     private val myTable = JTable(arrayOf<Array<Any>>(), COLUMN_NAMES).apply {
         autoCreateRowSorter = false
         rowSorter = null
-        columnModel.run {
-            getColumn(0).preferredWidth = 25  /* key name */
-            getColumn(1).preferredWidth = 15  /* type */
-            getColumn(2).preferredWidth = 100  /* value */
-        }
     }
 
     /* deliberately not the default, because this changes a file */
@@ -70,7 +65,14 @@
                         "Unable to read metadata.",
                         "Error", JOptionPane.ERROR_MESSAGE)
                 } else {
-                    myTable.model = MyTableModel(tableData, COLUMN_NAMES)
+                    myTable.run {
+                        model = MyTableModel(tableData, COLUMN_NAMES)
+                        autoResizeMode = JTable.AUTO_RESIZE_OFF
+                        setColWidth(0, 180, null)
+                        setColWidth(1, 72, "Undefined")
+                        setColWidth(2, 720, null)
+                        setOverallWidth()
+                    }
                     setVisible(true)
                 }
             }
--- a/src/name/blackcap/exifwasher/WashDialog.kt	Fri Apr 10 15:09:36 2020 -0700
+++ b/src/name/blackcap/exifwasher/WashDialog.kt	Fri Apr 10 19:17:09 2020 -0700
@@ -3,6 +3,7 @@
  */
 package name.blackcap.exifwasher
 
+import java.awt.Color
 import java.awt.Dimension
 import java.awt.event.ActionEvent
 import java.awt.event.ActionListener
@@ -28,10 +29,33 @@
     private val COLUMN_NAMES = arrayOf<String>("Delete?", "Key", "Type", "Value")
     private val myTable = JTable(arrayOf<Array<Any>>(), COLUMN_NAMES).apply {
         autoCreateRowSorter = false
+        border = BorderFactory.createLineBorder(Color.GRAY)
+        gridColor = Color.GRAY
         rowSorter = null
+        setShowGrid(true)
     }
 
-    private val selectAll = JCheckBox("Select all for deletion", false)
+    val impliedDeletions = mutableSetOf<String>()
+    private val selectAll = JCheckBox("Select all for deletion", false).also {
+        it.addActionListener(ActionListener { _ ->
+            val limit = myTable.rowCount - 1
+            if (it.isSelected()) {
+                impliedDeletions.clear()
+                for (i in 0 .. limit) {
+                    if(!(myTable.getValueAt(i, 0) as Boolean)) {
+                        impliedDeletions.add(myTable.getValueAt(i, 1) as String)
+                        myTable.setValueAt(true, i, 0)
+                    }
+                }
+            } else {
+                for (i in 0 .. limit) {
+                    if (impliedDeletions.contains(myTable.getValueAt(i, 1) as String)) {
+                        myTable.setValueAt(false, i, 0)
+                    }
+                }
+            }
+        })
+    }
 
     private val resetButton = JButton("Reset").also {
         it.addActionListener(ActionListener { doReset() })