FW: [Advanced-java] Syntax Highlighting - using Swing - JTextPane

Randahl Fink Isaksen randahl at rockit.dk
Mon Mar 3 10:35:41 2003


That is interesting, Florian.


Is your document editable too?

If so, how do you keep track of the styles of partial changes? Let us
say the document contains XHTML for which we would like to highlight the
syntax. If the user enters the string "br" inside a "<p>" tag, we might
not want to highlight it, because he could be about to enter an ordinary
text sentence like "br eaking news!" However, if he puts a "<" in front
of the "br" and later enters a "/> after the "br" then the document
suddenly contains "<br/>" which we would like to highlight. How do you
handle such situations?


Randahl

-----Original Message-----
From: advanced-java-bounces@lists.xcf.berkeley.edu
[mailto:advanced-java-bounces@lists.xcf.berkeley.edu] On Behalf Of
Florian Roth
Sent: 3. marts 2003 11:13
To: advanced-java
Subject: RE: [Advanced-java] Syntax Highlighting - using Swing -
JTextPane

Hi

The way I did synatax highlighting was overwriting the insertString()
method
DefaultStyledDocument class. Then I set an own EditorKit whose
createDefaultDocument() method was returning an instance of my document
class.

for example like this:
JTextPane pane = new JTextPane();
pane.setEditorKit(new StyledEditorKit(){
   public Document createDefaultDocument(){
      //return the document
   }
});

In the documents insertString(String str, in offset, AttributeSet a)
method,
you can check the input and replace the AttributeSet by an own one
containing your properties. Hava a look in the docu for
javax.swing.text.StyleConstants.

Greets
Florian

_______________________________________________
Advanced-java mailing list
Advanced-java@lists.xcf.berkeley.edu
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java