highlight several lines

Questions on using RSyntaxTextArea should go here.

Moderator: robert

highlight several lines

Postby tok » Fri Feb 06, 2009 4:44 pm

Hi,

I use RSyntaxTextArea in my own application. I'm very happy with it, but now I need to extend it.
I would like to highlight certain lines in the textarea (not syntax highlightning, but the entire lines). What is the recommended way to do this?

Further, it seems the SQL-Mode (i use only that mode) could be improved. The keyword "CREATE" is not highlighted. variables like xxx_yyy_zzz are not recognized as an entire word.

Cheers,
To
tok
 

Re: highlight several lines

Postby robert » Sat Feb 07, 2009 4:13 pm

There is currently no way to mark lines to highlight, but this can be added. I'll try to get it into the next release. I've added a tracker on SourceForge for this item.

As for SQL, I added the "create" keyword and modified it so "xxx_yyy_zzz" was correctly identified as a single identifier in Mark Occurrences (I assume this is what you were talking about?). You can get this in SVN release 75, or just wait for the next release.

Let me know if you find more issues with the SQL highlighter.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: highlight several lines

Postby robert » Tue Feb 10, 2009 9:20 pm

Follow-up questions:

What would you expect to happen if the user hit Enter in the middle of a highlighted line? Would the newly-created line not be highlighted (just the first line)?

It's easy to highlight a line, it's difficult to come up with a sensible way to manage that highlight if the user is allowed to manipulate the line (break it apart or remove it). If I had a use-case from you it might be easier to come up with something.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: highlight several lines

Postby tok » Sun Feb 15, 2009 3:03 pm

Sorry that i did not read the follow up question earlier.

In my application user input is disabled. I am using 2 RSyntaxTextAreas next to each other to realize a DIFF-Tool. I would like to be able to highlight any lines in any order programatically. An function like addHighlight(int linenumber) would be great.

You can take a look at it on http://www.tkibi.de/cms/index.php?page=db-scripter-en, the second screenshot.

Tobias
tok
 

Re: highlight several lines

Postby robert » Sun Feb 15, 2009 5:18 pm

Sounds good.

I've implemented line highlighting but haven't checked it in yet. The API is something like what you describe:

Code: Select all
textArea.addLineHighlight(int line, Color c)


This method returns a tag Object that you can use to later remove line highlights via

Code: Select all
textArea.removeLineHighlight(tag)


or

Code: Select all
textArea.removeAllLineHighlights()


This mimics the API of the Swing Highlighter class.

I'll post again when this gets added to SVN, hopefully in the next day or two.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: highlight several lines

Postby robert » Tue Feb 17, 2009 12:06 am

Check out revision 76 in SVN to check out the new line highlighting functionality. The API to use is exactly as described in my previous post. Let me know if you find any issues with it!
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: highlight several lines

Postby Guest » Fri Feb 20, 2009 6:33 pm

Hi Robert,

I tried it, but I see no highlightning. What was my mistake?

Code: Select all
   public void test() {
      textArea.setText("1\n2\n3");
      try {
         textArea.addLineHighlight(1, Color.yellow);
         textArea.addLineHighlight(2, Color.yellow);
         textArea.updateUI();
         
      } catch (BadLocationException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

Guest
 

Re: highlight several lines

Postby robert » Fri Feb 20, 2009 8:22 pm

Hmm, works for me. There's no need for the updateUI() call, by the way.

If you can send me a complete (short) demo program that reproduces the issue, I'll try running it locally and debug the problem.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: highlight several lines

Postby tok » Sat Feb 21, 2009 9:23 am

Ah, it works fine. My problem was a line in my code: setOpaque(false)
Thank you very much!
tok
 


Return to Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron