|
-
Dec 8th, 2003, 12:21 PM
#1
Thread Starter
Addicted Member
syntax...
I am playing around with making a java editor with syntax highlighting. I got everything to work ok however, when the file gets very large, there is a major speed issue. Anyone have any ideas on how to optimize this? ( the current syntax highlighter is re-highlighting the entire file every time text is inserted or removed. )
To protect time is to protect everything...
-
Dec 8th, 2003, 01:51 PM
#2
Maybe a way to split the file in parts that can be independently reparsed. Then only reparse the part where the eit occurred.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 9th, 2003, 12:52 AM
#3
Dazed Member
How is the highlighting mechanism implemented? Do you have a file filled with predefined keywords that are matched to what the user types?
-
Dec 15th, 2003, 01:22 PM
#4
Thread Starter
Addicted Member
Its an interface, actually, with all the java keywords, and operators, created as static final strings. As the user types int the JTextPane, the text is inserted, and then the entire text is searched for occurences of the keywords, operators, comments, quotations, and so on... The only problem is that this process gets too slow once the file reaches larger sizes ( more than a couple of pages ). I thought of trying to make a separate thread to do the highlighting, but for some reason, it even slower then...
To protect time is to protect everything...
-
Dec 15th, 2003, 01:46 PM
#5
Are you searcing the whole text all the time? Or just the word that was just written? It can't take that much time to check the last word that was typed....
-
Dec 16th, 2003, 03:51 PM
#6
Dazed Member
I don't see why it would be necessary to check the whole file everytime a keyword is entered.
Why don't you try opening the file for RandomAccess and position the file pointer to where a word is being typed or retyped?
-
Dec 16th, 2003, 04:18 PM
#7
The other suggestions are good ones. Color only the current word, or my favorite, only the visible area.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Dec 17th, 2003, 10:49 AM
#8
Thread Starter
Addicted Member
Granted, highlighting only the line affected by the change would be the ideal thing. However, what about quotes and multi-line comments? Those two parts of highlighting affect more than one line, and therefore you wouldn't be able to only check the line of the change. I would love to incorporate a system to only check the visible text, but, I can't figure out how to do that. If you know, please share...
To protect time is to protect everything...
-
Dec 17th, 2003, 11:38 AM
#9
If you go by the swing.text model, your document is already divided into areas of coloring: string literals, comments, keywords etc. A whole tree.
Any change would just need to check the current area for changes, if it ends it etc.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|