From 2af8b2e670447219e43e009ffcdb6ec23da330aa Mon Sep 17 00:00:00 2001 From: Alexey Merkulov Date: Tue, 10 Aug 2021 00:53:18 +0300 Subject: [PATCH] [IFT] Make minimum Learn toolwindow size as 460 Also remove some magic from size lesson message pane calculation GitOrigin-RevId: dd57bf23178caf1061b13b9c0e743834e06225b0 --- .../src/training/ui/UISettings.kt | 2 +- .../src/training/ui/views/LearnPanel.kt | 25 ++++++------------- .../src/training/ui/views/ModulesPanel.kt | 7 ++---- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/plugins/ide-features-trainer/src/training/ui/UISettings.kt b/plugins/ide-features-trainer/src/training/ui/UISettings.kt index b1940aee82af..2229122b86ac 100644 --- a/plugins/ide-features-trainer/src/training/ui/UISettings.kt +++ b/plugins/ide-features-trainer/src/training/ui/UISettings.kt @@ -14,7 +14,7 @@ import javax.swing.border.EmptyBorder internal class UISettings { //GENERAL UI SETTINGS - val width: Int by lazy { JBUI.scale(500) } + val panelWidth: Int by lazy { JBUI.scale(460) } //MAIN INSETS val northInset: Int by lazy { JBUI.scale(20) } diff --git a/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt b/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt index d9e606c3949f..b8efc67406c0 100644 --- a/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt +++ b/plugins/ide-features-trainer/src/training/ui/views/LearnPanel.kt @@ -76,7 +76,7 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { add(footer, BorderLayout.PAGE_END) } - preferredSize = Dimension(UISettings.instance.width, 100) + preferredSize = Dimension(UISettings.instance.panelWidth, 100) with(UISettings.instance) { border = EmptyBorder(northInset, JBUI.scale(18), southInset, JBUI.scale(18)) } @@ -136,7 +136,10 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { lessonMessagePane.alignmentX = Component.LEFT_ALIGNMENT lessonMessagePane.margin = JBUI.emptyInsets() lessonMessagePane.border = EmptyBorder(0, 0, JBUI.scale(20), JBUI.scale(14)) - lessonMessagePane.maximumSize = Dimension(UISettings.instance.width, 10000) + + preferredSize = Dimension(UISettings.instance.panelWidth, preferredSize.height) + + revalidate() //Set Next Button UI listOf(nextButton, prevButton).forEach { @@ -244,16 +247,9 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { } } - /** This important magic method is needed for [getPreferredSize]: it calculates the `lessonPanel.minimumSize` */ private fun adjustMessagesArea() { - //invoke #getPreferredSize explicitly to update actual size of LessonMessagePane - lessonMessagePane.preferredSize - - //Pack lesson panel - lessonPanel.repaint() - //run to update LessonMessagePane.getMinimumSize and LessonMessagePane.getPreferredSize - lessonPanelBoxLayout.invalidateLayout(lessonPanel) - lessonPanelBoxLayout.layoutContainer(lessonPanel) + revalidate() + repaint() } fun resetMessagesNumber(number: Int) { @@ -323,13 +319,6 @@ internal class LearnPanel(val learnToolWindow: LearnToolWindow) : JPanel() { @NlsSafe private fun getNextLessonKeyStrokeText() = "Enter" - /** It is a magic implementation and need to invoke [adjustMessagesArea] before the use of this method (from Swing library code) */ - override fun getPreferredSize(): Dimension { - if (lessonPanel.minimumSize == null) return Dimension(10, 10) - return Dimension(lessonPanel.minimumSize.getWidth().toInt() + UISettings.instance.westInset + UISettings.instance.eastInset, - lessonPanel.minimumSize.getHeight().toInt() + footer.minimumSize.getHeight().toInt() + UISettings.instance.northInset + UISettings.instance.southInset) - } - fun makeNextButtonSelected() { rootPane?.defaultButton = nextButton nextButton.isSelected = true diff --git a/plugins/ide-features-trainer/src/training/ui/views/ModulesPanel.kt b/plugins/ide-features-trainer/src/training/ui/views/ModulesPanel.kt index 821b1c9f3d0f..fed4e0de5cd0 100644 --- a/plugins/ide-features-trainer/src/training/ui/views/ModulesPanel.kt +++ b/plugins/ide-features-trainer/src/training/ui/views/ModulesPanel.kt @@ -31,6 +31,8 @@ class ModulesPanel(project: Project) : JPanel() { initModulesPanel() revalidate() + + preferredSize = Dimension(UISettings.instance.panelWidth, preferredSize.height) repaint() } @@ -105,11 +107,6 @@ class ModulesPanel(project: Project) : JPanel() { add(shiftedFooter) } - override fun getPreferredSize(): Dimension { - return Dimension(modulesPanel.minimumSize.getWidth().toInt() + UISettings.instance.westInset + UISettings.instance.eastInset, - super.getPreferredSize().height) - } - fun updateMainPanel() { modulesPanel.removeAll() initModulesPanel()