annotate src/name/blackcap/clipman/CoerceDialog.kt @ 58:88056f373a94

Set app name, deal with some deprecation.
author David Barts <n5jrn@me.com>
date Sat, 26 Mar 2022 23:45:34 -0700
parents 22725d4d7849
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 /*
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 * The dialog that controls font corecion.
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 package name.blackcap.clipman
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
5
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 import java.awt.Color
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
7 import java.awt.Container
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
8 import java.awt.Dimension
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.Font
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.awt.GraphicsEnvironment
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.awt.Toolkit
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.awt.event.ActionEvent
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.awt.event.ActionListener
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import java.util.logging.Level
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 import java.util.logging.Logger
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import javax.swing.*
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 import javax.swing.event.DocumentEvent
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 import javax.swing.event.DocumentListener
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
19
47
19d9da731c43 Recoded; cleaned up root namespace, removed race conditions.
David Barts <n5jrn@me.com>
parents: 43
diff changeset
20 class CoerceDialog: JDialog(Application.frame), ActionListener {
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
21 private val FONTS =
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
22 GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply {
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
23 sort()
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
24 }
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
25 private val SIZES =
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
26 arrayOf(9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 16.0f, 18.0f,
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
27 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 96.0f, 144.0f, 288.0f)
41
33fbe3a78d84 Got the settings stuff compiling (untested).
David Barts <n5jrn@me.com>
parents: 38
diff changeset
28
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 /* the proportional font family */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 private val _pFamily = JComboBox<String>(FONTS).apply {
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
31 selectedIndex = getFontIndex(Font.SERIF)
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
32 alignmentX = JComboBox.LEFT_ALIGNMENT
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 val pFamily: String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 return _pFamily.selectedItem as String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
38
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 /* the proportional font size */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 private val _pSize = JComboBox<Float>(SIZES).also {
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
41 it.selectedItem = PROP_SIZE.toFloat()
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
42 it.alignmentX = JComboBox.LEFT_ALIGNMENT
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 it.setEditable(true)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 val pSize: Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 return _pSize.selectedItem as Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
49
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 /* the monospaced font family */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 private val _mFamily = JComboBox<String>(FONTS).apply {
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
52 selectedIndex = getFontIndex(Font.MONOSPACED)
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
53 alignmentX = JComboBox.LEFT_ALIGNMENT
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 val mFamily: String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
57 return _mFamily.selectedItem as String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
59
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
60 /* the monospaced font size */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
61 private val _mSize = JComboBox<Float>(SIZES).also {
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
62 it.selectedItem = MONO_SIZE.toFloat()
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
63 it.alignmentX = JComboBox.LEFT_ALIGNMENT
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 it.setEditable(true)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 val mSize: Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 return _mSize.selectedItem as Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
70
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 /* standard spacing between elements (10 pixels ≅ 1/7") and half that */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 private val BW = 5
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 private val BW2 = 10
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
74
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
75 /* buttons */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
76 private val _coerce = JButton("Coerce").also {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
77 it.actionCommand = "Coerce"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 it.addActionListener(this)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
79 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
80
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 private val _cancel = JButton("Cancel").also {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 it.actionCommand = "Cancel"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 it.addActionListener(this)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
85
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
86 /* initializer */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
87 init {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 title = "Coerce Fonts"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 contentPane.apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 add(Box(BoxLayout.Y_AXIS).apply {
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
91 add(Box(BoxLayout.Y_AXIS).apply {
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
92 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
93 alignmentX = Box.CENTER_ALIGNMENT
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
94 add(leftLabel("Coerce proportionally-spaced text to…"))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
95 add(Box.createVerticalStrut(BW))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
96 add(Box(BoxLayout.X_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
97 alignmentX = Box.LEFT_ALIGNMENT
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
98 add(Box.createGlue())
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
99 add(Box(BoxLayout.Y_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
100 add(leftLabel("Family:"))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
101 add(_pFamily)
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
102 })
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
103 add(Box.createGlue())
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
104 add(Box(BoxLayout.Y_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
105 add(leftLabel("Size:"))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
106 add(_pSize)
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
107 })
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
108 add(Box.createGlue())
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
109 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
110 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
111 add(JSeparator())
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
112 add(Box(BoxLayout.Y_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
113 alignmentX = Box.CENTER_ALIGNMENT
33
277cbb78bc5a A few tweaks. Piece of shit still can't left-align its labels. Sigh.
David Barts <n5jrn@me.com>
parents: 32
diff changeset
114 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
115 add(leftLabel("Coerce monospaced text to…"))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
116 add(Box.createVerticalStrut(BW))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
117 add(Box(BoxLayout.X_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
118 alignmentX = Box.LEFT_ALIGNMENT
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
119 add(Box.createGlue())
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
120 add(Box(BoxLayout.Y_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
121 add(leftLabel("Family:"))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
122 add(_mFamily)
32
4d87bedb3f65 Looks better, Still wrestling with the damned labels.
David Barts <n5jrn@me.com>
parents: 31
diff changeset
123 })
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
124 add(Box.createGlue())
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
125 add(Box(BoxLayout.Y_AXIS).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
126 add(leftLabel("Size:"))
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
127 add(_mSize)
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
128 })
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
129 add(Box.createGlue())
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
130 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
131 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
132 add(JSeparator())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
133 add(Box(BoxLayout.X_AXIS).apply {
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
134 alignmentX = Box.CENTER_ALIGNMENT
33
277cbb78bc5a A few tweaks. Piece of shit still can't left-align its labels. Sigh.
David Barts <n5jrn@me.com>
parents: 32
diff changeset
135 border = BorderFactory.createEmptyBorder(BW, BW2, BW, BW2)
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
137 add(_cancel)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
138 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 add(_coerce)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
141 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
144 rootPane.setDefaultButton(_coerce)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
145 pack()
38
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
146 setResizable(false)
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
148
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
149 override fun actionPerformed(e: ActionEvent) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 when (e.actionCommand) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
151 "Coerce" -> {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
152 setVisible(false)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
153 coerce()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
154 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
155 "Cancel" -> setVisible(false)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
156 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
157 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
158
34
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
159 private fun leftLabel(text: String) = JLabel(text).apply {
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
160 alignmentX = JLabel.LEFT_ALIGNMENT
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
161 }
376643a09b52 Finally fixed the alignment. Wotta PITA...
David Barts <n5jrn@me.com>
parents: 33
diff changeset
162
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
163 private fun coerce() {
47
19d9da731c43 Recoded; cleaned up root namespace, removed race conditions.
David Barts <n5jrn@me.com>
parents: 43
diff changeset
164 val selected = Application.queue.getSelected()
56
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
165 if (!suitedForCoercing(selected)) {
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
166 return
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
167 }
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
168 if (selected == null) {
56
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
169 return /* redundant, but makes kotlinc happy */
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
170 }
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
171 if (badSize(_pSize, PROP_SIZE, "proportionally-spaced") || badSize(_mSize, MONO_SIZE, "monospaced")) {
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
172 return
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
173 }
56
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
174 val (plain, html) = when (selected.contents) {
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
175 is PasteboardItem.Plain ->
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
176 Pair(selected.contents.plain, null)
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
177 is PasteboardItem.HTML ->
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
178 Pair(selected.contents.plain, selected.contents.html)
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
179 is PasteboardItem.RTF ->
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
180 Pair(selected.contents.plain, selected.contents.html)
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
181 }
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
182 PasteboardItem.write(
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
183 PasteboardItem.HTML(
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
184 plain,
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
185 coerceHTML(html!!, normalizeFont(pFamily), pSize,
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
186 normalizeFont(mFamily), mSize)))
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
187 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
188
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
189 private fun badSize(control: JComboBox<Float>, default: Int, fontType: String): Boolean {
38
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
190 val size = control.selectedItem as? Float
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
191 if (size == null || size < 1.0f) {
47
19d9da731c43 Recoded; cleaned up root namespace, removed race conditions.
David Barts <n5jrn@me.com>
parents: 43
diff changeset
192 JOptionPane.showMessageDialog(Application.frame,
38
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
193 "Invalid ${fontType} font size.",
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
194 "Error",
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
195 JOptionPane.ERROR_MESSAGE)
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
196 control.selectedItem = default.toFloat()
38
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
197 return true
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
198 }
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
199 return false
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
200 }
08eaae2aaf76 Stop dialog resizing, fix detection of bad font sizes.
David Barts <n5jrn@me.com>
parents: 34
diff changeset
201
43
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
202 private fun getFontIndex(font: String): Int {
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
203 val found = FONTS.indexOf(font)
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
204 if (found < 0) {
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
205 LOGGER.log(Level.WARNING, "font '${font}' not found")
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
206 return 0
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
207 }
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
208 return found
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
209 }
339e2da5bf83 Simplified the settings. Compiles, not tested.
David Barts <n5jrn@me.com>
parents: 41
diff changeset
210
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
211 private fun normalizeFont(font: String): String {
58
88056f373a94 Set app name, deal with some deprecation.
David Barts <n5jrn@me.com>
parents: 56
diff changeset
212 val lcFont = font.lowercase()
31
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
213 return when (lcFont) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
214 in setOf("monospace", "serif", "sans-serif") -> lcFont
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
215 "monospaced" -> "monospace"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
216 "sansserif" -> "sans-serif"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
217 else -> font
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
218 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
219 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
220 }
56
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
221
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
222 /**
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
223 * See if the selected pasteboard item is suitable for coercing. If not,
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
224 * issue an error dialog.
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
225 */
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
226 fun suitedForCoercing(selected: QueueItem?): Boolean {
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
227 if (selected == null) {
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
228 JOptionPane.showMessageDialog(Application.frame,
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
229 "No item selected.",
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
230 "Error",
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
231 JOptionPane.ERROR_MESSAGE)
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
232 return false
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
233 }
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
234 if (selected.contents is PasteboardItem.Plain) {
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
235 JOptionPane.showMessageDialog(Application.frame,
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
236 "Only styled texts may be coerced.",
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
237 "Error",
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
238 JOptionPane.ERROR_MESSAGE)
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
239 return false
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
240 }
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
241 return true
22725d4d7849 An attempt to get it to troff-ize styled text.
David Barts <n5jrn@me.com>
parents: 47
diff changeset
242 }