public void actionPerformed(ActionEvent e) {
JTextComponent target = getTextComponent(e);
if (target != null) {
int offs = target.getCaretPosition();
boolean failed = false;
int oldOffs = offs;
Element curPara =
Utilities.getParagraphElement(target, offs);
try {
offs = Utilities.getNextWord(target, offs);
if(offs >= curPara.getEndOffset() &&
oldOffs != curPara.getEndOffset() - 1) {
// we should first move to the end of current
// paragraph (bug #4278839)
offs = curPara.getEndOffset() - 1;
}
} catch (BadLocationException bl) {
int end = target.getDocument().getLength();
if (offs != end) {
if(oldOffs != curPara.getEndOffset() - 1) {
offs = curPara.getEndOffset() - 1;
} else {
offs = end;
}
}
else {
failed = true;
}
}
if (!failed) {
if (select) {
target.moveCaretPosition(offs);
} else {
target.setCaretPosition(offs);
}
}
else {
UIManager.getLookAndFeel().provideErrorFeedback(target);
}
}
}
The operation to perform when this action is triggered. |