KTNB-395: Changes for IJ-MR-117926

(cherry picked from commit 6645d9a235e3af5b86a0d0f1dd1990f85068796f)

IJ-MR-117926

GitOrigin-RevId: 2b10ba82e37ee3b932b3409fab562ed9ea569d09
This commit is contained in:
Nikolay Egorov
2023-11-03 17:31:11 +00:00
committed by intellij-monorepo-bot
parent 75eb6655d6
commit 3e7d1533ee
2 changed files with 19 additions and 15 deletions
@@ -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<Color, Color?>
class NotebookAboveCellDelimiterPanel(val editor: Editor) : JPanel(GridBagLayout()) {
internal inner class ColoursChangeListenerAdapter(var isCodeCell: Boolean = false) {
private lateinit var currentColorsPalette: Pair<Color, Color?>
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<JPanel>,
) {
) {
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<AnAction>()
var isCodeCell = false
fun initialize(actions: Array<AnAction>, 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)
)
}
}
@@ -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()
}