StyledDocument parsing mIRC codes to display mIRC styled messages
Posted on 2003-03-21
I have made and application that can view mIRC created logs. At first what I did was simple use a JTextArea and load the *.log files into it.
Then to improve it I used a StyledDocument and a JEditorPane to parse the lines. Like i wanted the pane to display the lines as they are shown in mIRC window with all the correct formating of colors, bold, italic ... etc. In mIRC to write a text "this is a message" such that "is a" is in red color, "this" is in bold, and entire message is underline, you have to write this:
<ctrl+u><ctrl+b>this<ctrl+b> <ctrl+k>4is a<ctrl+k> message<ctrl+u>
The algorithm ive used is simple. parse one line character by character. the <ctrl> codes are of one character. if line.charAt(i) == UNDERLINE setStyle(underlineStyle) and so on.
This algo will work as long as the line of string is small. Everything is running also, parsing is done correctly also. The problem is that if the log file is huge with many lines say 10,000 characters, then through the use of this algorithm it takes a LONG time to do the work.
This is costing me very much in performance issue. One 64kb log file takes more than 5 minutes to display, and after that if i start to scroll the performance is degraded.
To improve what i did was first load the entrie file in a StringVector (custom made) line by line. then parse that line. this improved a little but not that much.
I wanted to know if there is a good option out there which can do this job, or if there is something like this done by someone.
mIRC takes a blink of a second to load that 64kb file. This i believe is due to it is using c++ language. so if i somehow learn to code like that in c++ and do a native with java.... any pointers appreciated.