private static void adjustHeight()

in src/org/jetbrains/plugins/ipnb/IpnbJfxUtils.java [239:267]


  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) {
      final Element mydiv = document.getElementById("mydiv");
      if (mydiv != null) {
        try {
          Thread.sleep(renderingDelay);
        }
        catch (InterruptedException ignored) {
        }
        final Object heightObject = engine.executeScript("document.height");
        final int height = heightObject instanceof Integer ? (int)heightObject : 0;
        final Object widthObject = engine.executeScript("document.width");
        int width = widthObject instanceof Integer ? (int)widthObject : 0;
        if (width < javafxPanel.getWidth()) width = javafxPanel.getWidth();
        if (height <= 0 || width <= 0) return;
        int count = countNewLinesInMath(source);

        final Dimension size = new Dimension(width, height + count * EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize());

        ApplicationManager.getApplication().invokeLater(()->{
          javafxPanel.setPreferredSize(size);
          javafxPanel.revalidate();
          javafxPanel.repaint();
        });
      }
    }
  }