Programmatically change background color in eclipse

I have a question related to the development of the eclipse plugin. Are there any means by which I can programmatically change the background color in eclipse. I can change the color of the foreground text by calling setTextColor (color, offset, length, controlRedraw) in ITextViewer but I do not find any function with which I can change the background color of the text. If someone went through this, share your thoughts.

Thanks arav

+3
source share
2 answers

I'm not sure that this can be done easily, without expanding your own version of the text editor, here you provide a class Configurationthat inturn accepts a class PresentationReconcilerthat looks like a class Rulethat you tell if you need to put the foreground or background color

See this document.

PresentationReconciler

  • IPresentationDamager: identify a dirty area based on a change in text
  • IPresentationRepairer: recreate a presentation for a dirty area
  • DefaultDamagerRepairer does both based on token scanner
  • ITokenScanner: parse text into token stream
  • RuleBasedScanner uses simple rules

Extract from presentation

http://web.archive.org/web/20140715222227/http://img266.i_mageshack.us/img266/5465/setrules2.png

From a text editor Recipes, recipes of the seasons for your text editor
Tom Eicher , IBM Eclipse Team

, . ( : ).
, , , .

+2

, , , - , , :

setTextColor, changeTextPresentation.

TextListener, TextChanged, . , , changeTextPresentation. . , , .

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.
}
+1

Source: https://habr.com/ru/post/1727427/


All Articles