annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 /*
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 * A standard spinner for inputting the maximum dimension of an image.
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 package name.blackcap.imageprep
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
5
21
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
6 import java.awt.Dimension
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import java.awt.Toolkit
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import javax.swing.*
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import javax.swing.event.ChangeEvent
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import javax.swing.event.ChangeListener
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.util.logging.Level
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.util.logging.Logger
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
13
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 /* maximum allowable maximum dimension */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 private val MAXDIM = 16384
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
16
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 /* preferred standard dimensions */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 private val STDDIMS = listOf<Int>(1600, 1280, 1024, 800, 640, 512, 400, 320)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
19
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 class MaxDimSpinner(val default: Int): JSpinner(SpinnerListModel(STDDIMS))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 init {
21
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
23 editor = JSpinner.ListEditor(this).apply {
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
24 textField.columns = STDDIMS.map { it.toString().length }.max() ?: 1
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
25 }
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 value = default
21
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
27 maximumSize = preferredSize
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 addChangeListener( ChangeListener {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 val v = value as? Int ?: (value as? String)?.toIntOrNull()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 if ( v == null || v < 1 || v > MAXDIM ) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 LOGGER.log(Level.INFO, "bad max dimension: $value")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 value = default
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 Toolkit.getDefaultToolkit().beep()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 }