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

Switched generic style objects order: paragraph comes before text (<S, PS> ==> <PS, S>) #246

Merged
merged 1 commit into from
Jan 25, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public static void main(String[] args) {
launch(args);
}

private final StyledTextArea<TextStyle, ParStyle> area =
AreaFactory.<TextStyle, ParStyle>styledTextArea(
TextStyle.EMPTY.updateFontSize(12).updateFontFamily("Serif").updateTextColor(Color.BLACK),
( text, style) -> text.setStyle(style.toCss()),
private final StyledTextArea<ParStyle, TextStyle> area =
AreaFactory.<ParStyle, TextStyle>styledTextArea(
ParStyle.EMPTY,
( paragraph, style) -> paragraph.setStyle(style.toCss()));
( paragraph, style) -> paragraph.setStyle(style.toCss()),
TextStyle.EMPTY.updateFontSize(12).updateFontFamily("Serif").updateTextColor(Color.BLACK),
( text, style) -> text.setStyle(style.toCss()));
{
area.setWrapText(true);
area.setStyleCodecs(TextStyle.CODEC, ParStyle.CODEC);
area.setStyleCodecs(ParStyle.CODEC, TextStyle.CODEC);
}

private final SuspendableNo updatingToolbar = new SuspendableNo();
Expand Down Expand Up @@ -150,7 +150,7 @@ protected boolean computeValue() {

int startPar = area.offsetToPosition(selection.getStart(), Forward).getMajor();
int endPar = area.offsetToPosition(selection.getEnd(), Backward).getMajor();
List<Paragraph<TextStyle, ParStyle>> pars = area.getParagraphs().subList(startPar, endPar + 1);
List<Paragraph<ParStyle, TextStyle>> pars = area.getParagraphs().subList(startPar, endPar + 1);

@SuppressWarnings("unchecked")
Optional<TextAlignment>[] alignments = pars.stream().map(p -> p.getParagraphStyle().alignment).distinct().toArray(Optional[]::new);
Expand Down Expand Up @@ -237,7 +237,7 @@ protected boolean computeValue() {
paragraphBackgroundPicker);
panel2.getChildren().addAll(sizeCombo, familyCombo, textColorPicker, backgroundColorPicker);

VirtualizedScrollPane<StyledTextArea<TextStyle, ParStyle>> vsPane = new VirtualizedScrollPane<>(area);
VirtualizedScrollPane<StyledTextArea<ParStyle, TextStyle>> vsPane = new VirtualizedScrollPane<>(area);
VBox vbox = new VBox();
VBox.setVgrow(vsPane, Priority.ALWAYS);
vbox.getChildren().addAll(panel1, panel2, vsPane);
Expand Down Expand Up @@ -331,7 +331,7 @@ private void updateParagraphStyleInSelection(Function<ParStyle, ParStyle> update
int startPar = area.offsetToPosition(selection.getStart(), Forward).getMajor();
int endPar = area.offsetToPosition(selection.getEnd(), Backward).getMajor();
for(int i = startPar; i <= endPar; ++i) {
Paragraph<TextStyle, ParStyle> paragraph = area.getParagraph(i);
Paragraph<ParStyle, TextStyle> paragraph = area.getParagraph(i);
area.setParagraphStyle(i, updater.apply(paragraph.getParagraphStyle()));
}
}
Expand Down
46 changes: 23 additions & 23 deletions richtextfx/src/main/java/org/fxmisc/richtext/AreaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,59 @@ public class AreaFactory {
* ********************************************************************** */

// StyledTextArea 1
public static <S, PS> StyledTextArea<S, PS> styledTextArea(
S initialStyle, BiConsumer<? super TextExt, S> applyStyle,
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle
public static <PS, S> StyledTextArea<PS, S> styledTextArea(
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialStyle, BiConsumer<? super TextExt, S> applyStyle
) {
return new StyledTextArea<S, PS>(
initialStyle, applyStyle,
return new StyledTextArea<PS, S>(
initialParagraphStyle, applyParagraphStyle,
initialStyle, applyStyle,
true);
}

// Embeds StyledTextArea 1
public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedStyledTextArea(
S initialStyle, BiConsumer<? super TextExt, S> applyStyle,
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle
public static <PS, S>VirtualizedScrollPane<StyledTextArea<PS, S>> embeddedStyledTextArea(
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialStyle, BiConsumer<? super TextExt, S> applyStyle
) {
return new VirtualizedScrollPane<>(styledTextArea(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle));
return new VirtualizedScrollPane<>(styledTextArea(initialParagraphStyle, applyParagraphStyle, initialStyle, applyStyle));
}

// StyledTextArea 2
public static <S, PS> StyledTextArea<S, PS> styledTextArea(
S initialStyle, BiConsumer<? super TextExt, S> applyStyle,
public static <PS, S> StyledTextArea<PS, S> styledTextArea(
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialStyle, BiConsumer<? super TextExt, S> applyStyle,
boolean preserveStyle
) {
return new StyledTextArea<S, PS>(
initialStyle, applyStyle,
return new StyledTextArea<PS, S>(
initialParagraphStyle, applyParagraphStyle,
initialStyle, applyStyle,
preserveStyle);
}

// Embeds StyledTextArea 2
public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedStyledTextArea(
S initialStyle, BiConsumer<? super TextExt, S> applyStyle,
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle, boolean preserveStyle
public static <PS, S>VirtualizedScrollPane<StyledTextArea<PS, S>> embeddedStyledTextArea(
PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle,
S initialStyle, BiConsumer<? super TextExt, S> applyStyle, boolean preserveStyle
) {
return new VirtualizedScrollPane<>(styledTextArea(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle, preserveStyle));
return new VirtualizedScrollPane<>(styledTextArea(initialParagraphStyle, applyParagraphStyle, initialStyle, applyStyle, preserveStyle));
}

// Clones StyledTextArea
public static <S, PS> StyledTextArea<S, PS> cloneStyleTextArea(StyledTextArea<S, PS> area) {
return new StyledTextArea<S, PS>(area.getInitialStyle(), area.getApplyStyle(),
area.getInitialParagraphStyle(), area.getApplyParagraphStyle(),
public static <PS, S> StyledTextArea<PS, S> cloneStyleTextArea(StyledTextArea<PS, S> area) {
return new StyledTextArea<PS, S>(area.getInitialParagraphStyle(), area.getApplyParagraphStyle(),
area.getInitialStyle(), area.getApplyStyle(),
area.getModel().getContent(), area.isPreserveStyle());
}

// Embeds cloned StyledTextArea
public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedClonedStyledTextArea(StyledTextArea<S, PS> area) {
public static <PS, S>VirtualizedScrollPane<StyledTextArea<PS, S>> embeddedClonedStyledTextArea(StyledTextArea<PS, S> area) {
return new VirtualizedScrollPane<>(cloneStyleTextArea(area));
}

// Embeds a cloned StyledTextArea from an embedded StyledTextArea
public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedClonedStyledTextArea(
VirtualizedScrollPane<StyledTextArea<S, PS>> virtualizedScrollPaneWithArea
public static <PS, S>VirtualizedScrollPane<StyledTextArea<PS, S>> embeddedClonedStyledTextArea(
VirtualizedScrollPane<StyledTextArea<PS, S>> virtualizedScrollPaneWithArea
) {
return embeddedClonedStyledTextArea(virtualizedScrollPaneWithArea.getContent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
/**
* Clipboard actions for {@link TextEditingArea}.
*/
public interface ClipboardActions<S, PS> extends EditActions<S, PS> {
public interface ClipboardActions<PS, S> extends EditActions<PS, S> {

Optional<Tuple2<Codec<S>, Codec<PS>>> getStyleCodecs();
Optional<Tuple2<Codec<PS>, Codec<S>>> getStyleCodecs();

/**
* Transfers the currently selected text to the clipboard,
Expand All @@ -45,9 +45,9 @@ default void copy() {
content.putString(getSelectedText());

getStyleCodecs().ifPresent(codecs -> {
Codec<StyledDocument<S, PS>> codec = ReadOnlyStyledDocument.codec(codecs._1, codecs._2);
Codec<StyledDocument<PS, S>> codec = ReadOnlyStyledDocument.codec(codecs._1, codecs._2);
DataFormat format = dataFormat(codec.getName());
StyledDocument<S, PS> doc = subDocument(selection.getStart(), selection.getEnd());
StyledDocument<PS, S> doc = subDocument(selection.getStart(), selection.getEnd());
ByteArrayOutputStream os = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(os);
try {
Expand All @@ -72,14 +72,14 @@ default void paste() {
Clipboard clipboard = Clipboard.getSystemClipboard();

if(getStyleCodecs().isPresent()) {
Tuple2<Codec<S>, Codec<PS>> codecs = getStyleCodecs().get();
Codec<StyledDocument<S, PS>> codec = ReadOnlyStyledDocument.codec(codecs._1, codecs._2);
Tuple2<Codec<PS>, Codec<S>> codecs = getStyleCodecs().get();
Codec<StyledDocument<PS, S>> codec = ReadOnlyStyledDocument.codec(codecs._1, codecs._2);
DataFormat format = dataFormat(codec.getName());
if(clipboard.hasContent(format)) {
byte[] bytes = (byte[]) clipboard.getContent(format);
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
DataInputStream dis = new DataInputStream(is);
StyledDocument<S, PS> doc = null;
StyledDocument<PS, S> doc = null;
try {
doc = codec.decode(dis);
} catch (IOException e) {
Expand Down
12 changes: 6 additions & 6 deletions richtextfx/src/main/java/org/fxmisc/richtext/EditActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Extended edit actions for {@link TextEditingArea}.
*/
public interface EditActions<S, PS> extends TextEditingArea<S, PS> {
public interface EditActions<PS, S> extends TextEditingArea<PS, S> {

/**
* Appends the given text to the end of the text content.
Expand All @@ -17,7 +17,7 @@ default void appendText(String text) {
/**
* Appends the given rich-text content to the end of this text-editing area.
*/
default void append(StyledDocument<S, PS> document) {
default void append(StyledDocument<PS, S> document) {
insert(getLength(), document);
}

Expand All @@ -37,7 +37,7 @@ default void insertText(int index, String text) {
* @param index The location to insert the text.
* @param document The rich-text content to insert.
*/
default void insert(int index, StyledDocument<S, PS> document) {
default void insert(int index, StyledDocument<PS, S> document) {
replace(index, index, document);
}

Expand Down Expand Up @@ -105,7 +105,7 @@ default void replaceText(String replacement) {
/**
* Replaces the entire content with the given rich-text content.
*/
default void replace(StyledDocument<S, PS> replacement) {
default void replace(StyledDocument<PS, S> replacement) {
replace(0, getLength(), replacement);
}

Expand All @@ -125,7 +125,7 @@ default void replaceSelection(String replacement) {
* caret position. If there was a selection, then the selection is cleared
* and the given replacement text is inserted.
*/
default void replaceSelection(StyledDocument<S, PS> replacement) {
default void replaceSelection(StyledDocument<PS, S> replacement) {
replace(getSelection(), replacement);
}

Expand All @@ -136,7 +136,7 @@ default void moveSelectedText(int pos) {
// no move, just position the caret
selectRange(pos, pos);
} else {
StyledDocument<S, PS> text = this.subDocument(sel.getStart(), sel.getEnd());
StyledDocument<PS, S> text = this.subDocument(sel.getStart(), sel.getEnd());
if(pos > sel.getEnd())
pos -= sel.getLength();
deleteText(sel);
Expand Down
Loading