From ba0894985b18737c5a44c3fff6d0fab4f7e509ce Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 10 May 2016 09:00:16 -0700 Subject: [PATCH] Removed AreaFactory The class' purposes: - clone StyledTextArea or one of its three subclasses (no longer needed due to EditableStyledDocument now being public as an interface) - add scroll bars by embedding the area into a VirtualizedScrollPane (more of a convenience method than anything else) Cloning is no longer needed. Embedding it had an annoying leads-to-more-boilerplate issue: one couldn't modify the area before it was embedded into the pane. So, it seemed simpler to remove this class entirely and just tell developers to embed the area in their own code. --- .../org/fxmisc/richtext/demo/CloneDemo.java | 5 +- .../richtext/demo/richtext/RichText.java | 7 +- .../java/org/fxmisc/richtext/AreaFactory.java | 206 ------------------ .../org/fxmisc/richtext/StyledTextArea.java | 17 +- 4 files changed, 18 insertions(+), 217 deletions(-) delete mode 100644 richtextfx/src/main/java/org/fxmisc/richtext/AreaFactory.java diff --git a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/CloneDemo.java b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/CloneDemo.java index f375786a1..b3eb7df3c 100644 --- a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/CloneDemo.java +++ b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/CloneDemo.java @@ -8,7 +8,6 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; -import org.fxmisc.richtext.AreaFactory; import org.fxmisc.richtext.InlineCssTextArea; public class CloneDemo extends Application { @@ -22,8 +21,8 @@ public void start(Stage primaryStage) { String selectedText = "selection"; String text = "Edit the top area (original)\nand watch the (clone) bottom area's displayed text change and its " + "selected text [" + selectedText + "] update itself accordingly."; - InlineCssTextArea area = AreaFactory.inlineCssTextArea(text); - InlineCssTextArea clone = AreaFactory.cloneInlineCssTextArea(area); + InlineCssTextArea area = new InlineCssTextArea(text); + InlineCssTextArea clone = new InlineCssTextArea(area.getContent()); VBox vbox = new VBox(area, clone); vbox.setSpacing(10); diff --git a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/RichText.java b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/RichText.java index 9e1041828..71f775e7a 100644 --- a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/RichText.java +++ b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/RichText.java @@ -34,7 +34,6 @@ import javafx.stage.Stage; import org.fxmisc.flowless.VirtualizedScrollPane; -import org.fxmisc.richtext.AreaFactory; import org.fxmisc.richtext.Paragraph; import org.fxmisc.richtext.StyleSpans; import org.fxmisc.richtext.StyledTextArea; @@ -46,10 +45,8 @@ public static void main(String[] args) { launch(args); } - private final StyledTextArea area = - AreaFactory.styledTextArea( - ParStyle.EMPTY, - ( paragraph, style) -> paragraph.setStyle(style.toCss()), + private final StyledTextArea area = new StyledTextArea<>( + ParStyle.EMPTY, ( paragraph, style) -> paragraph.setStyle(style.toCss()), TextStyle.EMPTY.updateFontSize(12).updateFontFamily("Serif").updateTextColor(Color.BLACK), ( text, style) -> text.setStyle(style.toCss())); { diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/AreaFactory.java b/richtextfx/src/main/java/org/fxmisc/richtext/AreaFactory.java deleted file mode 100644 index e07fe3f83..000000000 --- a/richtextfx/src/main/java/org/fxmisc/richtext/AreaFactory.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.fxmisc.richtext; - -import javafx.scene.text.TextFlow; -import org.fxmisc.flowless.VirtualizedScrollPane; - -import java.util.function.BiConsumer; - -/** - * AreaFactory is a convenience class used to create StyledTextArea - * and any of its subclasses. and optionally embed them - * into a {@link VirtualizedScrollPane}. - * - */ -public class AreaFactory { - - /* ********************************************************************** * - * * - * StyledTextArea * - * * - * ********************************************************************** */ - - // StyledTextArea 1 - public static StyledTextArea styledTextArea( - PS initialParagraphStyle, BiConsumer applyParagraphStyle, - S initialTextStyle, BiConsumer applyStyle - ) { - return new StyledTextArea<>( - initialParagraphStyle, applyParagraphStyle, - initialTextStyle, applyStyle, - true); - } - - // Embeds StyledTextArea 1 - public static VirtualizedScrollPane> embeddedStyledTextArea( - PS initialParagraphStyle, BiConsumer applyParagraphStyle, - S initialTextStyle, BiConsumer applyStyle - ) { - return new VirtualizedScrollPane<>(styledTextArea(initialParagraphStyle, applyParagraphStyle, initialTextStyle, applyStyle)); - } - - // StyledTextArea 2 - public static StyledTextArea styledTextArea( - PS initialParagraphStyle, BiConsumer applyParagraphStyle, - S initialTextStyle, BiConsumer applyStyle, - boolean preserveStyle - ) { - return new StyledTextArea<>( - initialParagraphStyle, applyParagraphStyle, - initialTextStyle, applyStyle, - preserveStyle); - } - - // Embeds StyledTextArea 2 - public static VirtualizedScrollPane> embeddedStyledTextArea( - PS initialParagraphStyle, BiConsumer applyParagraphStyle, - S initialTextStyle, BiConsumer applyStyle, boolean preserveStyle - ) { - return new VirtualizedScrollPane<>(styledTextArea(initialParagraphStyle, applyParagraphStyle, initialTextStyle, applyStyle, preserveStyle)); - } - - // Clones StyledTextArea - public static StyledTextArea cloneStyleTextArea(StyledTextArea area) { - return new StyledTextArea<>(area.getInitialParagraphStyle(), area.getApplyParagraphStyle(), - area.getInitialTextStyle(), area.getApplyStyle(), - area.getContent(), area.isPreserveStyle()); - } - - // Embeds cloned StyledTextArea - public static VirtualizedScrollPane> embeddedClonedStyledTextArea(StyledTextArea area) { - return new VirtualizedScrollPane<>(cloneStyleTextArea(area)); - } - - // Embeds a cloned StyledTextArea from an embedded StyledTextArea - public static VirtualizedScrollPane> embeddedClonedStyledTextArea( - VirtualizedScrollPane> virtualizedScrollPaneWithArea - ) { - return embeddedClonedStyledTextArea(virtualizedScrollPaneWithArea.getContent()); - } - - /* ********************************************************************** * - * * - * StyleClassedTextArea * - * * - * ********************************************************************** */ - - // StyleClassedTextArea 1 - public static StyleClassedTextArea styleClassedTextArea(boolean preserveStyle) { - return new StyleClassedTextArea(preserveStyle); - } - - // Embeds StyleClassedTextArea 1 - public static VirtualizedScrollPane embeddedStyleClassedTextArea(boolean preserveStyle) { - return new VirtualizedScrollPane<>(styleClassedTextArea(preserveStyle)); - } - - // StyleClassedTextArea 2 - public static StyleClassedTextArea styleClassedTextArea() { - return styleClassedTextArea(true); - } - - // Embeds StyleClassedTextArea 2 - public static VirtualizedScrollPane embeddedStyleClassedTextArea() { - return new VirtualizedScrollPane<>(styleClassedTextArea()); - } - - // Clones StyleClassedTextArea - public static StyleClassedTextArea cloneStyleClassedTextArea(StyleClassedTextArea area) { - return new StyleClassedTextArea(area.getContent(), area.isPreserveStyle()); - } - - // Embeds cloned StyleClassedTextArea - public static VirtualizedScrollPane embeddedClonedStyleClassedTextArea(StyleClassedTextArea area) { - return new VirtualizedScrollPane<>(cloneStyleClassedTextArea(area)); - } - - // Embeds a cloned StyleClassedTextArea from an embedded StyleClassedTextArea - public static VirtualizedScrollPane embeddedClonedStyleClassedTextArea( - VirtualizedScrollPane virtualizedScrollPaneWithArea - ) { - return embeddedClonedStyleClassedTextArea(virtualizedScrollPaneWithArea.getContent()); - } - - /* ********************************************************************** * - * * - * CodeArea * - * * - * ********************************************************************** */ - - // CodeArea 1 - public static CodeArea codeArea() { - return new CodeArea(); - } - - // Embeds CodeArea 1 - public static VirtualizedScrollPane embeddedCodeArea() { - return new VirtualizedScrollPane<>(codeArea()); - } - - // CodeArea 2 - public static CodeArea codeArea(String text) { - return new CodeArea(text); - } - - // Embeds CodeArea 2 - public static VirtualizedScrollPane embeddedCodeArea(String text) { - return new VirtualizedScrollPane<>(codeArea(text)); - } - - // Clones CodeArea - public static CodeArea cloneCodeArea(CodeArea area) { - return new CodeArea(area.getContent()); - } - - // Embeds a cloned CodeArea - public static VirtualizedScrollPane embeddedClonedCodeArea(CodeArea area) { - return new VirtualizedScrollPane<>(cloneCodeArea(area)); - } - - // Embeds a cloned CodeArea from an embedded CodeArea - public static VirtualizedScrollPane embeddedClonedCodeArea(VirtualizedScrollPane virtualizedScrollPaneWithArea) { - return new VirtualizedScrollPane<>(cloneCodeArea(virtualizedScrollPaneWithArea.getContent())); - } - - /* ********************************************************************** * - * * - * InlineCssTextArea * - * * - * ********************************************************************** */ - - // InlineCssTextArea 1 - public static InlineCssTextArea inlineCssTextArea() { - return new InlineCssTextArea(); - } - - // Embeds InlineCssTextArea 1 - public static VirtualizedScrollPane embeddedInlineCssTextArea() { - return new VirtualizedScrollPane<>(inlineCssTextArea()); - } - - // InlineCssTextArea 2 - public static InlineCssTextArea inlineCssTextArea(String text) { - return new InlineCssTextArea(text); - } - - // Embeds InlineCssTextArea 2 - public static VirtualizedScrollPane embeddedInlineCssTextArea(String text) { - return new VirtualizedScrollPane<>(inlineCssTextArea(text)); - } - - // Clones InlineCssTextArea - public static InlineCssTextArea cloneInlineCssTextArea(InlineCssTextArea area) { - return new InlineCssTextArea(area.getContent()); - } - - // Embeds a cloned InlineCssTextArea - public static VirtualizedScrollPane embeddedClonedInlineCssTextArea(InlineCssTextArea area) { - return new VirtualizedScrollPane<>(cloneInlineCssTextArea(area)); - } - - // Embeds a cloned InlineCssTextArea from an embedded InlineCssTextArea - public static VirtualizedScrollPane embeddedClonedInlineCssTextArea( - VirtualizedScrollPane virtualizedScrollPaneWithArea - ) { - return new VirtualizedScrollPane<>(cloneInlineCssTextArea(virtualizedScrollPaneWithArea.getContent())); - } -} diff --git a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java index bb585e94e..7210fa473 100644 --- a/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java +++ b/richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java @@ -73,9 +73,20 @@ * style or style classes.

* *

Note: Scroll bars no longer appear when the content spans outside - * of the viewport. To add scroll bars, the area needs to be embedded in - * a {@link VirtualizedScrollPane}. {@link AreaFactory} is provided to make - * this more convenient.

+ * of the viewport. To add scroll bars, the area needs to be wrapped in + * a {@link VirtualizedScrollPane}. For example,

+ *
+ * {@code
+ * // shows area without scroll bars
+ * InlineCssTextArea area = new InlineCssTextArea();
+ *
+ * // add scroll bars that will display as needed
+ * VirtualizedScrollPane vsPane = new VirtualizedScrollPane(area);
+ *
+ * Parent parent = //;
+ * parent.getChildren().add(vsPane)
+ * }
+ * 
* *

Overriding keyboard shortcuts

*