@Override protected void configureTextViewer(final TextViewer textViewer) { ThemePlugin.getDefault().getControlThemerFactory().apply(textViewer); // Force line highlight color. We need to perform this after the line painter is attached, which happens after // the return of this method. Scheduling async seems to work. UIUtils.getDisplay().asyncExec(new Runnable() { public void run() { CursorLinePainter p = getCursorLinePainterInstalled(textViewer); if (p != null) { p.setHighlightColor(getColorManager().getColor(getCurrentTheme().getLineHighlightAgainstBG())); } } }); }
private CursorLinePainter getCursorLinePainterInstalled(TextViewer viewer) { Listener[] listeners = viewer.getTextWidget().getListeners(3001/* StyledText.LineGetBackground */); for (Listener listener : listeners) { if (listener instanceof TypedListener) { TypedListener typedListener = (TypedListener) listener; if (typedListener.getEventListener() instanceof CursorLinePainter) { return (CursorLinePainter) typedListener.getEventListener(); } } } return null; }
/** * Initialize foreground, background color, current line highlight from the * current theme if needed. * */ private void applyThemeEditorIfNeeded() { if (!initializeViewerColors) { StyledText styledText = viewer.getTextWidget(); ((ITheme) tokenProvider).initializeViewerColors(styledText); initializeViewerColors = true; } if (!updateTextDecorations) { try { // Ugly code to update "current line highlight" : // - get the PaintManager from the ITextViewer with reflection. // - get the list of IPainter of PaintManager with reflection // - loop for IPainter to retrieve CursorLinePainter which manages "current line // highlight". PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class); if (paintManager != null) { List<IPainter> painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class); if (painters != null) { for (IPainter painter : painters) { if (painter instanceof CursorLinePainter) { // Update current line highlight Color background = tokenProvider.getEditorCurrentLineHighlight(); if (background != null) { ((CursorLinePainter) painter).setHighlightColor(background); } updateTextDecorations = true; } } } } } catch (Exception e) { e.printStackTrace(); } } }
private void createCursorLinePainter() { cursorLinePainter = new CursorLinePainter(txtViewer); Color color = new Color(Display.getCurrent(),PreferenceConverter.getColor(store,ILogViewerConstants.PREF_CURSORLINE_COLOR)); cursorLinePainter.setHighlightColor(color); ITextViewerExtension2 extension = (ITextViewerExtension2)txtViewer; extension.addPainter(cursorLinePainter); }