comparison src/name/blackcap/clipman/CoerceDialog.kt @ 47:19d9da731c43

Recoded; cleaned up root namespace, removed race conditions.
author David Barts <n5jrn@me.com>
date Sun, 12 Apr 2020 14:31:06 -0700
parents 339e2da5bf83
children 22725d4d7849
comparison
equal deleted inserted replaced
46:88066346f129 47:19d9da731c43
15 import java.util.logging.Logger 15 import java.util.logging.Logger
16 import javax.swing.* 16 import javax.swing.*
17 import javax.swing.event.DocumentEvent 17 import javax.swing.event.DocumentEvent
18 import javax.swing.event.DocumentListener 18 import javax.swing.event.DocumentListener
19 19
20 class CoerceDialog: JDialog(frame.v), ActionListener { 20 class CoerceDialog: JDialog(Application.frame), ActionListener {
21 private val FONTS = 21 private val FONTS =
22 GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply { 22 GraphicsEnvironment.getLocalGraphicsEnvironment().availableFontFamilyNames.copyOf().apply {
23 sort() 23 sort()
24 } 24 }
25 private val SIZES = 25 private val SIZES =
159 private fun leftLabel(text: String) = JLabel(text).apply { 159 private fun leftLabel(text: String) = JLabel(text).apply {
160 alignmentX = JLabel.LEFT_ALIGNMENT 160 alignmentX = JLabel.LEFT_ALIGNMENT
161 } 161 }
162 162
163 private fun coerce() { 163 private fun coerce() {
164 val selected = queue.v.getSelected() 164 val selected = Application.queue.getSelected()
165 if (selected == null) { 165 if (selected == null) {
166 JOptionPane.showMessageDialog(frame.v, 166 JOptionPane.showMessageDialog(Application.frame,
167 "No item selected.", 167 "No item selected.",
168 "Error", 168 "Error",
169 JOptionPane.ERROR_MESSAGE) 169 JOptionPane.ERROR_MESSAGE)
170 } else { 170 } else {
171 val (plain, html) = when (selected.contents) { 171 val (plain, html) = when (selected.contents) {
175 Pair(selected.contents.plain, selected.contents.html) 175 Pair(selected.contents.plain, selected.contents.html)
176 is PasteboardItem.RTF -> 176 is PasteboardItem.RTF ->
177 Pair(selected.contents.plain, selected.contents.html) 177 Pair(selected.contents.plain, selected.contents.html)
178 } 178 }
179 if (html == null) { 179 if (html == null) {
180 JOptionPane.showMessageDialog(frame.v, 180 JOptionPane.showMessageDialog(Application.frame,
181 "Only styled texts may be coerced.", 181 "Only styled texts may be coerced.",
182 "Error", 182 "Error",
183 JOptionPane.ERROR_MESSAGE) 183 JOptionPane.ERROR_MESSAGE)
184 } else { 184 } else {
185 if (badSize(_pSize, PROP_SIZE, "proportionally-spaced") || badSize(_mSize, MONO_SIZE, "monospaced")) { 185 if (badSize(_pSize, PROP_SIZE, "proportionally-spaced") || badSize(_mSize, MONO_SIZE, "monospaced")) {
195 } 195 }
196 196
197 private fun badSize(control: JComboBox<Float>, default: Int, fontType: String): Boolean { 197 private fun badSize(control: JComboBox<Float>, default: Int, fontType: String): Boolean {
198 val size = control.selectedItem as? Float 198 val size = control.selectedItem as? Float
199 if (size == null || size < 1.0f) { 199 if (size == null || size < 1.0f) {
200 JOptionPane.showMessageDialog(frame.v, 200 JOptionPane.showMessageDialog(Application.frame,
201 "Invalid ${fontType} font size.", 201 "Invalid ${fontType} font size.",
202 "Error", 202 "Error",
203 JOptionPane.ERROR_MESSAGE) 203 JOptionPane.ERROR_MESSAGE)
204 control.selectedItem = default.toFloat() 204 control.selectedItem = default.toFloat()
205 return true 205 return true
224 "sansserif" -> "sans-serif" 224 "sansserif" -> "sans-serif"
225 else -> font 225 else -> font
226 } 226 }
227 } 227 }
228 } 228 }
229
230 val coerceDialog = CoerceDialog()