20
|
1 /*
|
|
2 * A standard spinner for inputting the output quality of a JPEG 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 /* allowable JPEG quality range */
|
|
14 private val MINQUAL = 0
|
|
15 private val MAXQUAL = 100
|
|
16
|
|
17 class OutQualSpinner(val default: Int): JSpinner(SpinnerNumberModel(default, MINQUAL, MAXQUAL, 1))
|
|
18 {
|
|
19 init {
|
21
|
20 editor = JSpinner.NumberEditor(this).apply {
|
|
21 textField.columns = MAXQUAL.toString().length
|
|
22 }
|
20
|
23 value = default
|
21
|
24 maximumSize = preferredSize
|
20
|
25 addChangeListener( ChangeListener {
|
|
26 val v = value as? Int
|
|
27 if (v == null || v < MINQUAL || v > MAXQUAL) {
|
|
28 LOGGER.log(Level.INFO, "bad output quality: $value")
|
|
29 value = default
|
|
30 Toolkit.getDefaultToolkit().beep()
|
|
31 }
|
|
32 })
|
|
33 }
|
|
34 }
|