annotate src/name/blackcap/imageprep/MaxDimSpinner.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 /*
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
2 * A standard combo box for inputting the maximum dimension of an image.
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
3 * Note that this IS NOT a spinner; this class is so named for historical
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
4 * reasons.
20
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 package name.blackcap.imageprep
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
7
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.Toolkit
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
9 import java.awt.event.ActionEvent
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
10 import java.awt.event.ActionListener
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.util.logging.Level
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.util.logging.Logger
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
13 import javax.swing.*
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
14
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 /* maximum allowable maximum dimension */
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 private val MAXDIM = 16384
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
17
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 /* preferred standard dimensions */
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
19 private val STDDIMS = arrayOf<Int>(1600, 1280, 1024, 800, 640, 512, 400, 320).apply {
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
20 sort()
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
21 }
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
22
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
23 class MaxDimSpinner(val default: Int): JComboBox<Int>(STDDIMS)
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 {
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
25 private var _value: Int = 0
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
26 var value: Int
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
27 get() = _value
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
28 set(v) {
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
29 if (outOfRange(v))
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
30 throw IllegalArgumentException("bad max dimension: $v")
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
31 _value = v
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
32 val pos = STDDIMS.binarySearch(v)
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
33 if (pos >= 0)
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
34 selectedIndex = pos
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
35 else
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
36 selectedItem = v
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
37 }
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
38
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
39 private fun outOfRange(v: Int): Boolean = v < 1 || v > MAXDIM
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
40
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 init {
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 value = default
21
0f3634a0816d De-uglify SettingsDialog.
David Barts <n5jrn@me.com>
parents: 20
diff changeset
43 maximumSize = preferredSize
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
44 setEditable(true)
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
45 prototypeDisplayValue = MAXDIM
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
46 addActionListener(ActionListener {
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
47 val v = selectedItem as? Int ?: (selectedItem as? String)?.toIntOrNull()
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
48 if (v == null || outOfRange(v)) {
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
49 LOGGER.log(Level.INFO, "bad max dimension: $selectedItem")
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
50 Toolkit.getDefaultToolkit().beep()
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 value = default
22
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
52 } else {
d3979a2155a8 Fix out qual and max dim controls.
David Barts <n5jrn@me.com>
parents: 21
diff changeset
53 _value = v
20
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 })
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 }
71029c9bf7cd Commit overlooked files.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 }