• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

StyledDocument parsing mIRC codes to display mIRC styled messages

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.
0
glottis
Asked:
glottis
  • 5
  • 2
  • 2
  • +1
1 Solution
 
CEHJCommented:
*Much* easier to do this in a JEditorPane

editorPane.setContentType("text/html");
editorPane.append("<font color=\"red\">Warning!</font>");
0
 
glottisAuthor Commented:
i dont think that is going to help CEHJ

i do use JEditorPane.
and i insert new Styles in it.
ur method is way to long one, cause a line may be in different format, just simple word can be a different style.

aint there any DLL already made that i can use...

internet is such a big stack of hay... and information is the needle.
0
 
CEHJCommented:
Don't understand this i'm afraid:

>>ur method is way to long one, cause a line may be in different format, just simple word can be a different style.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
glottisAuthor Commented:
this is the current way i do...

public class IRCTextPane extends JTextPane {
 private DefaultStyledDocument doc;
 private boolean bold, under;
 
 public IRCTextPane() {
  setStyledDocument(doc = new DefaultStyledDocument());
 }
 
 protected void appendMessage(String message) {
  StyleContext styleContext = new StyleContext();
  Style style = styleContext.addStyle("Custom", null);
  int mLength = message.length();
  for (int i=0; i<mLength; i++) {
    char c = message.charAt(i);
    if (c == IRCUtility.BOLD_CHAR) {
      if (bold) StyleConstants.setBold(style, false);
      else StyleConstants.setBold(style, true);
      bold = !bold;
      continue;
    } else
    if (c == IRCUtility.UNDR_CHAR) {
     if (under) StyleConstants.setUnderline(style, false);
     else StyleConstants.setUnderline(style, true);
     under = !under;
     continue;
    } else
    ....
    and so on for other stuff like reverse, colouring
    ....
    } else addCharacter(c, style);
  } // end for
  addCharacter('\n', null);
 } // end appendMessage
 
 private void addCharacter(char c, Style style) {
  try {
   doc.insertString(doc.getLength(), c + "", style);
  } catch (BadLocationException e) { }
 } // end addCharacter
}

if u say i should use HTML then to insert a bold string <b>
then my message then un bold. </b>
also for colouring i hvae to insert a lot of strings. if one message contains 5 words which should be displayed in 5 different colours think how many <font> </font>s i have to insert.

Also i did take tis part first, but HTML formatting i didnt like that much. it didnt have that mIRC look in it.

my way does work, im only concerned on about the performance issue.

also in this IRCTextPane messages keep on coming, they dont stop.

so i will not be able to know when to insert </body></head>
0
 
glottisAuthor Commented:
would the performance increase if i override the paintComponent method... and donot call super.paintComponent untill and unless my entire String hasnot been parsed ?

when inserting the string to the document, it must be reapinting again and again ... might this help ?
0
 
wide_awakeCommented:
You might want to consider re-designing your parser.  It shouldn't take more than a few seconds to parse 64k of data.  

How many blocks are in your if/else/if/else/... section?

How many passes through the data does your parser make?

-Mark.
0
 
glottisAuthor Commented:
there are 4 if elses in one for loop.
the forth if contains two ifs
.

really not sure what htis means:
> How many passes through the data does your parser make?


0
 
wide_awakeCommented:
Sometimes it's possible to parse data by running through it just once, getting all info sequentially.  For other types of data, you need to know some details about the entire data set as a whole before it can be properly parsed, so you have to make multiple passes thru the data.

If you're just going through it once, then it's only 1 pass.  That's the most likely option, but it wouldn't explain why it's taking so long.  

Maybe you could try to insert print statements inside your loops to see where all the time is being spent.

-Mark.
0
 
glottisAuthor Commented:
beats me y it takes so long.

using styled document and appending String to it mite be the problem.

and i look into the SOPs
0
 
moduloCommented:
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/CleanUp/Q_20588987.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
moduloCommented:
Saving this Q as a PAQ and refunding the points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now