@@ -3,12 +3,15 @@ package org.utbot.cpp.clion.plugin.ui.wizard
3
3
import com.intellij.ide.wizard.Step
4
4
import com.intellij.openapi.ui.DialogPanel
5
5
import com.intellij.util.ui.HtmlPanel
6
+ import com.intellij.util.ui.UIUtil
7
+ import javax.swing.Box
6
8
import javax.swing.BoxLayout
7
9
import javax.swing.Icon
8
10
import javax.swing.JComponent
9
11
import javax.swing.JPanel
10
12
import java.awt.Component
11
13
import java.awt.Dimension
14
+ import java.awt.Font
12
15
13
16
abstract class UTBotBaseWizardStep : Step {
14
17
private val panel by lazy { JPanel () }
@@ -21,18 +24,19 @@ abstract class UTBotBaseWizardStep : Step {
21
24
override fun _init () {
22
25
if (! isInitialized) {
23
26
panel.layout = BoxLayout (panel, BoxLayout .Y_AXIS )
24
- panel.preferredSize = Dimension (800 , 400 )
27
+ panel.preferredSize = Dimension (STEP_WIDTH , STEP_HEIGHT )
25
28
panel.minimumSize = panel.preferredSize
26
29
createUI()
30
+ panel.add(Box .createVerticalGlue())
27
31
28
32
isInitialized = true
29
33
}
30
34
}
31
35
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)
35
38
onApplyCallbacks.add { apply () }
39
+ addComponentToStep(this )
36
40
}
37
41
38
42
override fun _commit (finishChosen : Boolean ) = onApplyCallbacks.forEach { it.invoke() }
@@ -44,30 +48,42 @@ abstract class UTBotBaseWizardStep : Step {
44
48
45
49
override fun getPreferredFocusedComponent (): JComponent ? = panel
46
50
47
- fun addHtml (htmlResource : String ) {
51
+ protected fun addHtml (htmlResource : String ) {
48
52
val text = this .javaClass.classLoader.getResource(htmlResource)?.readText()
49
53
? : 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)
51
61
}
52
62
53
63
open fun canProceedToNextStep (): Boolean = true
54
64
55
65
private fun createHtmlComponent (html : String ): JComponent = object : HtmlPanel () {
56
66
init {
57
67
update()
58
- alignmentX = Component .LEFT_ALIGNMENT
59
- adjustHeightToTextHeight()
68
+ adjustHeightToTextHeight(STEP_WIDTH )
60
69
}
61
70
71
+ override fun getBodyFont (): Font = UIUtil .getButtonFont().deriveFont(Font .PLAIN )
62
72
override fun getBody () = html
63
73
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
67
76
size = preferredSize
68
- minimumSize = preferredSize
77
+ val rectangleWrappingText = modelToView2D(document.length)
78
+ preferredSize =
79
+ Dimension (parentWidth, rectangleWrappingText.y.toInt() + rectangleWrappingText.height.toInt())
69
80
maximumSize = preferredSize
70
81
update()
71
82
}
72
83
}
84
+
85
+ companion object {
86
+ private const val STEP_HEIGHT = 400
87
+ private const val STEP_WIDTH = 800
88
+ }
73
89
}
0 commit comments