public void actionPerformed(ActionEvent e) {
JTextComponent target = getTextComponent(e);
if (target != null) {
int offs = target.getCaretPosition();
boolean failed = false;
try {
Element curPara =
Utilities.getParagraphElement(target, offs);
offs = Utilities.getPreviousWord(target, offs);
if(offs < curPara.getStartOffset()) {
// we should first move to the end of the
// previous paragraph (bug #4278839)
offs = Utilities.getParagraphElement(target, offs).
getEndOffset() - 1;
}
} catch (BadLocationException bl) {
if (offs != 0) {
offs = 0;
}
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. |