Example usage for javafx.scene.control IndexRange getLength

List of usage examples for javafx.scene.control IndexRange getLength

Introduction

In this page you can find the example usage for javafx.scene.control IndexRange getLength.

Prototype

public int getLength() 

Source Link

Document

Returns the length of the range.

Usage

From source file:org.beryx.viewreka.fxapp.codearea.SimpleCodeArea.java

protected void applyTab() {
    IndexRange selection = getSelection();
    Position startPos = offsetToPosition(selection.getStart(), Bias.Forward);
    if (selection.getLength() == 0) {
        int spaceCount = tabAdvance - startPos.getMinor() % tabAdvance;
        replaceSelection(StringUtils.repeat(' ', spaceCount));
    } else {/*w w w. j a  v a  2 s . c om*/
        int startParagraph = startPos.getMajor();
        Position endPos = offsetToPosition(selection.getEnd(), Bias.Forward);
        int endParagraph = endPos.getMajor();
        String spaces = StringUtils.repeat(' ', tabAdvance);
        for (int pg = startParagraph; pg <= endParagraph; pg++) {
            insertText(position(pg, 0).toOffset(), spaces);
        }
        int newStartOffset = startPos.offsetBy(tabAdvance, Bias.Forward).toOffset();
        int newEndOffset = endPos.offsetBy(tabAdvance, Bias.Forward).toOffset();
        selectRange(newStartOffset, newEndOffset);
    }
}