The code below,
//I need help here....
public void processChangedL ines(int offset, int length) throws BadLocationExce ption {
String text = getText();
ResetColor();
Set<String> syntax = keywords.keySet ();
Color color ;Pattern p;Matcher m;
for (String keyword : syntax) {
color = keywords.get(ke yword);
p = Pattern.compile ("\\b" + keyword + "\\b");
m = p.matcher(text) ;
while(m.find()) {
StyleConstants. setForeground(s tyle,col);
setCharacterAtt ributes(m.start (),keyword.leng th(),style,fals e);
}
}
}
//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(s tyle,Color.blac k);
setCharacterAtt ributes(0,getLe ngth(),style,fa lse);
}
}
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..
//I need help here....
public void processChangedL ines(int offset, int length) throws BadLocationExce ption {
String text = getText();
ResetColor();
Set<String> syntax = keywords.keySet ();
Color color ;Pattern p;Matcher m;
for (String keyword : syntax) {
color = keywords.get(ke yword);
p = Pattern.compile ("\\b" + keyword + "\\b");
m = p.matcher(text) ;
while(m.find()) {
StyleConstants. setForeground(s tyle,col);
setCharacterAtt ributes(m.start (),keyword.leng th(),style,fals e);
}
}
}
//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(s tyle,Color.blac k);
setCharacterAtt ributes(0,getLe ngth(),style,fa lse);
}
}
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..
Comment