programmatically change the background color in eclipse
I have a question related to eclipse plugin development. Is there any means by which I can programmatically change the background color in eclipse. I am able to change the text foreground color by calling setTextColor(color, offset, length, controlRedraw) in ITextViewer but I don't find any function by which I can change the开发者_开发问答 background color of the text. If anyone has been through this kindly share your thoughts.
Thanks arav
I am not sure this can be done easily, short of extending your own version of a Text Editor, here you provide a Configuration
Class which inturn accepts a PresentationReconciler
Class which is like a Rule
Class that tells you if you need to put a Foreground or a Background Color
See this document
PresentationReconciler
IPresentationDamager
: define dirty region given a text changeIPresentationRepairer
: recreate presentation for dirty regionDefaultDamagerRepairer
does both, based on a token scannerITokenScanner
: parse text into a token streamRuleBasedScanner
uses simple rules
Extract from the presentation
From Text Editor Recipes, Season’s recipes for your text editor
Tom Eicher, IBM Eclipse Team
Here, the null background color means, takes the default system background for that widget. (so here: white).
But you could specify whatever color you want, based on the partitioning of your document and on the rules that would apply.
I know this was asked a while ago, but in case anyone is looking for another solution, I thought I would post the following:
Since you are able to use the setTextColor method, then you should be able to use the changeTextPresentation method as well.
In the case of my plug-in, I have a TextListener that calls the TextChanged method I overwrote. I did the following to add background color using the changeTextPresentation method. In doing so, I was able to get a Green background with Black foreground. Not that I would want this, of course, but just for testing purposes.
public void TextChanged(TextEvent event){
...
TextPresentation presentation = new TextPresentation();
TextAttribute attr = new TextAttribute(new ColorManager().getColor(MyConstants.BLACK),
new ColorManager().getColor(MyConstants.GREEN), style);
presentation.addStyleRange(new StyleRange(startOffset, tokLength, attr.getForeground(),
attr.getBackground());
sourceViewer.changeTextPresentation(presentation, true); //sourceViewer is a global variable passed to my TextListener class constructor.
}
精彩评论