?
Solved

StyledDocument parsing mIRC codes to display mIRC styled messages

Posted on 2003-03-21
11
Medium Priority
?
371 Views
Last Modified: 2012-06-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.
0
Comment
Question by:glottis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8180491
*Much* easier to do this in a JEditorPane

editorPane.setContentType("text/html");
editorPane.append("<font color=\"red\">Warning!</font>");
0
 
LVL 2

Author Comment

by:glottis
ID: 8183350
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8183378
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:glottis
ID: 8183640
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
 
LVL 2

Author Comment

by:glottis
ID: 8183652
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
 
LVL 3

Expert Comment

by:wide_awake
ID: 8184378
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
 
LVL 2

Author Comment

by:glottis
ID: 8185571
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
 
LVL 3

Expert Comment

by:wide_awake
ID: 8186671
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
 
LVL 2

Author Comment

by:glottis
ID: 8190906
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
 

Expert Comment

by:modulo
ID: 8356031
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8365692
Saving this Q as a PAQ and refunding the points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question