Arbitrary colors management

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Arbitrary colors management

Postby beta-decay » Tue May 28, 2013 5:48 pm

Is it possible, using SyntaxConstants.SYNTAX_STYLE_NONE to liven the document up a bit, changing color/background for an arbitrary piece of text withing the pane?
beta-decay
 
Posts: 3
Joined: Tue May 28, 2013 5:14 pm

Re: Arbitrary colors management

Postby robert » Tue May 28, 2013 10:58 pm

Not using the mechanisms RSTA uses to syntax highlight text, but you can simulate background colors by using the standard Swing Highlighter class. For example:

java code:

DefaultHighlighter.DefaultHighlightPainter myHighlightPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 240, 240));
textArea.getHighlighter().addHighlight(startOffs, endOffs, myHighlightPainter);
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Arbitrary colors management

Postby beta-decay » Wed May 29, 2013 8:44 am

Sweet, thanks!

Is there a way to retrieve this information back from textArea? I mean which parts of text are which color.
And is there such a mechanism for modifying text color? That's the thing I'm most interested in...
beta-decay
 
Posts: 3
Joined: Tue May 28, 2013 5:14 pm

Re: Arbitrary colors management

Postby robert » Wed May 29, 2013 12:36 pm

If you don't keep track of the information yourself, you have to use textArea.getHighlighter().getHighlights() to see what is rendered with a Highlight.

You can't change the foreground color used for specific regions of text without writing your own TokenMaker class. This is because RSyntaxTextArea is built on JTextArea, which doesn't support multiple fonts or colors. RSTA adds this ability by providing its own View implementation, but that View only grabs font & color information from the current TokenMaker.
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm

Re: Arbitrary colors management

Postby beta-decay » Wed May 29, 2013 10:04 pm

Thank you, I'll look into these classes. Also, I saw here and there on the forum mentions of possibly implementing an on-the-fly method of adding tokens to the current TokenMarker. As I understand, this has not yet happened?
beta-decay
 
Posts: 3
Joined: Tue May 28, 2013 5:14 pm

Re: Arbitrary colors management

Postby robert » Fri May 31, 2013 1:00 pm

That's correct, that is not currently possible, and it is not currently a priority.
User avatar
robert
 
Posts: 788
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron