20
|
1 /*
|
|
2 * A standard spinner for inputting the maximum dimension of an image.
|
|
3 */
|
|
4 package name.blackcap.imageprep
|
|
5
|
|
6 import java.awt.Toolkit
|
|
7 import javax.swing.*
|
|
8 import javax.swing.event.ChangeEvent
|
|
9 import javax.swing.event.ChangeListener
|
|
10 import java.util.logging.Level
|
|
11 import java.util.logging.Logger
|
|
12
|
|
13 /* maximum allowable maximum dimension */
|
|
14 private val MAXDIM = 16384
|
|
15
|
|
16 /* preferred standard dimensions */
|
|
17 private val STDDIMS = listOf<Int>(1600, 1280, 1024, 800, 640, 512, 400, 320)
|
|
18
|
|
19 class MaxDimSpinner(val default: Int): JSpinner(SpinnerListModel(STDDIMS))
|
|
20 {
|
|
21 init {
|
|
22 editor = JSpinner.ListEditor(this)
|
|
23 value = default
|
|
24 noTaller()
|
|
25 addChangeListener( ChangeListener {
|
|
26 val v = value as? Int ?: (value as? String)?.toIntOrNull()
|
|
27 if ( v == null || v < 1 || v > MAXDIM ) {
|
|
28 LOGGER.log(Level.INFO, "bad max dimension: $value")
|
|
29 value = default
|
|
30 Toolkit.getDefaultToolkit().beep()
|
|
31 }
|
|
32 })
|
|
33 }
|
|
34 }
|