如何在TextEditor的子类中使用org.eclipse.jface.text.PaintManager?

时间:2015-06-19 10:33:53

标签: eclipse eclipse-plugin jface

如何将PaintManager附加到TextEditor? 例如,使用org.eclipse.jface.text.CursorLinePainter绘制光标线的背景。

1 个答案:

答案 0 :(得分:0)

您的编辑TextViewerSourceViewer提供了油漆管理员。您可以使用查看器的ITextViewerExtension2界面访问它。

例如,此代码来自SourceViewerDecorationSupport

private void showCursorLine() {
    if (fCursorLinePainter == null) {
        if (fSourceViewer instanceof ITextViewerExtension2) {
            fCursorLinePainter = new CursorLinePainter(fSourceViewer);
            fCursorLinePainter.setHighlightColor(getColor(fCursorLinePainterColorKey));

            ITextViewerExtension2 extension = (ITextViewerExtension2) fSourceViewer;
            extension.addPainter(fCursorLinePainter);
        }
    }
}