comparison src/name/blackcap/clipman/CoerceDialog.kt @ 32:4d87bedb3f65

Looks better, Still wrestling with the damned labels.
author David Barts <n5jrn@me.com>
date Thu, 30 Jan 2020 18:01:57 -0800
parents 0c6c18a733b7
children 277cbb78bc5a
comparison
equal deleted inserted replaced
31:0c6c18a733b7 32:4d87bedb3f65
26 private val DSIZEI = 6 /* SIZES[6] = 16 */ 26 private val DSIZEI = 6 /* SIZES[6] = 16 */
27 27
28 /* the proportional font family */ 28 /* the proportional font family */
29 private val _pFamily = JComboBox<String>(FONTS).apply { 29 private val _pFamily = JComboBox<String>(FONTS).apply {
30 selectedIndex = getFontIndex(Font.SERIF) 30 selectedIndex = getFontIndex(Font.SERIF)
31 alignmentX = JComboBox.LEFT_ALIGNMENT
31 } 32 }
32 val pFamily: String 33 val pFamily: String
33 get() { 34 get() {
34 return _pFamily.selectedItem as String 35 return _pFamily.selectedItem as String
35 } 36 }
36 37
37 /* the proportional font size */ 38 /* the proportional font size */
38 private val _pSize = JComboBox<Float>(SIZES).also { 39 private val _pSize = JComboBox<Float>(SIZES).also {
39 it.selectedIndex = DSIZEI 40 it.selectedIndex = DSIZEI
41 it.alignmentX = JComboBox.LEFT_ALIGNMENT
40 it.setEditable(true) 42 it.setEditable(true)
41 it.actionCommand = "Size" 43 it.actionCommand = "Size"
42 it.addActionListener(this) 44 it.addActionListener(this)
43 } 45 }
44 val pSize: Float 46 val pSize: Float
47 } 49 }
48 50
49 /* the monospaced font family */ 51 /* the monospaced font family */
50 private val _mFamily = JComboBox<String>(FONTS).apply { 52 private val _mFamily = JComboBox<String>(FONTS).apply {
51 selectedIndex = getFontIndex(Font.MONOSPACED) 53 selectedIndex = getFontIndex(Font.MONOSPACED)
54 alignmentX = JComboBox.LEFT_ALIGNMENT
52 } 55 }
53 val mFamily: String 56 val mFamily: String
54 get() { 57 get() {
55 return _mFamily.selectedItem as String 58 return _mFamily.selectedItem as String
56 } 59 }
57 60
58 /* the monospaced font size */ 61 /* the monospaced font size */
59 private val _mSize = JComboBox<Float>(SIZES).also { 62 private val _mSize = JComboBox<Float>(SIZES).also {
60 it.selectedIndex = DSIZEI 63 it.selectedIndex = DSIZEI
64 it.alignmentX = JComboBox.LEFT_ALIGNMENT
61 it.setEditable(true) 65 it.setEditable(true)
62 it.actionCommand = "Size" 66 it.actionCommand = "Size"
63 it.addActionListener(this) 67 it.addActionListener(this)
64 } 68 }
65 val mSize: Float 69 val mSize: Float
68 } 72 }
69 73
70 /* standard spacing between elements (10 pixels ≅ 1/7") and half that */ 74 /* standard spacing between elements (10 pixels ≅ 1/7") and half that */
71 private val BW = 5 75 private val BW = 5
72 private val BW2 = 10 76 private val BW2 = 10
73 private val VSPACE = Box.createVerticalStrut(BW)
74 private val VSPACE2 = Box.createVerticalStrut(BW2)
75 private val HSPACE2 = Box.createHorizontalStrut(BW2)
76 77
77 /* buttons */ 78 /* buttons */
78 private val _coerce = JButton("Coerce").also { 79 private val _coerce = JButton("Coerce").also {
79 it.actionCommand = "Coerce" 80 it.actionCommand = "Coerce"
80 it.addActionListener(this) 81 it.addActionListener(this)
88 /* initializer */ 89 /* initializer */
89 init { 90 init {
90 title = "Coerce Fonts" 91 title = "Coerce Fonts"
91 contentPane.apply { 92 contentPane.apply {
92 add(Box(BoxLayout.Y_AXIS).apply { 93 add(Box(BoxLayout.Y_AXIS).apply {
93 add(VSPACE2) 94 alignmentX = Box.CENTER_ALIGNMENT
94 add(leftLabel("Coerce proportionally-spaced text to:")) 95 add(JLabel("Coerce proportionally-spaced text to:").apply {
95 add(VSPACE) 96 horizontalAlignment = JLabel.CENTER
97 alignmentX = JLabel.CENTER_ALIGNMENT
98 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
99 })
96 add(Box(BoxLayout.X_AXIS).apply { 100 add(Box(BoxLayout.X_AXIS).apply {
97 add(HSPACE2) 101 border = BorderFactory.createEmptyBorder(0, BW2, BW, BW2)
98 add(Box.createGlue()) 102 add(Box.createGlue())
99 add(Box(BoxLayout.Y_AXIS).apply { 103 add(Box(BoxLayout.Y_AXIS).apply {
100 add(leftLabel("Family:")) 104 add(JLabel("Family:").apply {
105 horizontalAlignment = JLabel.CENTER
106 alignmentX = JLabel.LEFT_ALIGNMENT
107 })
101 add(_pFamily) 108 add(_pFamily)
102 }) 109 })
103 add(Box.createGlue()) 110 add(Box.createGlue())
104 add(Box(BoxLayout.Y_AXIS).apply { 111 add(Box(BoxLayout.Y_AXIS).apply {
105 add(leftLabel("Size:")) 112 add(JLabel("Size:").apply {
113 horizontalAlignment = JLabel.CENTER
114 alignmentX = JLabel.LEFT_ALIGNMENT
115 })
106 add(_pSize) 116 add(_pSize)
107 }) 117 })
108 add(Box.createGlue()) 118 add(Box.createGlue())
109 add(HSPACE2) 119 })
110 })
111 add(VSPACE2)
112 add(JSeparator()) 120 add(JSeparator())
113 add(VSPACE2) 121 add(JLabel("Coerce monospaced text to:").apply {
114 add(leftLabel("Coerce monospaced text to:")) 122 horizontalAlignment = JLabel.CENTER
115 add(VSPACE) 123 alignmentX = JLabel.CENTER_ALIGNMENT
124 border = BorderFactory.createEmptyBorder(BW2, BW2, BW, BW2)
125 })
116 add(Box(BoxLayout.X_AXIS).apply { 126 add(Box(BoxLayout.X_AXIS).apply {
117 add(HSPACE2) 127 border = BorderFactory.createEmptyBorder(0, BW2, BW, BW2)
118 add(Box.createGlue()) 128 add(Box.createGlue())
119 add(Box(BoxLayout.Y_AXIS).apply { 129 add(Box(BoxLayout.Y_AXIS).apply {
120 add(leftLabel("Family:")) 130 add(JLabel("Family:").apply {
131 horizontalAlignment = JLabel.CENTER
132 alignmentX = JLabel.LEFT_ALIGNMENT
133 })
121 add(_mFamily) 134 add(_mFamily)
122 }) 135 })
123 add(Box.createGlue()) 136 add(Box.createGlue())
124 add(Box(BoxLayout.Y_AXIS).apply { 137 add(Box(BoxLayout.Y_AXIS).apply {
125 add(leftLabel("Size:")) 138 add(JLabel("Size:").apply {
139 horizontalAlignment = JLabel.CENTER
140 alignmentX = JLabel.LEFT_ALIGNMENT
141 })
126 add(_mSize) 142 add(_mSize)
127 }) 143 })
128 add(Box.createGlue()) 144 add(Box.createGlue())
129 add(HSPACE2) 145 })
130 })
131 add(VSPACE2)
132 add(JSeparator()) 146 add(JSeparator())
133 add(VSPACE2)
134 add(Box(BoxLayout.X_AXIS).apply { 147 add(Box(BoxLayout.X_AXIS).apply {
148 border = BorderFactory.createEmptyBorder(BW2, BW2, BW2, BW2)
135 add(Box.createGlue()) 149 add(Box.createGlue())
136 add(_cancel) 150 add(_cancel)
137 add(Box.createGlue()) 151 add(Box.createGlue())
138 add(_coerce) 152 add(_coerce)
139 add(Box.createGlue()) 153 add(Box.createGlue())
140 }) 154 })
141 add(VSPACE2)
142 }) 155 })
143 } 156 }
144 rootPane.setDefaultButton(_coerce) 157 rootPane.setDefaultButton(_coerce)
145 pack() 158 pack()
146 }
147
148 private fun leftLabel(text: String) = JLabel(text).apply {
149 horizontalAlignment = JLabel.LEFT
150 alignmentX = JLabel.LEFT_ALIGNMENT
151 } 159 }
152 160
153 override fun actionPerformed(e: ActionEvent) { 161 override fun actionPerformed(e: ActionEvent) {
154 when (e.actionCommand) { 162 when (e.actionCommand) {
155 "Size" -> { 163 "Size" -> {