# HG changeset patch # User David Barts # Date 1586646779 25200 # Node ID 39b977021ea17e0a714b7ce09a95e9bc90de5abc # Parent 841f711c40bd84dc8a564503fb1a12d99b9fd9fb Tool tips in case key and type cols truncate. diff -r 841f711c40bd -r 39b977021ea1 build.xml --- a/build.xml Sat Apr 11 15:01:23 2020 -0700 +++ b/build.xml Sat Apr 11 16:12:59 2020 -0700 @@ -113,7 +113,7 @@ + version="1.02"/> diff -r 841f711c40bd -r 39b977021ea1 src/name/blackcap/exifwasher/Misc.kt --- a/src/name/blackcap/exifwasher/Misc.kt Sat Apr 11 15:01:23 2020 -0700 +++ b/src/name/blackcap/exifwasher/Misc.kt Sat Apr 11 16:12:59 2020 -0700 @@ -9,7 +9,9 @@ import java.awt.Font import java.awt.FontMetrics import java.awt.Graphics +import java.awt.Point import java.awt.Toolkit +import java.awt.event.MouseEvent import javax.swing.* import javax.swing.table.TableColumnModel import kotlin.annotation.* @@ -193,3 +195,25 @@ } preferredSize = Dimension(total, preferredSize.height) } + +/** + * A JTable for displaying metadata. Columns that might get harmfully + * truncated have tooltips when truncation happens. + */ +class JExifTable(rowData: Array>, colNames: Array): JTable(rowData, colNames) { + override fun getToolTipText(e: MouseEvent): String? { + val pos = e.point + val col = columnAtPoint(pos) + if (!setOf("Key", "Type").contains(getColumnName(col))) { + return null + } + val contents = getValueAt(rowAtPoint(pos), col) as String? + if (contents == null) { + return null + } + val needed = graphics.fontMetrics.stringWidth(contents) + val actual = columnModel.getColumn(col).width + return if (needed > actual) contents else null + } +} + diff -r 841f711c40bd -r 39b977021ea1 src/name/blackcap/exifwasher/ShowDialog.kt --- a/src/name/blackcap/exifwasher/ShowDialog.kt Sat Apr 11 15:01:23 2020 -0700 +++ b/src/name/blackcap/exifwasher/ShowDialog.kt Sat Apr 11 16:12:59 2020 -0700 @@ -26,7 +26,7 @@ private val HEIGHT = 480 private val COLUMN_NAMES = arrayOf("Key", "Type", "Value") - private val myTable = JTable(arrayOf>(), COLUMN_NAMES).apply { + private val myTable = JExifTable(arrayOf>(), COLUMN_NAMES).apply { autoCreateRowSorter = false border = BorderFactory.createLineBorder(Color.GRAY) gridColor = Color.GRAY diff -r 841f711c40bd -r 39b977021ea1 src/name/blackcap/exifwasher/WashDialog.kt --- a/src/name/blackcap/exifwasher/WashDialog.kt Sat Apr 11 15:01:23 2020 -0700 +++ b/src/name/blackcap/exifwasher/WashDialog.kt Sat Apr 11 16:12:59 2020 -0700 @@ -28,7 +28,7 @@ private val HEIGHT = 480 private val COLUMN_NAMES = arrayOf("Delete?", "Key", "Type", "Value") - private val myTable = JTable(arrayOf>(), COLUMN_NAMES).apply { + private val myTable = JExifTable(arrayOf>(), COLUMN_NAMES).apply { autoCreateRowSorter = false border = BorderFactory.createLineBorder(Color.GRAY) gridColor = Color.GRAY