public void highlightComments() {
try { // Highlight comments.
String s = this.getScriptArea().getText();
DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
this.getScriptArea().getHighlighter().removeAllHighlights();
boolean isComment = false;
int beginCommentIndex = Integer.MAX_VALUE;
int i;
for (i = 0; i < s.length(); i++) {
try {
if (s.substring(i, i + BEGIN_COMMENT.length()).equals(BEGIN_COMMENT)) {
if (!isComment) {
isComment = true;
beginCommentIndex = i;
i += BEGIN_COMMENT.length();
}
}
} catch (Exception e) {}
try {
if (s.substring(i, i + END_COMMENT.length()).equals(END_COMMENT)) {
isComment = false;
i += END_COMMENT.length();
try {
this.getScriptArea().getHighlighter().addHighlight(beginCommentIndex, i, painter);
} catch (BadLocationException e) {}
}
} catch (Exception e) {}
}
// Highlight ending.
if (isComment) {
try {
this.getScriptArea().getHighlighter().addHighlight(beginCommentIndex, i, painter);
} catch (BadLocationException e) {}
}
} catch (Exception e) {}
try { // Highlight declarations.
String s = this.getScriptArea().getText();
DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(new Color(240, 240, 240));
boolean isComment = false;
int beginCommentIndex = Integer.MAX_VALUE;
int i;