How can I use org.eclipse.jface.text.PaintManager in subclass of TextEditor?

36 views Asked by At

How can I attach a PaintManager to my TextEditor? For example, draw the background of cursor line with org.eclipse.jface.text.CursorLinePainter.

1

There are 1 answers

2
greg-449 On BEST ANSWER

Your editor's TextViewer or SourceViewer provides the paint manager. You can access it using the ITextViewerExtension2 interface of the viewer.

For example this code is from 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);
        }
    }
}