diff --git a/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookAboveCellDelimiterPanel.kt b/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookAboveCellDelimiterPanel.kt index 4156534cab53..4343c17a2f76 100644 --- a/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookAboveCellDelimiterPanel.kt +++ b/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookAboveCellDelimiterPanel.kt @@ -4,14 +4,18 @@ import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.project.ProjectManager +import com.intellij.uiDesigner.UIFormXmlConstants import java.awt.* import javax.swing.JComponent import javax.swing.JLayeredPane import javax.swing.JPanel +internal typealias BackgroundColorToCellRoofColor = Pair + class NotebookAboveCellDelimiterPanel(val editor: Editor) : JPanel(GridBagLayout()) { - internal inner class ColoursChangeListenerAdapter(var isCodeCell: Boolean = false) { - private lateinit var currentColorsPalette: Pair + + internal inner class ColorsChangeListenerAdapter { + private lateinit var currentColorsPalette: BackgroundColorToCellRoofColor private fun recreatePalette() { val newBackgroundColor = editor.colorsScheme.defaultBackground @@ -35,7 +39,7 @@ class NotebookAboveCellDelimiterPanel(val editor: Editor) : JPanel(GridBagLayout delimiterPanel: JPanel, codeRoofPanel: JPanel, cellBordersPanels: Iterable, - ) { + ) { if (::currentColorsPalette.isInitialized && backgroundColor == currentColorsPalette.first) return recreatePalette() @@ -46,14 +50,13 @@ class NotebookAboveCellDelimiterPanel(val editor: Editor) : JPanel(GridBagLayout } } - private val colorsChangeListenerAdapter = ColoursChangeListenerAdapter() + private val colorsChangeListenerAdapter = ColorsChangeListenerAdapter() val actions = ArrayList() var isCodeCell = false fun initialize(actions: Array, isCodeCell: Boolean) { this.actions.addAll(actions) this.isCodeCell = isCodeCell - colorsChangeListenerAdapter.isCodeCell = isCodeCell val backgroundColor = editor.colorsScheme.defaultBackground val cellRoofColor = if (isCodeCell) editor.notebookAppearance.getCodeCellBackground(editor.colorsScheme) else backgroundColor @@ -108,11 +111,12 @@ class NotebookAboveCellDelimiterPanel(val editor: Editor) : JPanel(GridBagLayout } } - addPropertyChangeListener("border") { + addPropertyChangeListener(UIFormXmlConstants.ELEMENT_FONT) { val newBackgroundColor = editor.colorsScheme.defaultBackground colorsChangeListenerAdapter.propertyChanged( newBackgroundColor, - delimiterPanel, codeRoofPanel, listOf(leftPanel, rightPanel)) + delimiterPanel, codeRoofPanel, listOf(leftPanel, rightPanel) + ) } } diff --git a/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookBelowCellDelimiterPanel.kt b/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookBelowCellDelimiterPanel.kt index 043763b5cb8f..1aee803a3f57 100644 --- a/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookBelowCellDelimiterPanel.kt +++ b/notebooks/notebook-ui/src/org/jetbrains/plugins/notebooks/ui/visualization/NotebookBelowCellDelimiterPanel.kt @@ -15,9 +15,8 @@ import javax.swing.JPanel import javax.swing.JProgressBar import kotlin.math.max -class NotebookBelowCellDelimiterPanel : JPanel(GridLayout(1, 1)) { +class NotebookBelowCellDelimiterPanel(val editor: EditorImpl) : JPanel(GridLayout(1, 1)) { private val steadyUI = JupyterProgressBarUI() - private lateinit var editor: EditorImpl private var shouldUseCustomBackground = false private val progress = object : JProgressBar(0, 100) { init { @@ -31,12 +30,11 @@ class NotebookBelowCellDelimiterPanel : JPanel(GridLayout(1, 1)) { } } - fun initialize(editor: EditorImpl, @Nls executionTimeDetails: String?, hasProgressBar: Boolean) { + fun initialize(@Nls executionTimeDetails: String?, hasProgressBar: Boolean) { val notebookAppearance = editor.notebookAppearance val customHeight = if (executionTimeDetails != null) notebookAppearance.EXECUTION_TIME_HEIGHT else notebookAppearance.SPACER_HEIGHT preferredSize = Dimension(preferredSize.width, customHeight) background = editor.colorsScheme.defaultBackground - this.editor = editor if (executionTimeDetails != null) { val label = JLabel(executionTimeDetails) @@ -59,10 +57,12 @@ class NotebookBelowCellDelimiterPanel : JPanel(GridLayout(1, 1)) { } override fun updateUI() { - if (::editor.isInitialized) { - background = if (shouldUseCustomBackground) - editor.notebookAppearance.getCodeCellBackground(editor.colorsScheme) - else editor.colorsScheme.defaultBackground + // This method is called within constructor of JPanel, at this time state is not yet initialised, reference is null. + if (editor != null) { + background = + if (shouldUseCustomBackground) + editor.notebookAppearance.getCodeCellBackground(editor.colorsScheme) + else editor.colorsScheme.defaultBackground } super.updateUI() }