Mercurial > cgi-bin > hgweb.cgi > ClipMan
comparison src/name/blackcap/clipman/CoerceDialog.kt @ 38:08eaae2aaf76
Stop dialog resizing, fix detection of bad font sizes.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 30 Jan 2020 22:06:37 -0800 |
parents | 376643a09b52 |
children | 33fbe3a78d84 |
comparison
equal
deleted
inserted
replaced
37:9890445e4cc4 | 38:08eaae2aaf76 |
---|---|
40 /* the proportional font size */ | 40 /* the proportional font size */ |
41 private val _pSize = JComboBox<Float>(SIZES).also { | 41 private val _pSize = JComboBox<Float>(SIZES).also { |
42 it.selectedIndex = DSIZEI | 42 it.selectedIndex = DSIZEI |
43 it.alignmentX = JComboBox.LEFT_ALIGNMENT | 43 it.alignmentX = JComboBox.LEFT_ALIGNMENT |
44 it.setEditable(true) | 44 it.setEditable(true) |
45 it.actionCommand = "Size" | |
46 it.addActionListener(this) | |
47 } | 45 } |
48 val pSize: Float | 46 val pSize: Float |
49 get() { | 47 get() { |
50 return _pSize.selectedItem as Float | 48 return _pSize.selectedItem as Float |
51 } | 49 } |
63 /* the monospaced font size */ | 61 /* the monospaced font size */ |
64 private val _mSize = JComboBox<Float>(SIZES).also { | 62 private val _mSize = JComboBox<Float>(SIZES).also { |
65 it.selectedIndex = DSIZEI | 63 it.selectedIndex = DSIZEI |
66 it.alignmentX = JComboBox.LEFT_ALIGNMENT | 64 it.alignmentX = JComboBox.LEFT_ALIGNMENT |
67 it.setEditable(true) | 65 it.setEditable(true) |
68 it.actionCommand = "Size" | |
69 it.addActionListener(this) | |
70 } | 66 } |
71 val mSize: Float | 67 val mSize: Float |
72 get() { | 68 get() { |
73 return _mSize.selectedItem as Float | 69 return _mSize.selectedItem as Float |
74 } | 70 } |
146 }) | 142 }) |
147 }) | 143 }) |
148 } | 144 } |
149 rootPane.setDefaultButton(_coerce) | 145 rootPane.setDefaultButton(_coerce) |
150 pack() | 146 pack() |
147 setResizable(false) | |
151 } | 148 } |
152 | 149 |
153 override fun actionPerformed(e: ActionEvent) { | 150 override fun actionPerformed(e: ActionEvent) { |
154 when (e.actionCommand) { | 151 when (e.actionCommand) { |
155 "Size" -> { | |
156 val source = e.source as? JComboBox<Float> | |
157 if (source != null && (source.selectedItem as Float) < 1.0f) { | |
158 Toolkit.getDefaultToolkit().beep() | |
159 source.selectedIndex = DSIZEI | |
160 } | |
161 } | |
162 "Coerce" -> { | 152 "Coerce" -> { |
163 setVisible(false) | 153 setVisible(false) |
164 coerce() | 154 coerce() |
165 } | 155 } |
166 "Cancel" -> setVisible(false) | 156 "Cancel" -> setVisible(false) |
191 JOptionPane.showMessageDialog(frame.v, | 181 JOptionPane.showMessageDialog(frame.v, |
192 "Only styled texts may be coerced.", | 182 "Only styled texts may be coerced.", |
193 "Error", | 183 "Error", |
194 JOptionPane.ERROR_MESSAGE) | 184 JOptionPane.ERROR_MESSAGE) |
195 } else { | 185 } else { |
186 if (badSize(_pSize, "proportionally-spaced") || badSize(_mSize, "monospaced")) { | |
187 return | |
188 } | |
196 PasteboardItem.write( | 189 PasteboardItem.write( |
197 PasteboardItem.HTML( | 190 PasteboardItem.HTML( |
198 plain, | 191 plain, |
199 coerceHTML(html, normalizeFont(pFamily), pSize, | 192 coerceHTML(html, normalizeFont(pFamily), pSize, |
200 normalizeFont(mFamily), mSize))) | 193 normalizeFont(mFamily), mSize))) |
201 } | 194 } |
202 } | 195 } |
196 } | |
197 | |
198 private fun badSize(control: JComboBox<Float>, fontType: String): Boolean { | |
199 val size = control.selectedItem as? Float | |
200 if (size == null || size < 1.0f) { | |
201 JOptionPane.showMessageDialog(frame.v, | |
202 "Invalid ${fontType} font size.", | |
203 "Error", | |
204 JOptionPane.ERROR_MESSAGE) | |
205 control.selectedIndex = DSIZEI | |
206 return true | |
207 } | |
208 return false | |
203 } | 209 } |
204 | 210 |
205 private fun getFontIndex(font: String): Int { | 211 private fun getFontIndex(font: String): Int { |
206 val found = FONTS.indexOf(font) | 212 val found = FONTS.indexOf(font) |
207 if (found < 0) { | 213 if (found < 0) { |