gpt4 book ai didi

java - Eclipse:如何在垂直标尺上自定义标记的绘制

转载 作者:行者123 更新时间:2023-11-30 11:35:16 25 4
gpt4 key购买 nike

我正在开发一个 Eclipse 插件,它在 Eclipse 自己的 AbstractTextEditor 中显示自定义多行标记。

这是我目前所拥有的:

  • 具有父类(super class)型“org.eclipse.core.resources.textmarker”的自定义标记
  • annotationType (org.eclipse.ui.editors.annotationTypes)
  • markerAnnotationSpecification (org.eclipse.ui.editors.markerAnnotationSpecification)

一切正常,我的标记显示在编辑器中。但我需要自定义它们在 VerticalRuler 上的绘制方式,因此它们不仅显示为图标,而且显示为跨越受影响的源代码行的垂直线。

我知道,这可以通过实现 IAnnotationPresentation 并覆盖 paint() 来使用注释来完成。

但是我怎样才能对标记执行此操作呢?

编辑:这是我正在尝试实现的屏幕截图:

Red bars on the left

最佳答案

我通过贡献一个 RulerColumn(扩展点 org.eclipse.ui.workbench.texteditor.rulerColumns)并将 markerAnnotationSpecification 配置为 not 包含 verticalRulerPreferenceKeyverticalRulerPreferenceValue(因此它不会显示在默认的 AnnotationRulerColumn 上)。

如果有人还发现关于如何最好地实现 IContributedRulerColumn 的文档有点稀疏:似乎要走的路是子类化 AbstractContributedRulerColumn 并将方法委托(delegate)给AbstractRulerColumn 的子类。

例如:

public class MyRulerColumn extends AbstractContributedRulerColumn {
private IVerticalRulerColumn delegate = new AbstractRulerColumn() { … }
public void setModel(IAnnotationModel model) {
delegate.setModel(model);
}

}

自定义外观就像覆盖委托(delegate)中的一个 paint… 方法一样简单。

关于java - Eclipse:如何在垂直标尺上自定义标记的绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15207185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com