comparison src/name/blackcap/imageprep/MaxDimSpinner.kt @ 21:0f3634a0816d

De-uglify SettingsDialog.
author David Barts <n5jrn@me.com>
date Sat, 21 Nov 2020 21:25:05 -0800
parents 71029c9bf7cd
children d3979a2155a8
comparison
equal deleted inserted replaced
20:71029c9bf7cd 21:0f3634a0816d
1 /* 1 /*
2 * A standard spinner for inputting the maximum dimension of an image. 2 * A standard spinner for inputting the maximum dimension of an image.
3 */ 3 */
4 package name.blackcap.imageprep 4 package name.blackcap.imageprep
5 5
6 import java.awt.Dimension
6 import java.awt.Toolkit 7 import java.awt.Toolkit
7 import javax.swing.* 8 import javax.swing.*
8 import javax.swing.event.ChangeEvent 9 import javax.swing.event.ChangeEvent
9 import javax.swing.event.ChangeListener 10 import javax.swing.event.ChangeListener
10 import java.util.logging.Level 11 import java.util.logging.Level
17 private val STDDIMS = listOf<Int>(1600, 1280, 1024, 800, 640, 512, 400, 320) 18 private val STDDIMS = listOf<Int>(1600, 1280, 1024, 800, 640, 512, 400, 320)
18 19
19 class MaxDimSpinner(val default: Int): JSpinner(SpinnerListModel(STDDIMS)) 20 class MaxDimSpinner(val default: Int): JSpinner(SpinnerListModel(STDDIMS))
20 { 21 {
21 init { 22 init {
22 editor = JSpinner.ListEditor(this) 23 editor = JSpinner.ListEditor(this).apply {
24 textField.columns = STDDIMS.map { it.toString().length }.max() ?: 1
25 }
23 value = default 26 value = default
24 noTaller() 27 maximumSize = preferredSize
25 addChangeListener( ChangeListener { 28 addChangeListener( ChangeListener {
26 val v = value as? Int ?: (value as? String)?.toIntOrNull() 29 val v = value as? Int ?: (value as? String)?.toIntOrNull()
27 if ( v == null || v < 1 || v > MAXDIM ) { 30 if ( v == null || v < 1 || v > MAXDIM ) {
28 LOGGER.log(Level.INFO, "bad max dimension: $value") 31 LOGGER.log(Level.INFO, "bad max dimension: $value")
29 value = default 32 value = default