comparison src/name/blackcap/exifwasher/Misc.kt @ 8:88d02fa97d78

Got WasherDialog table laying out somewhat sanely.
author David Barts <n5jrn@me.com>
date Fri, 10 Apr 2020 15:09:36 -0700
parents dc1f4359659d
children 0a106e9b91b4
comparison
equal deleted inserted replaced
7:65d14d44bc3f 8:88d02fa97d78
3 */ 3 */
4 package name.blackcap.exifwasher 4 package name.blackcap.exifwasher
5 5
6 import java.awt.Component 6 import java.awt.Component
7 import java.awt.Cursor 7 import java.awt.Cursor
8 import java.awt.Dimension
9 import java.awt.Font
10 import java.awt.FontMetrics
11 import java.awt.Graphics
8 import java.awt.Toolkit 12 import java.awt.Toolkit
9 import javax.swing.* 13 import javax.swing.*
14 import javax.swing.table.TableColumnModel
10 import kotlin.annotation.* 15 import kotlin.annotation.*
11 import kotlin.properties.ReadWriteProperty 16 import kotlin.properties.ReadWriteProperty
12 import kotlin.reflect.* 17 import kotlin.reflect.*
13 18
14 /** 19 /**
161 */ 166 */
162 fun JDialog.close() { 167 fun JDialog.close() {
163 setVisible(false) 168 setVisible(false)
164 dispose() 169 dispose()
165 } 170 }
171
172 /**
173 * Set column width of a table.
174 */
175 fun JTable.setColWidth(col: Int, width: Int, string: String?) {
176 val FUZZ = 4
177 columnModel.getColumn(col).preferredWidth = if (string.isNullOrEmpty()) {
178 width + FUZZ
179 } else {
180 maxOf(width, graphics.fontMetrics.stringWidth(string)) + FUZZ
181 }
182 }
183
184 /**
185 * Set overall width of a table.
186 */
187 fun JTable.setOverallWidth() {
188 val tcm = columnModel
189 var total = 0
190 for (i in 0 .. tcm.columnCount - 1) {
191 total += tcm.getColumn(i).preferredWidth
192 }
193 preferredSize = Dimension(total, preferredSize.height)
194 }