Skip to content

Commit 7153e7c

Browse files
committed
fix spacing between components
1 parent 5869fe2 commit 7153e7c

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/UTBotBaseWizardStep.kt

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ package org.utbot.cpp.clion.plugin.ui.wizard
33
import com.intellij.ide.wizard.Step
44
import com.intellij.openapi.ui.DialogPanel
55
import com.intellij.util.ui.HtmlPanel
6+
import com.intellij.util.ui.UIUtil
7+
import javax.swing.Box
68
import javax.swing.BoxLayout
79
import javax.swing.Icon
810
import javax.swing.JComponent
911
import javax.swing.JPanel
1012
import java.awt.Component
1113
import java.awt.Dimension
14+
import java.awt.Font
1215

1316
abstract class UTBotBaseWizardStep : Step {
1417
private val panel by lazy { JPanel() }
@@ -21,18 +24,19 @@ abstract class UTBotBaseWizardStep : Step {
2124
override fun _init() {
2225
if (!isInitialized) {
2326
panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS)
24-
panel.preferredSize = Dimension(800, 400)
27+
panel.preferredSize = Dimension(STEP_WIDTH, STEP_HEIGHT)
2528
panel.minimumSize = panel.preferredSize
2629
createUI()
30+
panel.add(Box.createVerticalGlue())
2731

2832
isInitialized = true
2933
}
3034
}
3135

32-
fun DialogPanel.addToUI() {
33-
alignmentX = Component.LEFT_ALIGNMENT
34-
panel.add(this)
36+
protected fun DialogPanel.addToUI() {
37+
this.maximumSize = Dimension(maximumSize.width, minimumSize.height)
3538
onApplyCallbacks.add { apply() }
39+
addComponentToStep(this)
3640
}
3741

3842
override fun _commit(finishChosen: Boolean) = onApplyCallbacks.forEach { it.invoke() }
@@ -44,30 +48,42 @@ abstract class UTBotBaseWizardStep : Step {
4448

4549
override fun getPreferredFocusedComponent(): JComponent? = panel
4650

47-
fun addHtml(htmlResource: String) {
51+
protected fun addHtml(htmlResource: String) {
4852
val text = this.javaClass.classLoader.getResource(htmlResource)?.readText()
4953
?: error("Unable to get resource: $htmlResource")
50-
panel.add(createHtmlComponent(text))
54+
addComponentToStep(createHtmlComponent(text))
55+
}
56+
57+
private fun addComponentToStep(component: JComponent) {
58+
// From BoxLayout docs: all components should have the same alignmentX
59+
component.alignmentX = Component.LEFT_ALIGNMENT
60+
panel.add(component)
5161
}
5262

5363
open fun canProceedToNextStep(): Boolean = true
5464

5565
private fun createHtmlComponent(html: String): JComponent = object : HtmlPanel() {
5666
init {
5767
update()
58-
alignmentX = Component.LEFT_ALIGNMENT
59-
adjustHeightToTextHeight()
68+
adjustHeightToTextHeight(STEP_WIDTH)
6069
}
6170

71+
override fun getBodyFont(): Font = UIUtil.getButtonFont().deriveFont(Font.PLAIN)
6272
override fun getBody() = html
6373

64-
fun adjustHeightToTextHeight() {
65-
// set dummy size, to update preferred
66-
size = Dimension(100, Short.MAX_VALUE.toInt())
74+
fun adjustHeightToTextHeight(parentWidth: Int) {
75+
// to use modelToView2D the size of JTextComponent must be > 0
6776
size = preferredSize
68-
minimumSize = preferredSize
77+
val rectangleWrappingText = modelToView2D(document.length)
78+
preferredSize =
79+
Dimension(parentWidth, rectangleWrappingText.y.toInt() + rectangleWrappingText.height.toInt())
6980
maximumSize = preferredSize
7081
update()
7182
}
7283
}
84+
85+
companion object {
86+
private const val STEP_HEIGHT = 400
87+
private const val STEP_WIDTH = 800
88+
}
7389
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h2>🖥️ Server Installation</h2>
22
<p> If you are working on remote machine you can start UTBot Server installation
3-
right from here. Otherwise, please do it manually. </p>
4-
<p> In order to learn more about UTBot Server Installation process,
3+
right from here. Otherwise, please do it manually.
4+
In order to learn more about UTBot Server Installation process,
55
please, refer to the
66
<a href="https://github.com/UnitTestBot/UTBotCpp/wiki/install-server">installation manual</a>.
77
</p>

0 commit comments

Comments
 (0)