annotate src/name/blackcap/imageprep/OutQualSpinner.kt @ 27:404eb7e57fe6

Standardize things for Linux packaging.
author David Barts <n5jrn@me.com>
date Fri, 25 Dec 2020 18:58:45 -0800
parents d3979a2155a8
children
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 output quality of a JPEG 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 /* allowable JPEG quality range */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 private val MINQUAL = 0
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 private val MAXQUAL = 100
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 class OutQualSpinner(val default: Int): JSpinner(SpinnerNumberModel(default, MINQUAL, MAXQUAL, 1))
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 init {
21
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
20 editor = JSpinner.NumberEditor(this).apply {
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
21 textField.columns = MAXQUAL.toString().length
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
22 }
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 value = default
21
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
24 maximumSize = preferredSize
20
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
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 if (v == null || v < MINQUAL || v > MAXQUAL) {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 LOGGER.log(Level.INFO, "bad output quality: $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 }