}
private class ScrollSelectionCallback implements Runnable {
@Override
public void run() {
TextArea textArea = (TextArea)getComponent();
int selectionStart = textArea.getSelectionStart();
int selectionLength = textArea.getSelectionLength();
int selectionEnd = selectionStart + selectionLength - 1;
switch (scrollDirection) {
case UP: {
// Get previous offset
int index = getNextInsertionPoint(mouseX, selectionStart, scrollDirection);
if (index != -1) {
textArea.setSelection(index, selectionEnd - index + 1);
scrollCharacterToVisible(index + 1);
}
break;
}
case DOWN: {
// Get next offset
int index = getNextInsertionPoint(mouseX, selectionEnd, scrollDirection);
if (index != -1) {
// If the next character is a paragraph terminator, increment
// the selection
if (index < textArea.getCharacterCount()
&& textArea.getCharacterAt(index) == '\n') {
index++;
}
textArea.setSelection(selectionStart, index - selectionStart);
scrollCharacterToVisible(index - 1);
}
break;
}