Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

JEditorPane

Thread view: 
Iyo - 15 Mar 2004 16:57 GMT
hi,
I was trying to create text editor with syntax highlighting.
I read that only JEditorPane can manage with different
text styles in one text field.

I have read documentation, but I cant understand which
classes are responsible for formating text.
I noticed Document,StyledDocument and DefaultStyledDocument classes,
but I dont know how to use those class to format text.
I was thinking about creating own class : SourceStyledDocument but it
would be very difficult, especially when I dont know how Document is
communicating with JEditorPane.

If anybody knows where can I read about JEditorPane, or know some good
tutorials, please reply.

I read:
http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
but there is nothing concrete.
Daniel Sjöblom - 17 Mar 2004 19:32 GMT
> hi,
> I was trying to create text editor with syntax highlighting.
[quoted text clipped - 15 lines]
> http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
> but there is nothing concrete.

Once upon a time, I also asked this question. In response, Fahd Shariff
 posted an example extension of SyntaxStyledDocument. You should look
up Simple/MutableAttributeSet and the setCharacterAttributes method in
JEditorPane. Basically, JEditorPane reads the attributes of a selected
set of characters and paints it accordingly. Any time text is inserted
into the document, you scan through the document and set the correct
attributes for specific syntactic elements. I can email you the source
if you are interested.

Ostermiller (I forget his first name, try google) has also implemented a
 syntax highlighting package, that uses some slightly different tactics
(painting and parsing is done in separate threads). The source is
available under GPL licensing I think.

The bad news is that the first option is terribly slow, and the second
looks a bit weird, and they both use generic swing components that are
not meant to be used for code editors. You are better off using some
component that is designed with syntax highlighting in mind. The old
JEdit component is fast and in the public domain, but it is no longer
maintained, so you will need to modify it to fit your needs.
Signature

Daniel Sjöblom
Remove _NOSPAM to reply by mail

Iyo - 17 Mar 2004 21:41 GMT
Uzytkownik "Daniel Sj?blom" <dsjoblom@mbnet.fi_NOSPAM> napisal w wiadomosci
news:40589afa$0$26136$7b6a8dc4@news.mbnet.fi...

> Once upon a time, I also asked this question. In response, Fahd Shariff
>   posted an example extension of SyntaxStyledDocument. You should look
[quoted text clipped - 4 lines]
> attributes for specific syntactic elements. I can email you the source
> if you are interested.
I'am interested. Pplease use this email address: iyo( at)o2.pl

I have started implementing other solution:
1. I have inherited my class SourceDocument from AbstractDocument.
2. I keep text in a list of javax.swing.text.Segment.
3. I have created simple structure:
   A) every SourceDocument has own rootElement which is subclass of Element
   B) rootElement contains list od SourceBlockElement which is subclass of
BranchElement,
       SourceBlockElement's are for example blocks and instructions
   C) SourceBlockElement can store other SourceBlockElement and
SourceLeafElement
   D) SourceLeafElement can be for example: keyword, numer,string ,
operator, etc
4. every leaf element is associated with part of text which is stored in
Segment
5. every leaf element have own Style -> MuttableAttributeSet
6. every SourceDocument have Syntax class which is responsible for
recognizing leaf and block elements

When user will update data I find leaf element (which have been changed) and
update it or create new leaf element.
So I dont have to parse all document, but only the right Element.
Particular Element shouldn't be longer than one line (50 characters).
I think this solution should work quite fast, and it dont require threads.

I have a lot of problems with make my Document compatible with
AbstractDocument :(
I cant deal with it.

> Ostermiller (I forget his first name, try google) has also implemented a
>   syntax highlighting package, that uses some slightly different tactics
> (painting and parsing is done in separate threads). The source is
> available under GPL licensing I think.

I thought about threads too, but I think solution i've just described is
more
elegant.

> The bad news is that the first option is terribly slow, and the second
> looks a bit weird, and they both use generic swing components that are
> not meant to be used for code editors. You are better off using some
> component that is designed with syntax highlighting in mind. The old
> JEdit component is fast and in the public domain, but it is no longer
> maintained, so you will need to modify it to fit your needs.

I'am starting my adventure with Java. I wanted to create code editor only
as exercise. So it isnt very important to me, but
thx for response.

Michal Piotrkowski
gipsy - 17 Mar 2004 21:17 GMT
> hi,
> I was trying to create text editor with syntax highlighting.
[quoted text clipped - 15 lines]
> http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html
> but there is nothing concrete.

This package is fast (but not free)
http://www.japisoft.com/syntaxcolor/
Thomas Weidenfeller - 18 Mar 2004 08:50 GMT
> hi,
> I was trying to create text editor with syntax highlighting.
> I read that only JEditorPane can manage with different
> text styles in one text field.

See the SwingSet2 demo which comes with your SDK. It contains an example
(used to display the source of the SwingSet demos from within the demo).

/Thomas
Hiran Chaudhuri - 22 Mar 2004 14:35 GMT
> hi,
> I was trying to create text editor with syntax highlighting.
> I read that only JEditorPane can manage with different
> text styles in one text field.

Have a look at
http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/index.html

Perhaps it helps you more than me. My focus was to introduce custom text
elements.

Hiran


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.