by Christian » Tue Apr 20, 2010 9:01 am
No problem. I just wanted to implement a feature as you can see it in eclipse selecting a text and the text is highlighted wherever it is written in the field.
I just added a KeyListener for reacting on selections via keyboard and a MouseListener to react on selections made per mouse. If an event occures I call the following code:
- Code: Select all
if(this.markAllOccurences) {
final int start = this.textArea.getSelectionStart();
final int ende = this.textArea.getSelectionEnd();
final int carPos = this.textArea.getCaretPosition();
final String text = this.textArea.getSelectedText();
if(text != null && text.length() > 0) {
if(this.textArea.markAll(text, true, false, false) == 1) {
this.textArea.clearMarkAllHighlights();
}
if(carPos == ende) {
this.textArea.setSelectionStart(start);
this.textArea.setSelectionEnd(ende);
} else { //for selection via keyboard press shift + arrow left
this.textArea.setSelectionStart(ende);
this.textArea.setSelectionEnd(start);
this.textArea.moveCaretPosition(start);
}
} else {
this.textArea.clearMarkAllHighlights();
}
}
And it works. Then I saw that the RSTA has a method setMarkOccurrences(boolean). I thought it was what I wanted to have but now I think I've found out, that this just highlights Token when the caret is on a special position. I'm not sure, whether to use this feature from RSTA because it seems not to work in some languages.
I hope now it is clear what I wanted

No problem. I just wanted to implement a feature as you can see it in eclipse selecting a text and the text is highlighted wherever it is written in the field.
I just added a KeyListener for reacting on selections via keyboard and a MouseListener to react on selections made per mouse. If an event occures I call the following code:
[code]
if(this.markAllOccurences) {
final int start = this.textArea.getSelectionStart();
final int ende = this.textArea.getSelectionEnd();
final int carPos = this.textArea.getCaretPosition();
final String text = this.textArea.getSelectedText();
if(text != null && text.length() > 0) {
if(this.textArea.markAll(text, true, false, false) == 1) {
this.textArea.clearMarkAllHighlights();
}
if(carPos == ende) {
this.textArea.setSelectionStart(start);
this.textArea.setSelectionEnd(ende);
} else { //for selection via keyboard press shift + arrow left
this.textArea.setSelectionStart(ende);
this.textArea.setSelectionEnd(start);
this.textArea.moveCaretPosition(start);
}
} else {
this.textArea.clearMarkAllHighlights();
}
}
[/code]
And it works. Then I saw that the RSTA has a method setMarkOccurrences(boolean). I thought it was what I wanted to have but now I think I've found out, that this just highlights Token when the caret is on a special position. I'm not sure, whether to use this feature from RSTA because it seems not to work in some languages.
I hope now it is clear what I wanted ;)