Example usage for javafx.scene.control IndexRange getEnd

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

Introduction

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

Prototype

public int getEnd() 

Source Link

Document

Returns the end position of the range (exclusive).

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 ww  w  . j av  a 2s  .  c o  m
        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);
    }
}