From d2f680147d1b0ac9f64f59f4ff489488a402a769 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 26 Jun 2017 17:14:14 +0300 Subject: [PATCH] PY-24830 Intellij IDEA 2017 freeze on Macos 10.12.5 --- .../jetbrains/plugins/ipnb/IpnbJfxUtils.java | 32 +++++++++++-------- .../org/jetbrains/plugins/ipnb/IpnbUtils.java | 8 ++--- .../ipnb/editor/panels/IpnbMarkdownPanel.java | 4 +-- .../editor/panels/code/IpnbHtmlPanel.java | 2 +- .../editor/panels/code/IpnbLatexPanel.java | 2 +- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java index 170e5219e376..f883a6537cb2 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java @@ -3,6 +3,7 @@ package org.jetbrains.plugins.ipnb; import com.github.rjeschke.txtmark.Configuration; import com.github.rjeschke.txtmark.Processor; import com.intellij.ide.BrowserUtil; +import com.intellij.ide.IdeEventQueue; import com.intellij.ide.ui.LafManager; import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo; import com.intellij.openapi.application.ApplicationManager; @@ -11,10 +12,10 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.UIUtil; import com.jetbrains.python.PythonHelpersLocator; +import com.sun.javafx.application.PlatformImpl; import com.sun.javafx.webkit.Accessor; import com.sun.webkit.WebPage; import com.sun.webkit.graphics.WCSize; -import javafx.application.Platform; import javafx.concurrent.Worker; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; @@ -67,8 +68,12 @@ public class IpnbJfxUtils { private static final String ourPostfix = ""; private static URL ourStyleUrl; - public static JComponent createHtmlPanel(@NotNull final String source, int width, boolean repaint) { + private static void runFX(@NotNull Runnable r) { + IdeEventQueue.unsafeNonblockingExecute(r); + } + + public static JComponent createHtmlPanel(@NotNull final String source, int width) { final JFXPanel javafxPanel = new JFXPanel() { @Override protected void processMouseWheelEvent(MouseWheelEvent e) { @@ -77,7 +82,7 @@ public class IpnbJfxUtils { parent.dispatchEvent(parentEvent); } }; - Platform.runLater(() -> { + ApplicationManager.getApplication().invokeLater(() -> runFX(() -> PlatformImpl.runLater(() -> { final WebView webView = new WebView(); webView.setContextMenuEnabled(false); webView.setOnDragDetected(event -> { @@ -90,14 +95,14 @@ public class IpnbJfxUtils { engine.setOnStatusChanged(event -> { final String data = event.getData(); if (data != null && data.isEmpty()) { - adjustHeight(webView, javafxPanel, source, repaint); + adjustHeight(webView, javafxPanel, source); } }); } else { engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { if (newValue == Worker.State.SUCCEEDED) { - adjustHeight(webView, javafxPanel, source, repaint); + adjustHeight(webView, javafxPanel, source); } }); } @@ -117,7 +122,7 @@ public class IpnbJfxUtils { javafxPanel.setScene(scene); updateLaf(LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo, engine, javafxPanel); - }); + }))); return javafxPanel; } @@ -233,7 +238,7 @@ public class IpnbJfxUtils { } } - private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source, boolean repaintCallback) { + private static void adjustHeight(final WebView webView, final JFXPanel javafxPanel, String source) { final WebEngine engine = webView.getEngine(); final Document document = engine.getDocument(); if (document != null) { @@ -275,10 +280,11 @@ public class IpnbJfxUtils { final Dimension size = new Dimension( width, height + count * EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize()); - ApplicationManager.getApplication().invokeLater(()-> javafxPanel.setPreferredSize(size)); - if (repaintCallback) { - ApplicationManager.getApplication().invokeLater(()->javafxPanel.repaint()); - } + ApplicationManager.getApplication().invokeLater(()->{ + javafxPanel.setPreferredSize(size); + javafxPanel.revalidate(); + javafxPanel.repaint(); + }); } } } @@ -290,11 +296,11 @@ public class IpnbJfxUtils { } private static void updateLafDarcula(WebEngine engine, JFXPanel jfxPanel) { - Platform.runLater(() -> { + ApplicationManager.getApplication().invokeLater(() -> runFX(() -> PlatformImpl.runLater(() -> { ourStyleUrl = IpnbFileType.class.getResource("/style/javaFXBrowserDarcula.css"); engine.setUserStyleSheetLocation(ourStyleUrl.toExternalForm()); jfxPanel.getScene().getStylesheets().add(ourStyleUrl.toExternalForm()); engine.reload(); - }); + }))); } } diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java index fd9bf1dce075..396664b79be0 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/IpnbUtils.java @@ -23,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, boolean repaint) { - final JComponent panel = createHtmlPanel(source, width, repaint); + public static JComponent createLatexPane(@NotNull final String source, int width) { + final JComponent panel = createHtmlPanel(source, width); panel.addMouseListener(new MouseAdapter() { @Override @@ -52,9 +52,9 @@ public class IpnbUtils { return hasFx == 1; } - public static JComponent createHtmlPanel(@NotNull final String source, int width, boolean repaint) { + public static JComponent createHtmlPanel(@NotNull final String source, int width) { if (hasFx()) { - return IpnbJfxUtils.createHtmlPanel(source, width, repaint); + return IpnbJfxUtils.createHtmlPanel(source, width); } return createNonJfxPanel(source); } 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 e06f4d820fdb..6f98093631cb 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 @@ -36,13 +36,13 @@ public class IpnbMarkdownPanel extends IpnbEditablePanel { @Override protected JComponent createViewPanel() { final int width = myParent.getWidth(); - return IpnbUtils.createLatexPane(StringUtil.join(myCell.getHtmls(), ""), width, false); + return IpnbUtils.createLatexPane(StringUtil.join(myCell.getHtmls(), ""), width); } } 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 e988d2f3e4bb..ddecc70018c2 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, false); + return IpnbUtils.createLatexPane(StringUtil.join(myCell.getLatex(), ""), width); } }