private @NotNull Dimension getPreferredSize(int minWidth, int maxWidth, int maxHeight) {
    Component view = getViewport().getView();
    Dimension paneSize;

    JScrollBar hBar = getHorizontalScrollBar();
    JScrollBar vBar = getVerticalScrollBar();
    int insetWidth = 0;
    if (view instanceof DocumentationEditorPane editorPane) {
      paneSize = editorPane.getPackedSize(minWidth, maxWidth);
    }
    else if (view instanceof JPanel panel) {
      Component[] components = panel.getComponents();
      Insets viewInsets = panel.getInsets();
      insetWidth = viewInsets.left + viewInsets.right;
      Dimension editorPaneSize = ((DocumentationEditorPane)components[0]).getPackedSize(minWidth, maxWidth);
      int locationLabelSizeHeight = components.length > 1 && panel.getComponents()[1].isVisible()
                                    ? panel.getComponents()[1].getPreferredSize().height
                                    : Math.max(JBUI.scale(getContentOuterPadding() - getSpaceAfterParagraph()), 0);
      paneSize = new Dimension(editorPaneSize.width + vBar.getPreferredSize().width + insetWidth,
                               editorPaneSize.height + locationLabelSizeHeight + viewInsets.top + viewInsets.bottom);
    }
    else {
      throw new IllegalStateException(view.getClass().getName());
    }
    boolean hasHBar = paneSize.width - vBar.getPreferredSize().width - insetWidth > maxWidth && hBar.isOpaque();
    int hBarHeight = hasHBar ? hBar.getPreferredSize().height : 0;

    boolean hasVBar = paneSize.height + hBarHeight > maxHeight && vBar.isOpaque();
    int vBarWidth = hasVBar ? vBar.getPreferredSize().width : 0;

    Insets insets = getInsets();
    int preferredWidth = paneSize.width + vBarWidth + insets.left + insets.right;
    int preferredHeight = paneSize.height + hBarHeight + insets.top + insets.bottom;
    return new Dimension(
      Math.min(preferredWidth, maxWidth),
      Math.min(preferredHeight, maxHeight)
    );
  }
private @NotNull Dimension getPreferredSize(int minWidth, int maxWidth, int maxHeight)