comparison src/name/blackcap/exifwasher/Misc.kt @ 19:39b977021ea1

Tool tips in case key and type cols truncate.
author David Barts <n5jrn@me.com>
date Sat, 11 Apr 2020 16:12:59 -0700
parents 0a106e9b91b4
children 965435b85a69
comparison
equal deleted inserted replaced
18:841f711c40bd 19:39b977021ea1
7 import java.awt.Cursor 7 import java.awt.Cursor
8 import java.awt.Dimension 8 import java.awt.Dimension
9 import java.awt.Font 9 import java.awt.Font
10 import java.awt.FontMetrics 10 import java.awt.FontMetrics
11 import java.awt.Graphics 11 import java.awt.Graphics
12 import java.awt.Point
12 import java.awt.Toolkit 13 import java.awt.Toolkit
14 import java.awt.event.MouseEvent
13 import javax.swing.* 15 import javax.swing.*
14 import javax.swing.table.TableColumnModel 16 import javax.swing.table.TableColumnModel
15 import kotlin.annotation.* 17 import kotlin.annotation.*
16 import kotlin.properties.ReadWriteProperty 18 import kotlin.properties.ReadWriteProperty
17 import kotlin.reflect.* 19 import kotlin.reflect.*
191 for (i in 0 .. limit) { 193 for (i in 0 .. limit) {
192 total += tcm.getColumn(i).preferredWidth 194 total += tcm.getColumn(i).preferredWidth
193 } 195 }
194 preferredSize = Dimension(total, preferredSize.height) 196 preferredSize = Dimension(total, preferredSize.height)
195 } 197 }
198
199 /**
200 * A JTable for displaying metadata. Columns that might get harmfully
201 * truncated have tooltips when truncation happens.
202 */
203 class JExifTable(rowData: Array<Array<out Any?>>, colNames: Array<out Any?>): JTable(rowData, colNames) {
204 override fun getToolTipText(e: MouseEvent): String? {
205 val pos = e.point
206 val col = columnAtPoint(pos)
207 if (!setOf("Key", "Type").contains(getColumnName(col))) {
208 return null
209 }
210 val contents = getValueAt(rowAtPoint(pos), col) as String?
211 if (contents == null) {
212 return null
213 }
214 val needed = graphics.fontMetrics.stringWidth(contents)
215 val actual = columnModel.getColumn(col).width
216 return if (needed > actual) contents else null
217 }
218 }
219