The code below,
//I need help here....
public void processChangedLines(int offset, int length) throws BadLocationException {
String text = getText();
ResetColor();
Set<String> syntax = keywords.keySet();
Color color ;Pattern p;Matcher m;
for (String keyword : syntax) {
color = keywords.get(keyword);
p = Pattern.compile("\\b" + keyword + "\\b");
m = p.matcher(text);
while(m.find()){
StyleConstants.setForeground(style,col);
setCharacterAttributes(m.start(),keyword.length(), style,false);
}
}
}
//I've tested the code below with all keywords in a line x 10000 lines (it is fast).... No problem here...
private void ResetColor(){
StyleConstants.setForeground(style,Color.black);
setCharacterAttributes(0,getLength(),style,false);
}
}
are the methods for coloring syntax, im currently doing my notepad that supports syntax highlighting...
I call that method when any key is pressed... " key events"
The method's performance will slow after 400 lines
I suspect the m = p.matcher(text); but i don't know the other alternatives for it....
Can anyone here advice me how to reimplement, optimize and/or give me some algorithms for that method's optimization?
Any reply will be appreciated...
A beginner, Sukatoa..