@@ -20,13 +20,10 @@ import org.digma.intellij.plugin.ui.model.environment.EnvironmentsSupplier
2020import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
2121import java.awt.Dimension
2222import java.awt.FlowLayout
23- import java.util.Objects
23+ import java.util.*
2424import java.util.function.Function
2525import javax.swing.Icon
2626import javax.swing.JComponent
27- import kotlin.math.abs
28- import kotlin.math.max
29- import kotlin.math.min
3027
3128// need to remember we have two instances of this panel , one for the insights tab and one for the errors tab.
3229// both instances need to be in sync with the selected button and the environments list.
@@ -60,35 +57,32 @@ class EnvironmentsPanel(
6057 }
6158
6259 /*
63- usually this panel works fine.
64- there is one issue: sometimes when the plugin window opens on startup this panel takes too much
65- vertical space and the insights list is almost not shown. any hover over this panel with the mouse or any
66- other action related to the plugin will fix it and the tab will re-layout. from there on the panel functions ok.
67- I could not find any way to cause this panel to layout correctly on startup.
68- so the code in getPreferredSize limits the height on startup to a reasonable size and only the first few calls
69- to getPreferredSize, from there on its ok. it proves to solve or at least hide the issue.
70- it will be noticeable when there are many environments and only on first opening of the window and only occasionally.
71- */
72- private var startup = 0
60+ usually this panel works fine.
61+ there is one issue: sometimes when the plugin window opens on startup this panel takes too much
62+ vertical space and the insights list is almost not shown. any hover over this panel with the mouse or any
63+ other action related to the plugin will fix it and the tab will re-layout. from there on the panel functions ok.
64+ It seems that super.getPreferredSize() sometimes returns a size with negative width, when that happens the flow
65+ layout computes a much too large vertical space and when the panel is first visible it's too large.
66+ I could not find any way to cause this panel to layout correctly on startup.
67+ this code in getPreferredSize will keep track on the last positive size and return that one if super returns
68+ a negative width. it seems to do the job.
69+ */
70+ private var lastPositivePs: Dimension = Dimension (100 , 300 )
7371 override fun getPreferredSize (): Dimension {
74- if (startup < 5 ) {
75- startup++
76- val myPs = super .getPreferredSize()
77- if (myPs != null && myPs.width > 0 && myPs.height > 0 ) {
78- var aggregatedWidth = 0
79- var height = 30
80- components.forEach {
81- aggregatedWidth + = abs(it.preferredSize.width)
82- height = max(height, abs(it.preferredSize.height))
83- }
84- val lines = (aggregatedWidth / (abs(myPs.width) + 1 )) + 1
85- val preferredHeight = (lines * height) + (lines * 3 )
86- return Dimension (myPs.width, min(min(myPs.height, preferredHeight), 300 ))
72+ val ps = super .getPreferredSize()
73+ if (ps != null ) {
74+ return if (ps.width >= 0 && ps.height >= 0 ) {
75+ lastPositivePs = ps
76+ ps
77+ } else {
78+ lastPositivePs
8779 }
8880 }
81+
8982 return super .getPreferredSize()
9083 }
9184
85+
9286 private fun select (newSelectedEnv : String? ) {
9387 val currentSelected: EnvLink ? = getSelected()
9488 if (currentSelected != null ) {
0 commit comments