Eclipse Plug-in development question: background color

Having trouble installing Oxygen? Got a bug to report? Post it all here.
barryodriscoll
Posts: 2
Joined: Mon Mar 07, 2005 3:13 pm

Eclipse Plug-in development question: background color

Post by barryodriscoll »

I'm not sure if this is the right place to be asking this sort of question but I've tried on the eclipse.org newsgroups and I got no reply and seeing as the oxygen developers must have encountered a similar problem in developing their plug in I thought I'd try and ask.

As my final year project in my computer science degree I am developing an eclipse plug in. My plug-in is going to be a tool for helping in program comprehension. Instead of actively assisting the programmer in the job of reading source code my plug-in will first ask the programmer what the context of his current maintenance project and
then record any edits he makes to the file. This mapping will then be stored for future developers who are working on a similar maintenance project and can use the mapping to get a start up in trying to read the code. Its sorta like the comments you can attach to changes in a CVS repository but with more functionality and imbedded in the IDE.

I'm having difficulty trying to figure out how to change the background color of certain lines in the java editor so that I can tell the programmer which lines were changed in relation to a certain maintenance task. I was hoping you might be able to help me out with a few suggestions of classes to look at in eclipse or if its even possible to alter the background color of the eclipse java editor.


The classes I've found in the api which seem to point in the right direction are Painter or SytledText. StyledText has a setBackground method but it doesn't appear to be something you can apply to the current source editor. IPainter can be constructed on ITextViewer which I'm guessing is a means of connecting it to the current text editor but I can only get ITextEditor from PlatformUI interface and can't find a way of getting ITextViewer.

Any help advice on this problem would be really appricated.
Mircea
Posts: 131
Joined: Tue Mar 25, 2003 11:21 am

Post by Mircea »

Hi Barry,

You should use the method:
public void setLineBackground(int startLine, int lineCount, Color background); from the StyledText class.

Its JavaDoc says:

* Sets the background color of the specified lines.
* The background color is drawn for the width of the widget. All
* line background colors are discarded when setText is called.
* The text background color if defined in a StyleRange overlays the
* line background color. Should not be called if a LineBackgroundListener
* has been set since the listener maintains the line backgrounds.
* <p>
* Line background colors are maintained relative to the line text, not the
* line index that is specified in this method call.
* During text changes, when entire lines are inserted or removed, the line
* background colors that are associated with the lines after the change
* will "move" with their respective text. An entire line is defined as
* extending from the first character on a line to the last and including the
* line delimiter.
* </p>
* <p>
* When two lines are joined by deleting a line delimiter, the top line
* background takes precedence and the color of the bottom line is deleted.
* For all other text changes line background colors will remain unchanged.
* </p>
*
* @param startLine first line the color is applied to, 0 based
* @param lineCount number of lines the color applies to.
* @param background line background color

Regards,
Mircea
Mircea Enachescu
<oXygen> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
barryodriscoll
Posts: 2
Joined: Mon Mar 07, 2005 3:13 pm

Post by barryodriscoll »

For some reason I can't get that to work in the Java Editor, I think you have to extend the editor and contribute that. But I can use setstyleranges in styledtext and its doing roughly what I want.
stormmind
Posts: 1
Joined: Sat May 28, 2005 2:48 pm

Post by stormmind »

barryodriscoll,

I am trying to make a plugin that among other things changes the background color of java-source code. You seem to have come quite a bit on the way to that and i was wondering if you could help me with that? Where do you get StyledText from and how do you get to the current editor? Are you using any extensionpoints or how do you do stuff?

Sorry if I sound newbish, but I've spent an afternoon learning eclipse PDE from scratch and just don't have a clue about pretty much anything. =P

Thanks!

// Storm
schuro
Posts: 1
Joined: Mon Aug 08, 2005 5:48 pm

Re: Eclipse Plug-in development question: background color

Post by schuro »

did you find out a suitable way to color the background of the lines ?

the background of the Text is no problem..
I don't know how to modify the background of the styledText-widget
in a good manner..

any suggestions are appreciated..

roland
mobab
Posts: 1
Joined: Tue Jan 10, 2006 12:21 am

Post by mobab »

I had the same prob in eclipse and just figured it out.
If you want to change the background color of your editor and your editor extends AbstractTextEditor:

Color myBackroundColor = new Color(...)
getSourceViewer().getTextWidget().setBackground(myBackGroundColor);

getSourceViewer() is a protected method in org.eclipse.ui.texteditor.AbstractTextEditor it returns an ISourceViewer on which you can call getTextWidget() which returns a StyledText obj that you can set the bg color of.

Hope this helps,
Abbie.
Post Reply