Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Rename classes to compare alternative HTML rendering implementations

AuthorDaveJarvis <email>
Date2021-11-09 17:11:01 GMT-0800
Commit4c866cad81ff1333891b5153d4b93e666395ae0f
Parentbf2b611
Delta41 lines added, 36 lines removed, 5-line increase
src/main/java/com/keenwrite/processors/markdown/extensions/fences/FencedDivRenderer.java
}
- static class Factory implements @NotNull NodeRendererFactory {
+ static class Factory implements NodeRendererFactory {
@Override
public @NotNull NodeRenderer apply( @NotNull final DataHolder options ) {
src/main/java/com/keenwrite/preview/FlyingSaucerPanel.java
* Responsible for configuring FlyingSaucer's {@link XHTMLPanel}.
*/
-public final class FlyingSaucerPanel extends XHTMLPanel implements HtmlPanel {
+public final class FlyingSaucerPanel extends XHTMLPanel implements
+ HtmlRenderer {
/**
src/main/java/com/keenwrite/preview/HtmlPanel.java
-package com.keenwrite.preview;
-
-import org.w3c.dom.Document;
-
-import javax.swing.*;
-
-public interface HtmlPanel {
-
- /**
- * Renders an HTML document with respect to a base location.
- *
- * @param doc The document to render.
- * @param baseUri The document's relative URI.
- */
- void render( final Document doc, final String baseUri );
-
- /**
- * Scrolls the given {@link JScrollPane} to the first HTML element that
- * has an {@code id} attribute that matches the given identifier.
- *
- * @param id The HTML element identifier.
- * @param scrollPane The GUI widget that controls scrolling.
- */
- void scrollTo( final String id, final JScrollPane scrollPane );
-
- /**
- * Clears the cache (e.g., so that images are re-rendered using updated
- * dimensions).
- */
- void clearCache();
-}
src/main/java/com/keenwrite/preview/HtmlPreview.java
private final StringBuilder mDocument = new StringBuilder( 65536 );
- private HtmlPanel mPreview;
+ private HtmlRenderer mPreview;
private JScrollPane mScrollPane;
private String mBaseUriPath = "";
public void render( final String html ) {
final var doc = CONVERTER.fromJsoup( parse( decorate( html ) ) );
- doc.setDocumentURI( getBaseUri() );
+ final var uri = getBaseUri();
+ doc.setDocumentURI( uri );
- invokeLater( () -> mPreview.render( doc, getBaseUri() ) );
+ invokeLater( () -> mPreview.render( doc, uri ) );
fireDocumentChangedEvent( html );
src/main/java/com/keenwrite/preview/HtmlRenderer.java
+package com.keenwrite.preview;
+
+import org.w3c.dom.Document;
+
+import javax.swing.*;
+
+/**
+ * Denotes the ability to render an HTML document onto a Swing component.
+ */
+public interface HtmlRenderer {
+
+ /**
+ * Renders an HTML document with respect to a base location.
+ *
+ * @param doc The document to render.
+ * @param baseUri The document's relative URI.
+ */
+ void render( final Document doc, final String baseUri );
+
+ /**
+ * Scrolls the given {@link JScrollPane} to the first HTML element that
+ * has an {@code id} attribute that matches the given identifier.
+ *
+ * @param id The HTML element identifier.
+ * @param scrollPane The GUI widget that controls scrolling.
+ */
+ void scrollTo( final String id, final JScrollPane scrollPane );
+
+ /**
+ * Clears the cache (e.g., so that images are re-rendered using updated
+ * dimensions).
+ */
+ void clearCache();
+}