@Override
public boolean mouseMove(Component component, int x, int y) {
boolean consumed = super.mouseMove(component, x, y);
if (Mouse.getCapturer() == component) {
TextPane textPane = (TextPane)getComponent();
Bounds visibleArea = textPane.getVisibleArea();
visibleArea = new Bounds(visibleArea.x, visibleArea.y,
visibleArea.width, visibleArea.height);
if (y >= visibleArea.y
&& y < visibleArea.y + visibleArea.height) {
// Stop the scroll selection timer
if (scheduledScrollSelectionCallback != null) {
scheduledScrollSelectionCallback.cancel();
scheduledScrollSelectionCallback = null;
}
scrollDirection = null;
int offset = getInsertionPoint(x, y);
if (offset != -1) {
// Select the range
if (offset > anchor) {
textPane.setSelection(anchor, offset - anchor);
} else {
textPane.setSelection(offset, anchor - offset);
}
}
} else {
if (scheduledScrollSelectionCallback == null) {
scrollDirection = (y < visibleArea.y) ? TextPane.ScrollDirection.UP : TextPane.ScrollDirection.DOWN;