以编程方式更改 Eclipse 中的背景颜色

发布于 2024-08-17 02:20:59 字数 207 浏览 1 评论 0原文

我有一个关于 eclipse 插件开发的问题。有什么办法吗 通过它我可以以编程方式更改 Eclipse 中的背景颜色。 我可以通过调用更改文本前景色 ITextViewer 中的 setTextColor(颜色、偏移量、长度、controlRedraw) 但我没有找到任何可以更改背景的功能 文本的颜色。 如果有人经历过这种情况,请分享您的想法。

谢谢 阿拉夫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦断已成空 2024-08-24 02:20:59

我不确定这是否可以轻松完成,除非扩展您自己的文本编辑器版本,在这里您提供一个 Configuration 类,该类又接受一个 PresentationReconciler 类,就像告诉您是否需要放置前景色或背景色的 Rule

请参阅 本文档

PresentationReconciler

  • IPresentationDamager:定义给定文本的脏区域更改
  • IPresentationRepairer:为脏区域重新创建演示
  • DefaultDamagerRepairer 基于令牌扫描器执行这两项操作
  • ITokenScanner:将文本解析为令牌流
  • RuleBasedScanner 使用简单的规则

从演示文稿中摘录

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

来自文本编辑器食谱,文本编辑器的季节食谱
Tom Eicher,IBM Eclipse 团队

这里,空背景颜色意味着采用该小部件的默认系统背景。 (所以这里:白色)。
但是您可以根据文档的分区和适用的规则指定所需的任何颜色。

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 change
  • IPresentationRepairer: recreate presentation for dirty region
  • DefaultDamagerRepairer does both, based on a token scanner
  • ITokenScanner: parse text into a token stream
  • RuleBasedScanner uses simple rules

Extract from the presentation

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

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.

女中豪杰 2024-08-24 02:20:59

我知道不久前有人问过这个问题,但如果有人正在寻找其他解决方案,我想我会发布以下内容:

既然您能够使用 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.
}

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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文