Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make areas FXML ready via "@NamedArg(parameterName)" #466

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions richtextfx/src/main/java/org/fxmisc/richtext/CodeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import java.util.Collection;

import javafx.beans.NamedArg;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.StyledText;

Expand All @@ -23,7 +24,7 @@ public class CodeArea extends StyleClassedTextArea {
setUseInitialStyleForInsertion(true);
}

public CodeArea(EditableStyledDocument<Collection<String>, StyledText<Collection<String>>, Collection<String>> document) {
public CodeArea(@NamedArg("document") EditableStyledDocument<Collection<String>, StyledText<Collection<String>>, Collection<String>> document) {
super(document, false);
}

Expand All @@ -37,7 +38,7 @@ public CodeArea() {
*
* @param text Initial text content.
*/
public CodeArea(String text) {
public CodeArea(@NamedArg("text") String text) {
this();

appendText(text);
Expand Down
48 changes: 27 additions & 21 deletions richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.function.UnaryOperator;
import java.util.stream.Stream;

import javafx.beans.NamedArg;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding;
Expand Down Expand Up @@ -502,15 +503,20 @@ public Optional<Tuple2<Codec<PS>, Codec<SEG>>> getStyleCodecs() {
* @param nodeFactory A function which is used to create the JavaFX scene nodes for a
* particular segment.
*/
public GenericStyledArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle, TextOps<SEG, S> segmentOps,
Function<SEG, Node> nodeFactory) {
public GenericStyledArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("segmentOps") TextOps<SEG, S> segmentOps,
@NamedArg("nodeFactory") Function<SEG, Node> nodeFactory) {
this(initialParagraphStyle, applyParagraphStyle, initialTextStyle, segmentOps, true, nodeFactory);
}

public GenericStyledArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle, TextOps<SEG, S> segmentOps,
boolean preserveStyle, Function<SEG, Node> nodeFactory) {
public GenericStyledArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("segmentOps") TextOps<SEG, S> segmentOps,
@NamedArg("preserveStyle") boolean preserveStyle,
@NamedArg("nodeFactory") Function<SEG, Node> nodeFactory) {
this(initialParagraphStyle, applyParagraphStyle, initialTextStyle,
new GenericEditableStyledDocument<>(initialParagraphStyle, initialTextStyle, segmentOps), segmentOps, preserveStyle, nodeFactory);
}
Expand All @@ -521,30 +527,30 @@ public GenericStyledArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> appl
* shares the same {@link EditableStyledDocument}.
*/
public GenericStyledArea(
PS initialParagraphStyle,
BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle,
EditableStyledDocument<PS, SEG, S> document,
TextOps<SEG, S> textOps,
Function<SEG, Node> nodeFactory) {
this(initialParagraphStyle, applyParagraphStyle, initialTextStyle, document, textOps, true, nodeFactory);
@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("document") EditableStyledDocument<PS, SEG, S> document,
@NamedArg("segmentOps") TextOps<SEG, S> segmentOps,
@NamedArg("nodeFactory") Function<SEG, Node> nodeFactory) {
this(initialParagraphStyle, applyParagraphStyle, initialTextStyle, document, segmentOps, true, nodeFactory);

}

public GenericStyledArea(
PS initialParagraphStyle,
BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle,
EditableStyledDocument<PS, SEG, S> document,
TextOps<SEG, S> textOps,
boolean preserveStyle,
Function<SEG, Node> nodeFactory) {
@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("document") EditableStyledDocument<PS, SEG, S> document,
@NamedArg("segmentOps") TextOps<SEG, S> segmentOps,
@NamedArg("preserveStyle") boolean preserveStyle,
@NamedArg("nodeFactory") Function<SEG, Node> nodeFactory) {
this.initialTextStyle = initialTextStyle;
this.initialParagraphStyle = initialParagraphStyle;
this.preserveStyle = preserveStyle;
this.content = document;
this.applyParagraphStyle = applyParagraphStyle;
this.segmentOps = textOps;
this.segmentOps = segmentOps;

undoManager = preserveStyle
? createRichUndoManager(UndoManagerFactory.unlimitedHistoryFactory())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.fxmisc.richtext;


import javafx.beans.NamedArg;
import javafx.scene.text.TextFlow;

import org.fxmisc.richtext.model.Codec;
Expand All @@ -17,7 +18,7 @@ public InlineCssTextArea() {
this(new SimpleEditableStyledDocument<>("", ""));
}

public InlineCssTextArea(EditableStyledDocument<String, StyledText<String>, String> document) {
public InlineCssTextArea(@NamedArg("document") EditableStyledDocument<String, StyledText<String>, String> document) {
super(
"", TextFlow::setStyle,
"", TextExt::setStyle,
Expand All @@ -32,7 +33,7 @@ public InlineCssTextArea(EditableStyledDocument<String, StyledText<String>, Stri
*
* @param text Initial text content.
*/
public InlineCssTextArea(String text) {
public InlineCssTextArea(@NamedArg("text") String text) {
this();

replaceText(0, 0, text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Collections;

import javafx.beans.NamedArg;
import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.EditableStyledDocument;
import org.fxmisc.richtext.model.SimpleEditableStyledDocument;
Expand All @@ -13,7 +14,8 @@
*/
public class StyleClassedTextArea extends StyledTextArea<Collection<String>, Collection<String>> {

public StyleClassedTextArea(EditableStyledDocument<Collection<String>, StyledText<Collection<String>>, Collection<String>> document, boolean preserveStyle) {
public StyleClassedTextArea(@NamedArg("document") EditableStyledDocument<Collection<String>, StyledText<Collection<String>>, Collection<String>> document,
@NamedArg("preserveStyle") boolean preserveStyle) {
super(Collections.<String>emptyList(),
(paragraph, styleClasses) -> paragraph.getStyleClass().addAll(styleClasses),
Collections.<String>emptyList(),
Expand All @@ -26,7 +28,7 @@ public StyleClassedTextArea(EditableStyledDocument<Collection<String>, StyledTex
StyledText.codec(Codec.collectionCodec(Codec.STRING_CODEC))
);
}
public StyleClassedTextArea(boolean preserveStyle) {
public StyleClassedTextArea(@NamedArg("preserveStyle") boolean preserveStyle) {
this(
new SimpleEditableStyledDocument<>(
Collections.<String>emptyList(), Collections.<String>emptyList()
Expand Down
32 changes: 21 additions & 11 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.function.BiConsumer;

import javafx.beans.NamedArg;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.text.TextFlow;
Expand Down Expand Up @@ -61,25 +62,32 @@
*/
public class StyledTextArea<PS, S> extends GenericStyledArea<PS, StyledText<S>, S> {

public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle, BiConsumer<? super TextExt, S> applyStyle,
EditableStyledDocument<PS, StyledText<S>, S> document, boolean preserveStyle) {
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("document") EditableStyledDocument<PS, StyledText<S>, S> document,
@NamedArg("preserveStyle") boolean preserveStyle) {
super(initialParagraphStyle, applyParagraphStyle,
initialTextStyle,
document, StyledText.textOps(), preserveStyle,
seg -> createStyledTextNode(seg, StyledText.textOps(), applyStyle));
}

public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle, BiConsumer<? super TextExt, S> applyStyle,
EditableStyledDocument<PS, StyledText<S>, S> document) {
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("document") EditableStyledDocument<PS, StyledText<S>, S> document) {
this(initialParagraphStyle, applyParagraphStyle,
initialTextStyle, applyStyle, document, true);
}

public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle, BiConsumer<? super TextExt, S> applyStyle,
boolean preserveStyle) {
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle,
@NamedArg("preserveStyle") boolean preserveStyle) {
this(
initialParagraphStyle,
applyParagraphStyle,
Expand All @@ -89,8 +97,10 @@ public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyPa
preserveStyle);
}

public StyledTextArea(PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialTextStyle, BiConsumer<? super TextExt, S> applyStyle) {
public StyledTextArea(@NamedArg("initialParagraphStyle") PS initialParagraphStyle,
@NamedArg("applyParagraphStyle") BiConsumer<TextFlow, PS> applyParagraphStyle,
@NamedArg("initialTextStyle") S initialTextStyle,
@NamedArg("applyStyle") BiConsumer<? super TextExt, S> applyStyle) {
this(initialParagraphStyle, applyParagraphStyle,
initialTextStyle, applyStyle, true);
}
Expand Down