annotate src/name/blackcap/imageprep/MaxDimSpinner.kt @ 20:71029c9bf7cd

Commit overlooked files.
author David Barts <n5jrn@me.com>
date Sat, 21 Nov 2020 10:15:35 -0800
parents
children 0f3634a0816d
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
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import java.awt.Toolkit
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import javax.swing.*
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import javax.swing.event.ChangeEvent
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import javax.swing.event.ChangeListener
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.util.logging.Level
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.util.logging.Logger
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
12
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 /* maximum allowable maximum dimension */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 private val MAXDIM = 16384
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
15
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 /* preferred standard dimensions */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 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
18
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 class MaxDimSpinner(val default: Int): JSpinner(SpinnerListModel(STDDIMS))
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 init {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 editor = JSpinner.ListEditor(this)
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 value = default
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 noTaller()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 addChangeListener( ChangeListener {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 val v = value as? Int ?: (value as? String)?.toIntOrNull()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 if ( v == null || v < 1 || v > MAXDIM ) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 LOGGER.log(Level.INFO, "bad max dimension: $value")
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 value = default
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 Toolkit.getDefaultToolkit().beep()
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 }