Example usage for javafx.scene.control IndexRange getStart

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

Introduction

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

Prototype

public int getStart() 

Source Link

Document

Returns the start position 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 {/*from w  w w  .  j ava  2s  . 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);
    }
}