Skip to content

Commit 60c53bd

Browse files
committed
Update to Flowless 0.4 and ReactFX 2.0-M2.
1 parent b9eea16 commit 60c53bd

File tree

5 files changed

+48
-28
lines changed

5 files changed

+48
-28
lines changed

richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/JavaKeywordsAsync.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.fxmisc.richtext.StyleSpans;
2121
import org.fxmisc.richtext.StyleSpansBuilder;
2222
import org.reactfx.EventStream;
23+
import org.reactfx.util.Try;
2324

2425
public class JavaKeywordsAsync extends Application {
2526

@@ -89,6 +90,7 @@ public void start(Stage primaryStage) {
8990
.successionEnds(Duration.ofMillis(500))
9091
.supplyTask(this::computeHighlightingAsync)
9192
.awaitLatest(textChanges)
93+
.map(Try::get)
9294
.subscribe(this::applyHighlighting);
9395
codeArea.replaceText(0, 0, sampleCode);
9496

richtextfx/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ apply plugin: 'signing'
44
group = 'org.fxmisc.richtext'
55

66
dependencies {
7-
compile group: 'org.reactfx', name: 'reactfx', version: '[1.4,1.5)'
8-
compile group: 'org.fxmisc.undo', name: 'undofx', version: '[1.0.1,)'
7+
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M2u1'
8+
compile group: 'org.fxmisc.undo', name: 'undofx', version: '[1.1,)'
99
compile group: 'org.fxmisc.easybind', name: 'easybind', version: '[1.0.3,)'
10-
compile group: 'org.fxmisc.flowless', name: 'flowless', version: '[0.3,)'
10+
compile group: 'org.fxmisc.flowless', name: 'flowless', version: '0.4'
1111
compile group: 'org.fxmisc.wellbehaved', name: 'wellbehavedfx', version: '[0.1,0.2)'
1212
testCompile group: 'junit', name: 'junit', version: '[4.0,)'
1313
}

richtextfx/src/main/java/org/fxmisc/richtext/EditableStyledDocument.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,22 @@ public ReadOnlyStyledDocument<S> snapshot() {
122122
public EventStream<RichTextChange<S>> richChanges() { return richChanges; }
123123

124124
{
125-
EventStream<String> removedText = EventStreams.zip(textChangePosition, textRemovalEnd).map((a, b) -> getText(a, b));
125+
EventStream<String> removedText = EventStreams.zip(textChangePosition, textRemovalEnd).map(t2 -> t2.map((a, b) -> getText(a, b)));
126126
EventStream<Integer> changePosition = EventStreams.merge(textChangePosition, styleChangePosition);
127127
EventStream<Integer> removalEnd = EventStreams.merge(textRemovalEnd, styleChangeEnd);
128-
EventStream<StyledDocument<S>> removedDocument = EventStreams.zip(changePosition, removalEnd).map((a, b) -> subSequence(a, b));
128+
EventStream<StyledDocument<S>> removedDocument = EventStreams.zip(changePosition, removalEnd).map(t2 -> t2.map((a, b) -> subSequence(a, b)));
129129
EventStream<Integer> insertionEnd = EventStreams.merge(
130-
changePosition.emitBothOnEach(insertionLength).map((start, len) -> start + len),
130+
changePosition.emitBothOnEach(insertionLength).map(t2 -> t2.map((start, len) -> start + len)),
131131
styleChangeEnd.emitOn(styleChangeDone));
132132
EventStream<StyledDocument<S>> insertedDocument = EventStreams.merge(
133133
this.insertedDocument,
134-
changePosition.emitBothOnEach(insertionEnd).map((a, b) -> subSequence(a, b)));
134+
changePosition.emitBothOnEach(insertionEnd).map(t2 -> t2.map((a, b) -> subSequence(a, b))));
135135

136136
plainTextChanges = EventStreams.zip(textChangePosition, removedText, insertedText)
137-
.map((pos, removed, inserted) -> new PlainTextChange(pos, removed, inserted));
137+
.map(t3 -> t3.map((pos, removed, inserted) -> new PlainTextChange(pos, removed, inserted)));
138138

139139
richChanges = EventStreams.zip(changePosition, removedDocument, insertedDocument)
140-
.map((pos, removed, inserted) -> new RichTextChange<S>(pos, removed, inserted));
140+
.map(t3 -> t3.map((pos, removed, inserted) -> new RichTextChange<S>(pos, removed, inserted)));
141141
}
142142

143143

richtextfx/src/main/java/org/fxmisc/richtext/skin/ParagraphBox.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import java.util.function.IntFunction;
99

1010
import javafx.beans.property.BooleanProperty;
11+
import javafx.beans.property.DoubleProperty;
1112
import javafx.beans.property.IntegerProperty;
1213
import javafx.beans.property.ObjectProperty;
1314
import javafx.beans.property.Property;
1415
import javafx.beans.property.SimpleBooleanProperty;
16+
import javafx.beans.property.SimpleDoubleProperty;
1517
import javafx.beans.property.SimpleIntegerProperty;
1618
import javafx.beans.property.SimpleObjectProperty;
1719
import javafx.geometry.Bounds;
@@ -46,6 +48,8 @@ public ObjectProperty<IntFunction<? extends Node>> graphicFactoryProperty() {
4648

4749
private final MonadicBinding<Node> graphic;
4850

51+
final DoubleProperty graphicOffset = new SimpleDoubleProperty(0.0);
52+
4953
private final BooleanProperty wrapText = new SimpleBooleanProperty(false);
5054
public BooleanProperty wrapTextProperty() { return wrapText; }
5155
{
@@ -57,10 +61,10 @@ public ObjectProperty<IntFunction<? extends Node>> graphicFactoryProperty() {
5761
public void setIndex(int index) { this.index.set(index); }
5862
public int getIndex() { return index.get(); }
5963

60-
public ParagraphBox(int index, Paragraph<S> par, BiConsumer<Text, S> applyStyle) {
64+
public ParagraphBox(Paragraph<S> par, BiConsumer<Text, S> applyStyle) {
6165
this.getStyleClass().add("paragraph-box");
6266
this.text = new ParagraphText<>(par, applyStyle);
63-
this.index = new SimpleIntegerProperty(index);
67+
this.index = new SimpleIntegerProperty(0);
6468
getChildren().add(text);
6569
graphic = EasyBind.combine(graphicFactory, this.index, (f, i) -> f != null ? f.apply(i.intValue()) : null);
6670
graphic.addListener((obs, oldG, newG) -> {
@@ -71,6 +75,14 @@ public ParagraphBox(int index, Paragraph<S> par, BiConsumer<Text, S> applyStyle)
7175
getChildren().add(newG);
7276
}
7377
});
78+
graphicOffset.addListener(obs -> requestLayout());
79+
}
80+
81+
@Override
82+
public String toString() {
83+
return graphic.isPresent()
84+
? "[#|" + text.getParagraph() + "]"
85+
: "[" + text.getParagraph() + "]";
7486
}
7587

7688
public Property<Boolean> caretVisibleProperty() { return text.caretVisibleProperty(); }
@@ -145,7 +157,7 @@ protected double computePrefWidth(double ignoredHeight) {
145157
Insets insets = getInsets();
146158
return wrapText.get()
147159
? 0 // return 0, VirtualFlow will size it to its width anyway
148-
: getGraphicWidth() + text.prefWidth(-1) + insets.getLeft() + insets.getRight();
160+
: getGraphicPrefWidth() + text.prefWidth(-1) + insets.getLeft() + insets.getRight();
149161
}
150162

151163
@Override
@@ -160,17 +172,21 @@ void layoutChildren() {
160172
Bounds bounds = getLayoutBounds();
161173
double w = bounds.getWidth();
162174
double h = bounds.getHeight();
163-
double layoutX = getLayoutX();
164-
double graphicWidth = getGraphicWidth();
175+
double graphicWidth = getGraphicPrefWidth();
176+
165177
text.resizeRelocate(graphicWidth, 0, w - graphicWidth, h);
166178

167179
graphic.ifPresent(g -> {
168-
g.resizeRelocate(-layoutX, 0, graphicWidth, h);
180+
g.resizeRelocate(graphicOffset.get(), 0, graphicWidth, h);
169181
});
170182
}
171183

172-
double getGraphicWidth() {
173-
return graphic.getOpt().map(g -> g.prefWidth(-1)).orElse(0.0);
184+
double getGraphicPrefWidth() {
185+
if(graphic.isPresent()) {
186+
return graphic.get().prefWidth(-1);
187+
} else {
188+
return 0.0;
189+
}
174190
}
175191

176192
/**

richtextfx/src/main/java/org/fxmisc/richtext/skin/StyledTextAreaVisual.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.fxmisc.easybind.monadic.MonadicObservableValue;
4141
import org.fxmisc.flowless.Cell;
4242
import org.fxmisc.flowless.VirtualFlow;
43+
import org.fxmisc.flowless.VirtualFlowHit;
4344
import org.fxmisc.richtext.MouseOverTextEvent;
4445
import org.fxmisc.richtext.Paragraph;
4546
import org.fxmisc.richtext.PopupAlignment;
@@ -139,11 +140,11 @@ public StyledTextAreaVisual(
139140
// Initialize content
140141
virtualFlow = VirtualFlow.createVertical(
141142
area.getParagraphs(),
142-
(index, par) -> {
143-
Cell<Paragraph<S>, ParagraphBox<S>> cell = createCell(index, par, applyStyle);
143+
par -> {
144+
Cell<Paragraph<S>, ParagraphBox<S>> cell = createCell(par, applyStyle);
144145
nonEmptyCells.add(cell.getNode());
145146
return cell.beforeReset(() -> nonEmptyCells.remove(cell.getNode()))
146-
.afterUpdateItem((i, p) -> nonEmptyCells.add(cell.getNode()));
147+
.afterUpdateItem(p -> nonEmptyCells.add(cell.getNode()));
147148
});
148149

149150
// initialize navigator
@@ -202,8 +203,8 @@ public StyledTextAreaVisual(
202203
EventStreams.valuesOf(area.popupAlignmentProperty()),
203204
EventStreams.valuesOf(popupAnchorAdjustment))
204205
.repeatOn(positionPopupImpulse)
205-
.filter((w, al, adj) -> w != null)
206-
.subscribe((w, al, adj) -> positionPopup(w, al, adj)));
206+
.filter(t3 -> t3.map((w, al, adj) -> w != null))
207+
.subscribe(t3 -> t3.exec((w, al, adj) -> positionPopup(w, al, adj))));
207208

208209
// dispatch MouseOverTextEvents when mouseOverTextDelay is not null
209210
EventStreams.valuesOf(area.mouseOverTextDelayProperty())
@@ -266,7 +267,7 @@ void followCaret() {
266267
int parIdx = area.getCurrentParagraph();
267268
Cell<Paragraph<S>, ParagraphBox<S>> cell = virtualFlow.getCell(parIdx);
268269
Bounds caretBounds = cell.getNode().getCaretBounds();
269-
double graphicWidth = cell.getNode().getGraphicWidth();
270+
double graphicWidth = cell.getNode().getGraphicPrefWidth();
270271
Bounds region = extendLeft(caretBounds, graphicWidth);
271272
virtualFlow.show(cell, region);
272273
}
@@ -311,7 +312,7 @@ int getInsertionIndex(double textX, Position targetLine) {
311312
}
312313

313314
int getInsertionIndex(double textX, double y) {
314-
VirtualFlow.HitInfo<Cell<Paragraph<S>, ParagraphBox<S>>> hit = virtualFlow.hit(y);
315+
VirtualFlowHit<Cell<Paragraph<S>, ParagraphBox<S>>> hit = virtualFlow.hit(y);
315316
if(hit.isBeforeCells()) {
316317
return 0;
317318
} else if(hit.isAfterCells()) {
@@ -352,16 +353,16 @@ Position position(int par, int line) {
352353
* ********************************************************************** */
353354

354355
private Cell<Paragraph<S>, ParagraphBox<S>> createCell(
355-
int index,
356356
Paragraph<S> paragraph,
357357
BiConsumer<Text, S> applyStyle) {
358358

359-
ParagraphBox<S> box = new ParagraphBox<>(index, paragraph, applyStyle);
359+
ParagraphBox<S> box = new ParagraphBox<>(paragraph, applyStyle);
360360

361361
box.highlightFillProperty().bind(highlightFill);
362362
box.highlightTextFillProperty().bind(highlightTextFill);
363363
box.wrapTextProperty().bind(area.wrapTextProperty());
364364
box.graphicFactoryProperty().bind(area.paragraphGraphicFactoryProperty());
365+
box.graphicOffset.bind(virtualFlow.breadthOffsetProperty());
365366

366367
BooleanBinding hasCaret = Bindings.equal(
367368
box.indexProperty(),
@@ -404,6 +405,7 @@ public void dispose() {
404405
box.highlightTextFillProperty().unbind();
405406
box.wrapTextProperty().unbind();
406407
box.graphicFactoryProperty().unbind();
408+
box.graphicOffset.unbind();
407409

408410
box.caretVisibleProperty().unbind();
409411
cellCaretVisible.dispose();
@@ -417,7 +419,7 @@ public void dispose() {
417419
}
418420

419421
private ParagraphBox<S> getCell(int index) {
420-
return virtualFlow.getCellIfVisible(index).get().getNode();
422+
return virtualFlow.getCell(index).getNode();
421423
}
422424

423425
private int getCellInsertionIndex(ParagraphBox<S> cell, double x, int line) {
@@ -477,7 +479,7 @@ private Optional<Bounds> getSelectionBoundsOnScreen() {
477479
return getCaretBoundsOnScreen();
478480
}
479481

480-
Bounds[] bounds = virtualFlow.visibleCells()
482+
Bounds[] bounds = virtualFlow.visibleCells().stream()
481483
.map(c -> c.getNode().getSelectionBoundsOnScreen())
482484
.filter(opt -> opt.isPresent())
483485
.map(opt -> opt.get())

0 commit comments

Comments
 (0)