box.highlightFillProperty().bind(highlightFill);
box.highlightTextFillProperty().bind(highlightTextFill);
box.wrapTextProperty().bind(area.wrapTextProperty());
box.graphicFactoryProperty().bind(area.paragraphGraphicFactoryProperty());
BooleanBinding hasCaret = Bindings.equal(
box.indexProperty(),
area.currentParagraphProperty());
// caret is visible only in the paragraph with the caret
BooleanBinding cellCaretVisible = hasCaret.and(caretVisible);
box.caretVisibleProperty().bind(cellCaretVisible);
// bind cell's caret position to area's caret column,
// when the cell is the one with the caret
org.fxmisc.easybind.Subscription caretPositionSub =
EasyBind.when(hasCaret).bind(
box.caretPositionProperty(),
area.caretColumnProperty());
// keep paragraph selection updated
ObjectBinding<IndexRange> cellSelection = Bindings.createObjectBinding(() -> {
int idx = box.getIndex();
return idx != -1
? area.getParagraphSelection(idx)
: StyledTextArea.EMPTY_RANGE;
}, area.selectionProperty(), box.indexProperty());
box.selectionProperty().bind(cellSelection);
return new Cell<Paragraph<S>, ParagraphBox<S>>() {
@Override
public ParagraphBox<S> getNode() {
return box;
}
@Override
public void updateIndex(int index) {
box.setIndex(index);
}
@Override
public void dispose() {
box.highlightFillProperty().unbind();
box.highlightTextFillProperty().unbind();
box.wrapTextProperty().unbind();
box.graphicFactoryProperty().unbind();
box.caretVisibleProperty().unbind();
cellCaretVisible.dispose();
hasCaret.dispose();
caretPositionSub.unsubscribe();
box.selectionProperty().unbind();
cellSelection.dispose();