annotate src/name/blackcap/clipman/CoerceDialog.kt @ 31:0c6c18a733b7

Compiles, new menu still a mess.
author David Barts <n5jrn@me.com>
date Thu, 30 Jan 2020 16:01:51 -0800
parents
children 4d87bedb3f65
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
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 import java.awt.Font
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 import java.awt.GraphicsEnvironment
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 import java.awt.Toolkit
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 import java.awt.event.ActionEvent
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 import java.awt.event.ActionListener
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 import java.util.logging.Level
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 import java.util.logging.Logger
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 import javax.swing.*
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 import javax.swing.event.DocumentEvent
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 import javax.swing.event.DocumentListener
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
17
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 class CoerceDialog: JDialog(frame.v), ActionListener {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 private val FONTS =
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
20 GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
21 sort()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
22 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
23 private val SIZES =
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 arrayOf(9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 16.0f, 18.0f,
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
25 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 96.0f, 144.0f, 288.0f)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 private val DSIZEI = 6 /* SIZES[6] = 16 */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
27
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 /* the proportional font family */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 private val _pFamily = JComboBox<String>(FONTS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 selectedIndex = getFontIndex(Font.SERIF)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 val pFamily: String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 return _pFamily.selectedItem as String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
36
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
37 /* the proportional font size */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
38 private val _pSize = JComboBox<Float>(SIZES).also {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 it.selectedIndex = DSIZEI
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
40 it.setEditable(true)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 it.actionCommand = "Size"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 it.addActionListener(this)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 val pSize: Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
45 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 return _pSize.selectedItem as Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 }
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 /* the monospaced font family */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 private val _mFamily = JComboBox<String>(FONTS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 selectedIndex = getFontIndex(Font.MONOSPACED)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
52 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
53 val mFamily: String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
54 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 return _mFamily.selectedItem as String
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
57
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
58 /* the monospaced font size */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
59 private val _mSize = JComboBox<Float>(SIZES).also {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
60 it.selectedIndex = DSIZEI
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
61 it.setEditable(true)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
62 it.actionCommand = "Size"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
63 it.addActionListener(this)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 val mSize: Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 get() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 return _mSize.selectedItem as Float
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 }
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 /* 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
71 private val BW = 5
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 private val BW2 = 10
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 private val VSPACE = Box.createVerticalStrut(BW)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 private val VSPACE2 = Box.createVerticalStrut(BW2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
75 private val HSPACE2 = Box.createHorizontalStrut(BW2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
76
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
77 /* buttons */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 private val _coerce = JButton("Coerce").also {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
79 it.actionCommand = "Coerce"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
80 it.addActionListener(this)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
81 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
82
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 private val _cancel = JButton("Cancel").also {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 it.actionCommand = "Cancel"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 it.addActionListener(this)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
86 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
87
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 /* initializer */
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 init {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 title = "Coerce Fonts"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
91 contentPane.apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
92 add(Box(BoxLayout.Y_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 add(VSPACE2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 add(leftLabel("Coerce proportionally-spaced text to:"))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
95 add(VSPACE)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 add(Box(BoxLayout.X_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 add(HSPACE2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
98 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 add(Box(BoxLayout.Y_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 add(leftLabel("Family:"))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 add(_pFamily)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
104 add(Box(BoxLayout.Y_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
105 add(leftLabel("Size:"))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
106 add(_pSize)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
107 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
108 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
109 add(HSPACE2)
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(VSPACE2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
112 add(JSeparator())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
113 add(VSPACE2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
114 add(leftLabel("Coerce monospaced text to:"))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
115 add(VSPACE)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
116 add(Box(BoxLayout.X_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
117 add(HSPACE2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
118 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
119 add(Box(BoxLayout.Y_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
120 add(leftLabel("Family:"))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
121 add(_mFamily)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
123 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 add(Box(BoxLayout.Y_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
125 add(leftLabel("Size:"))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 add(_mSize)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
127 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
128 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
129 add(HSPACE2)
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 add(VSPACE2)
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(VSPACE2)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
134 add(Box(BoxLayout.X_AXIS).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
135 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 add(_cancel)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
137 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
138 add(_coerce)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 add(Box.createGlue())
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 })
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
141 add(VSPACE2)
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()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 }
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 private fun leftLabel(text: String) = JLabel(text).apply {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
149 horizontalAlignment = JLabel.LEFT
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
150 alignmentX = JLabel.LEFT_ALIGNMENT
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
151 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
152
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
153 override fun actionPerformed(e: ActionEvent) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
154 when (e.actionCommand) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
155 "Size" -> {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
156 val source = e.source as? JComboBox<Float>
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
157 if (source != null && (source.selectedItem as Float) < 1.0f) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
158 Toolkit.getDefaultToolkit().beep()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
159 source.selectedIndex = DSIZEI
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
160 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
161 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
162 "Coerce" -> {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
163 setVisible(false)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
164 coerce()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
166 "Cancel" -> setVisible(false)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
167 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
168 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
169
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
170 private fun coerce() {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
171 val selected = queue.v.getSelected()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
172 if (selected == null) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
173 JOptionPane.showMessageDialog(frame.v,
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
174 "No item selected.",
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
175 "Error",
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
176 JOptionPane.ERROR_MESSAGE)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
177 } else {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
178 val (plain, html) = when (selected.contents) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
179 is PasteboardItem.Plain ->
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
180 Pair(selected.contents.plain, null)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
181 is PasteboardItem.HTML ->
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
182 Pair(selected.contents.plain, selected.contents.html)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
183 is PasteboardItem.RTF ->
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
184 Pair(selected.contents.plain, selected.contents.html)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
185 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
186 if (html == null) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
187 JOptionPane.showMessageDialog(frame.v,
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
188 "Only styled texts may be coerced.",
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
189 "Error",
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
190 JOptionPane.ERROR_MESSAGE)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
191 } else {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
192 PasteboardItem.write(
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
193 PasteboardItem.HTML(
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
194 plain,
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
195 coerceHTML(html, normalizeFont(pFamily), pSize,
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
196 normalizeFont(mFamily), mSize)))
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
197 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
198 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
199 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
200
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
201 private fun getFontIndex(font: String): Int {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
202 val found = FONTS.indexOf(font)
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
203 if (found < 0) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
204 LOGGER.log(Level.WARNING, "font '${font}' not found")
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
205 return 0
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
206 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
207 return found
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
208 }
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
209
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
210 private fun normalizeFont(font: String): String {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
211 val lcFont = font.toLowerCase()
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
212 return when (lcFont) {
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
213 in setOf("monospace", "serif", "sans-serif") -> lcFont
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
214 "monospaced" -> "monospace"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
215 "sansserif" -> "sans-serif"
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
216 else -> font
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
217 }
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
0c6c18a733b7 Compiles, new menu still a mess.
David Barts <n5jrn@me.com>
parents:
diff changeset
221 val coerceDialog = CoerceDialog()