comparison 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
comparison
equal deleted inserted replaced
8:88d02fa97d78 9:0a106e9b91b4
1 /* 1 /*
2 * The dialog that controls washing a single file. 2 * The dialog that controls washing a single file.
3 */ 3 */
4 package name.blackcap.exifwasher 4 package name.blackcap.exifwasher
5 5
6 import java.awt.Color
6 import java.awt.Dimension 7 import java.awt.Dimension
7 import java.awt.event.ActionEvent 8 import java.awt.event.ActionEvent
8 import java.awt.event.ActionListener 9 import java.awt.event.ActionListener
9 import java.io.File 10 import java.io.File
10 import java.io.FileInputStream 11 import java.io.FileInputStream
26 private val HEIGHT = 480 27 private val HEIGHT = 480
27 28
28 private val COLUMN_NAMES = arrayOf<String>("Delete?", "Key", "Type", "Value") 29 private val COLUMN_NAMES = arrayOf<String>("Delete?", "Key", "Type", "Value")
29 private val myTable = JTable(arrayOf<Array<Any>>(), COLUMN_NAMES).apply { 30 private val myTable = JTable(arrayOf<Array<Any>>(), COLUMN_NAMES).apply {
30 autoCreateRowSorter = false 31 autoCreateRowSorter = false
32 border = BorderFactory.createLineBorder(Color.GRAY)
33 gridColor = Color.GRAY
31 rowSorter = null 34 rowSorter = null
32 } 35 setShowGrid(true)
33 36 }
34 private val selectAll = JCheckBox("Select all for deletion", false) 37
38 val impliedDeletions = mutableSetOf<String>()
39 private val selectAll = JCheckBox("Select all for deletion", false).also {
40 it.addActionListener(ActionListener { _ ->
41 val limit = myTable.rowCount - 1
42 if (it.isSelected()) {
43 impliedDeletions.clear()
44 for (i in 0 .. limit) {
45 if(!(myTable.getValueAt(i, 0) as Boolean)) {
46 impliedDeletions.add(myTable.getValueAt(i, 1) as String)
47 myTable.setValueAt(true, i, 0)
48 }
49 }
50 } else {
51 for (i in 0 .. limit) {
52 if (impliedDeletions.contains(myTable.getValueAt(i, 1) as String)) {
53 myTable.setValueAt(false, i, 0)
54 }
55 }
56 }
57 })
58 }
35 59
36 private val resetButton = JButton("Reset").also { 60 private val resetButton = JButton("Reset").also {
37 it.addActionListener(ActionListener { doReset() }) 61 it.addActionListener(ActionListener { doReset() })
38 } 62 }
39 63