# HG changeset patch # User David Barts # Date 1586571429 25200 # Node ID 0a106e9b91b421de7584ce752b30ba0d7e98513b # Parent 88d02fa97d782147e4951d8df4d93a78c3e6d449 Fix table layout; fix "select all for deletion" feature. diff -r 88d02fa97d78 -r 0a106e9b91b4 src/name/blackcap/exifwasher/Menus.kt --- 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) }) } diff -r 88d02fa97d78 -r 0a106e9b91b4 src/name/blackcap/exifwasher/Misc.kt --- 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) diff -r 88d02fa97d78 -r 0a106e9b91b4 src/name/blackcap/exifwasher/Osdep.kt.mac.osdep --- 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) } } diff -r 88d02fa97d78 -r 0a106e9b91b4 src/name/blackcap/exifwasher/ShowDialog.kt --- 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>(), 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) } } diff -r 88d02fa97d78 -r 0a106e9b91b4 src/name/blackcap/exifwasher/WashDialog.kt --- 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("Delete?", "Key", "Type", "Value") private val myTable = JTable(arrayOf>(), 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() + 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() })