diff src/name/blackcap/exifwasher/WashDialog.kt @ 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 e52fd1a575de
line wrap: on
line diff
--- 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() })