diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java index bf2516142124..170e5219e376 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java @@ -5,6 +5,7 @@ import com.github.rjeschke.txtmark.Processor; import com.intellij.ide.BrowserUtil; import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.util.text.StringUtil; @@ -66,7 +67,7 @@ public class IpnbJfxUtils { private static final String ourPostfix = ""; private static URL ourStyleUrl; - public static JComponent createHtmlPanel(@NotNull final String source, int width) { + public static JComponent createHtmlPanel(@NotNull final String source, int width, boolean repaint) { final JFXPanel javafxPanel = new JFXPanel() { @Override @@ -89,14 +90,14 @@ public class IpnbJfxUtils { engine.setOnStatusChanged(event -> { final String data = event.getData(); if (data != null && data.isEmpty()) { - adjustHeight(webView, javafxPanel, source); + adjustHeight(webView, javafxPanel, source, repaint); } }); } else { engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { if (newValue == Worker.State.SUCCEEDED) { - adjustHeight(webView, javafxPanel, source); + adjustHeight(webView, javafxPanel, source, repaint); } }); } @@ -232,7 +233,7 @@ public class IpnbJfxUtils { } } - private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source) { + private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source, boolean repaintCallback) { final WebEngine engine = webView.getEngine(); final Document document = engine.getDocument(); if (document != null) { @@ -273,8 +274,11 @@ public class IpnbJfxUtils { final Dimension size = new Dimension( width, height + count * EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize()); - javafxPanel.setPreferredSize(size); - javafxPanel.setMinimumSize(size); + + ApplicationManager.getApplication().invokeLater(()-> javafxPanel.setPreferredSize(size)); + if (repaintCallback) { + ApplicationManager.getApplication().invokeLater(()->javafxPanel.repaint()); + } } } } diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java index 6c93eee46568..fd9bf1dce075 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java @@ -10,7 +10,6 @@ import javafx.application.Platform; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.ipnb.editor.IpnbEditorUtil; -import org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel; import javax.swing.*; import java.awt.*; @@ -24,8 +23,8 @@ public class IpnbUtils { private static final Logger LOG = Logger.getInstance(IpnbUtils.class); private static int hasFx = 0; - public static JComponent createLatexPane(@NotNull final String source, int width, IpnbFilePanel parent) { - final JComponent panel = createHtmlPanel(source, width, parent); + public static JComponent createLatexPane(@NotNull final String source, int width, boolean repaint) { + final JComponent panel = createHtmlPanel(source, width, repaint); panel.addMouseListener(new MouseAdapter() { @Override @@ -53,9 +52,9 @@ public class IpnbUtils { return hasFx == 1; } - public static JComponent createHtmlPanel(@NotNull final String source, int width, IpnbFilePanel parent) { + public static JComponent createHtmlPanel(@NotNull final String source, int width, boolean repaint) { if (hasFx()) { - return IpnbJfxUtils.createHtmlPanel(source, width); + return IpnbJfxUtils.createHtmlPanel(source, width, repaint); } return createNonJfxPanel(source); } diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbRunAllCellsAction.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbRunAllCellsAction.java index 87f1a06d7911..aef347eac494 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbRunAllCellsAction.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/actions/IpnbRunAllCellsAction.java @@ -62,11 +62,8 @@ public class IpnbRunAllCellsAction extends IpnbRunCellBaseAction { private static void runCells(List cells, IpnbFilePanel ipnbFilePanel) { for (IpnbEditablePanel cell : cells) { cell.runCell(true); - ipnbFilePanel.revalidate(); - ipnbFilePanel.repaint(); - IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { - IdeFocusManager.getGlobalInstance().requestFocus(ipnbFilePanel, true); - }); + IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> + IdeFocusManager.getGlobalInstance().requestFocus(ipnbFilePanel, true)); } } diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java index 69b5c375979b..07ff5d6c3705 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java @@ -9,7 +9,6 @@ import com.intellij.ui.JBColor; import com.intellij.ui.OnePixelSplitter; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.ipnb.editor.IpnbEditorUtil; @@ -34,8 +33,8 @@ public abstract class IpnbEditablePanel { @@ -180,8 +178,7 @@ public abstract class IpnbEditablePanel { - revalidate(); - repaint(); - myParent.loaded(); - }, 100); + myParent.loaded(); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { IdeFocusManager.getGlobalInstance().requestFocus(this, true); }); @@ -610,7 +599,6 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D if (mySelectedCellPanel != null && e.getID() == KeyEvent.KEY_PRESSED) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { mySelectedCellPanel.switchToEditing(); - repaint(); } if (e.getKeyCode() == KeyEvent.VK_UP) { selectPrev(mySelectedCellPanel); @@ -692,17 +680,6 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D else { mySelectedCellPanel = null; mySelectedIndex = -1; - repaint(); - } - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - if (mySelectedCellPanel != null) { - g.setColor(mySelectedCellPanel.isEditing() ? JBColor.GREEN : JBColor.GRAY); - g.drawRoundRect(mySelectedCellPanel.getX() - 50, mySelectedCellPanel.getTop() - 1, - mySelectedCellPanel.getWidth() + 145 - IpnbEditorUtil.PROMPT_SIZE.width, mySelectedCellPanel.getHeight() + 2, 5, 5); } } @@ -714,7 +691,6 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { IdeFocusManager.getGlobalInstance().requestFocus(this, true); }); - repaint(); setSelectedCell(ipnbPanel, true); } } @@ -732,29 +708,15 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D if (ipnbPanel.equals(mySelectedCellPanel)) return; if (mySelectedCellPanel != null) { mySelectedCellPanel.setEditing(false); + mySelectedCellPanel.setBorder(BorderFactory.createLineBorder(IpnbEditorUtil.getBackground())); } + ipnbPanel.setBorder(BorderFactory.createLineBorder(ipnbPanel.isEditing() ? JBColor.GREEN : JBColor.GRAY)); + mySelectedCellPanel = ipnbPanel; mySelectedIndex = myIpnbPanels.indexOf(ipnbPanel); - myQueue.queue(new Update("Jupyter.Repaint", HIGH_PRIORITY) { - @Override - public void run() { - revalidate(); - repaint(); - if (ipnbPanel.getBounds().getHeight() != 0) { - myListener.selectionChanged(ipnbPanel, mouse); - } - } - }); - } - - public void revalidateAndRepaint() { - myQueue.queue(new Update("Jupyter.Repaint", HIGH_PRIORITY) { - @Override - public void run() { - revalidate(); - repaint(); - } - }); + if (ipnbPanel.getBounds().getHeight() != 0) { + myListener.selectionChanged(ipnbPanel, mouse); + } } @Nullable diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbMarkdownPanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbMarkdownPanel.java index a42f42d9cc4c..e06f4d820fdb 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbMarkdownPanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbMarkdownPanel.java @@ -3,10 +3,14 @@ package org.jetbrains.plugins.ipnb.editor.panels; import com.intellij.ui.KeyStrokeAdapter; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.ipnb.IpnbUtils; +import org.jetbrains.plugins.ipnb.editor.IpnbEditorUtil; import org.jetbrains.plugins.ipnb.format.cells.IpnbMarkdownCell; import javax.swing.*; +import java.awt.*; import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; public class IpnbMarkdownPanel extends IpnbEditablePanel { @@ -32,13 +36,32 @@ public class IpnbMarkdownPanel extends IpnbEditablePanel { myParent.getIpnbFilePanel().processKeyPressed(event); } }); + setBorder(BorderFactory.createLineBorder(IpnbEditorUtil.getBackground())); } @NotNull @@ -261,10 +262,6 @@ public class IpnbCodePanel extends IpnbEditablePanel { @Override public void switchToEditing() { setEditing(true); - final Container parent = getParent(); - if (parent != null) { - parent.repaint(); - } IdeFocusManager.findInstance().requestFocus(myCodeSourcePanel.getEditor().getContentComponent(), true); } @@ -306,7 +303,6 @@ public class IpnbCodePanel extends IpnbEditablePanel { myPromptLabel.setText(promptText); final IpnbFilePanel filePanel = myParent.getIpnbFilePanel(); setEditing(false); - filePanel.revalidateAndRepaint(); IdeFocusManager.findInstance().requestFocus(filePanel, true); if (mySelectNext) { filePanel.selectNext(this, true); @@ -342,8 +338,6 @@ public class IpnbCodePanel extends IpnbEditablePanel { addOutputPanel(component, outputContent, outputContent instanceof IpnbOutOutputCell); } } - final IpnbFilePanel filePanel = myParent.getIpnbFilePanel(); - filePanel.revalidateAndRepaint(); }, ModalityState.stateForComponent(this)); } @@ -352,10 +346,6 @@ public class IpnbCodePanel extends IpnbEditablePanel { myViewPanel.removeAll(); final JComponent panel = createViewPanel(); myViewPanel.add(panel); - - final IpnbFilePanel filePanel = myParent.getIpnbFilePanel(); - filePanel.revalidate(); - filePanel.repaint(); } @Override diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java index b72657b6d747..d09b1cf080fd 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java @@ -27,6 +27,7 @@ import com.intellij.openapi.editor.event.EditorMouseListener; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.reference.SoftReference; import com.intellij.ui.Gray; import com.intellij.ui.awt.RelativePoint; @@ -103,8 +104,7 @@ public class IpnbCodeSourcePanel extends IpnbPanel imp final Container parent = codePanel.getParent(); if (keyCode == KeyEvent.VK_ESCAPE && parent instanceof IpnbFilePanel) { getIpnbCodePanel().setEditing(false); - parent.repaint(); - UIUtil.requestFocus(getIpnbCodePanel().getFileEditor().getIpnbFilePanel()); + IdeFocusManager.getGlobalInstance().requestFocus(getIpnbCodePanel().getFileEditor().getIpnbFilePanel(), true); } } @@ -134,15 +134,9 @@ public class IpnbCodeSourcePanel extends IpnbPanel imp final int height = myEditor.getLineHeight() * Math.max(myEditor.getDocument().getLineCount(), 1) + 10; contentComponent.setPreferredSize(new Dimension(parent.getWidth() - 300, height)); panel.setPreferredSize(new Dimension(parent.getWidth() - 300, height)); - codePanel.revalidate(); - codePanel.repaint(); - panel.revalidate(); - panel.repaint(); if (parent instanceof IpnbFilePanel) { IpnbFilePanel ipnbFilePanel = (IpnbFilePanel)parent; - ipnbFilePanel.revalidate(); - ipnbFilePanel.repaint(); if (keyCode == KeyEvent.VK_ENTER && InputEvent.CTRL_MASK == e.getModifiers()) { IpnbRunCellBaseAction.runCell(ipnbFilePanel, false); } @@ -193,7 +187,6 @@ public class IpnbCodeSourcePanel extends IpnbPanel imp panel.setPreferredSize(new Dimension(parent.getWidth() - 300, height)); panel.revalidate(); panel.repaint(); - parent.repaint(); } } }); diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbHtmlPanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbHtmlPanel.java index 6a0157393748..e4d3925ff498 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbHtmlPanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbHtmlPanel.java @@ -19,6 +19,6 @@ public class IpnbHtmlPanel extends IpnbCodeOutputPanel { @Override protected JComponent createViewPanel() { final int width = myParent.getWidth(); - return IpnbUtils.createLatexPane(StringUtil.join(myCell.getHtmls(), ""), width, myParent); + return IpnbUtils.createLatexPane(StringUtil.join(myCell.getHtmls(), ""), width, false); } } diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbLatexPanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbLatexPanel.java index cca08303b575..e988d2f3e4bb 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbLatexPanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbLatexPanel.java @@ -23,6 +23,6 @@ public class IpnbLatexPanel extends IpnbCodeOutputPanel { @Override protected JComponent createViewPanel() { final int width = myParent.getWidth(); - return IpnbUtils.createLatexPane(StringUtil.join(myCell.getLatex(), ""), width, myParent); + return IpnbUtils.createLatexPane(StringUtil.join(myCell.getLatex(), ""), width, false); } }