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