/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
JTextComponent text = (textPane != null) ? textPane : getTextComponent(e);
String currentSearch = JOptionPane.showInputDialog(
text.getParent(),
GT._("String to find"),
(search == null) ? lastSearch : search);
if ((currentSearch == null) || ("".equals(currentSearch.trim()))) {
return;
}
lastSearch = currentSearch;
String textPattern = "";
char firstChar = lastSearch.charAt(0);
if (Character.isLetter(firstChar)) {
textPattern =
"[" + Character.toUpperCase(firstChar) + Character.toLowerCase(firstChar) + "]" +
Pattern.quote(lastSearch.substring(1));
} else {
textPattern = Pattern.quote(lastSearch);
}
Pattern pattern = Pattern.compile(textPattern);
Matcher matcher = pattern.matcher(text.getText());
if (matcher.find(text.getCaretPosition())) {
text.setCaretPosition(matcher.start());
text.moveCaretPosition(matcher.end());
text.requestFocus();
return;
}
if (matcher.find(0)) {
text.setCaretPosition(matcher.start());
text.moveCaretPosition(matcher.end());
text.requestFocus();
return;
}
}