Search in sources :

Example 1 with IAnnotationAccess

use of org.eclipse.jface.text.source.IAnnotationAccess in project mylyn.docs by eclipse.

the class HtmlViewer method initPainter.

@SuppressWarnings("deprecation")
private void initPainter() {
    if (haveInit) {
        return;
    }
    haveInit = true;
    // bug# 245759: must work outside of an Eclipse runtime
    ColorRegistry colorRegistry = WikiTextUiResources.getColors();
    IAnnotationAccess annotationAccess = new IAnnotationAccess() {

        public Object getType(Annotation annotation) {
            return annotation.getType();
        }

        public boolean isMultiLine(Annotation annotation) {
            return true;
        }

        public boolean isTemporary(Annotation annotation) {
            return true;
        }
    };
    AnnotationPainter painter = new AnnotationPainter(this, annotationAccess);
    // paint bullets
    painter.addDrawingStrategy(BulletAnnotation.TYPE, new BulletDrawingStrategy());
    painter.addAnnotationType(BulletAnnotation.TYPE, BulletAnnotation.TYPE);
    painter.setAnnotationTypeColor(BulletAnnotation.TYPE, getTextWidget().getForeground());
    // paint HR
    painter.addDrawingStrategy(HorizontalRuleAnnotation.TYPE, new HorizontalRuleDrawingStrategy());
    painter.addAnnotationType(HorizontalRuleAnnotation.TYPE, HorizontalRuleAnnotation.TYPE);
    painter.setAnnotationTypeColor(HorizontalRuleAnnotation.TYPE, colorRegistry.get(WikiTextUiResources.COLOR_HR));
    if (displayImages) {
        // paint images
        painter.addDrawingStrategy(ImageAnnotation.TYPE, new ImageDrawingStrategy(this));
        painter.addAnnotationType(ImageAnnotation.TYPE, ImageAnnotation.TYPE);
        painter.setAnnotationTypeColor(ImageAnnotation.TYPE, getTextWidget().getForeground());
    }
    addTextPresentationListener(painter);
    addPainter(painter);
    getTextWidget().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            imageCache.dispose();
        }
    });
    if (displayImages) {
        new ImageManager(this, imageCache, painter);
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ColorRegistry(org.eclipse.jface.resource.ColorRegistry) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) HorizontalRuleDrawingStrategy(org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation.HorizontalRuleDrawingStrategy) ImageDrawingStrategy(org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation.ImageDrawingStrategy) BulletDrawingStrategy(org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation.BulletDrawingStrategy) DisposeEvent(org.eclipse.swt.events.DisposeEvent) AnnotationPainter(org.eclipse.jface.text.source.AnnotationPainter) Annotation(org.eclipse.jface.text.source.Annotation) HorizontalRuleAnnotation(org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation.HorizontalRuleAnnotation) ImageAnnotation(org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation.ImageAnnotation) BulletAnnotation(org.eclipse.mylyn.internal.wikitext.ui.viewer.annotation.BulletAnnotation) ImageManager(org.eclipse.mylyn.internal.wikitext.ui.viewer.ImageManager)

Example 2 with IAnnotationAccess

use of org.eclipse.jface.text.source.IAnnotationAccess in project egit by eclipse.

the class SpellcheckableMessageArea method configureAnnotationPreferences.

private SourceViewerDecorationSupport configureAnnotationPreferences() {
    ISharedTextColors textColors = EditorsUI.getSharedTextColors();
    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(sourceViewer, null, annotationAccess, textColors);
    List annotationPreferences = new MarkerAnnotationPreferences().getAnnotationPreferences();
    Iterator e = annotationPreferences.iterator();
    while (e.hasNext()) support.setAnnotationPreference((AnnotationPreference) e.next());
    support.install(EditorsUI.getPreferenceStore());
    return support;
}
Also used : ISharedTextColors(org.eclipse.jface.text.source.ISharedTextColors) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) Iterator(java.util.Iterator) IntList(org.eclipse.jgit.util.IntList) List(java.util.List) ArrayList(java.util.ArrayList) MarkerAnnotationPreferences(org.eclipse.ui.texteditor.MarkerAnnotationPreferences) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport)

Example 3 with IAnnotationAccess

use of org.eclipse.jface.text.source.IAnnotationAccess in project eclipse-integration-commons by spring-projects.

the class EditorToolkit method createTextEditor.

public TextViewer createTextEditor(Composite composite, String text, boolean spellCheck, int style) {
    AnnotationModel annotationModel = new AnnotationModel();
    final SourceViewer textViewer = new SourceViewer(composite, null, null, true, style);
    textViewer.showAnnotations(false);
    textViewer.showAnnotationsOverview(false);
    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(textViewer, null, annotationAccess, EditorsUI.getSharedTextColors());
    @SuppressWarnings("unchecked") Iterator e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator();
    while (e.hasNext()) {
        support.setAnnotationPreference((AnnotationPreference) e.next());
    }
    support.install(EditorsUI.getPreferenceStore());
    textViewer.getTextWidget().setIndent(2);
    textViewer.getTextWidget().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            support.uninstall();
        }
    });
    IThemeManager themeManager = editorSite.getWorkbenchWindow().getWorkbench().getThemeManager();
    textViewer.getTextWidget().setFont(themeManager.getCurrentTheme().getFontRegistry().get(CommonThemes.FONT_EDITOR_COMMENT));
    final ActionContributorProxy actionContributor = getContributor();
    if (actionContributor.getSelectionChangedListener() != null) {
        textViewer.addSelectionChangedListener(actionContributor.getSelectionChangedListener());
    }
    textViewer.getTextWidget().addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            actionContributor.updateSelectableActions(textViewer.getSelection());
        }

        public void focusLost(FocusEvent e) {
            StyledText st = (StyledText) e.widget;
            st.setSelectionRange(st.getCaretOffset(), 0);
            actionContributor.forceActionsEnabled();
        }
    });
    textViewer.addTextListener(new ITextListener() {

        public void textChanged(TextEvent event) {
            actionContributor.updateSelectableActions(textViewer.getSelection());
        }
    });
    Document document = new Document(text);
    StsTextViewerConfiguration viewerConfig = new StsTextViewerConfiguration(spellCheck, false);
    textViewer.configure(viewerConfig);
    textViewer.setDocument(document, annotationModel);
    EditorUtil.setTextViewer(textViewer.getControl(), textViewer);
    configureContextMenuManager(textViewer.getControl());
    return textViewer;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) TextEvent(org.eclipse.jface.text.TextEvent) ITextListener(org.eclipse.jface.text.ITextListener) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) IThemeManager(org.eclipse.ui.themes.IThemeManager) MarkerAnnotationPreferences(org.eclipse.ui.texteditor.MarkerAnnotationPreferences) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) SourceViewerDecorationSupport(org.eclipse.ui.texteditor.SourceViewerDecorationSupport) FocusEvent(org.eclipse.swt.events.FocusEvent) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) Iterator(java.util.Iterator) FocusListener(org.eclipse.swt.events.FocusListener)

Example 4 with IAnnotationAccess

use of org.eclipse.jface.text.source.IAnnotationAccess in project tdi-studio-se by Talend.

the class TalendJavaSourceViewer method initializeViewer.

private static ReconcilerViewer initializeViewer(Composite composite, int styles, boolean checkCode, IDocument document, int visibleOffset) {
    IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    ISharedTextColors sharedColors = JavaPlugin.getDefault().getJavaTextTools().getColorManager();
    IOverviewRuler overviewRuler = null;
    IVerticalRuler verticalRuler = null;
    if (checkCode) {
        overviewRuler = new OverviewRuler(annotationAccess, 12, sharedColors);
        Iterator e = EditorsPlugin.getDefault().getMarkerAnnotationPreferences().getAnnotationPreferences().iterator();
        while (e.hasNext()) {
            AnnotationPreference preference = (AnnotationPreference) e.next();
            if (preference.contributesToHeader()) {
                overviewRuler.addHeaderAnnotationType(preference.getAnnotationType());
            }
        }
    }
    verticalRuler = new CompositeRuler(12);
    ReconcilerViewer viewer = new TalendJavaSourceViewer(composite, verticalRuler, overviewRuler, checkCode, styles, annotationAccess, sharedColors, checkCode, document);
    if (visibleOffset != -1) {
        viewer.setVisibleRegion(visibleOffset, 0);
    }
    return viewer;
}
Also used : IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) ISharedTextColors(org.eclipse.jface.text.source.ISharedTextColors) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) Iterator(java.util.Iterator) OverviewRuler(org.eclipse.jface.text.source.OverviewRuler) IOverviewRuler(org.eclipse.jface.text.source.IOverviewRuler) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference) ReconcilerViewer(org.talend.designer.core.ui.viewer.ReconcilerViewer)

Example 5 with IAnnotationAccess

use of org.eclipse.jface.text.source.IAnnotationAccess in project eclipse.platform.text by eclipse.

the class CodeMiningDemo method addAnnotationPainter.

private static void addAnnotationPainter(ISourceViewer viewer) {
    IAnnotationAccess annotationAccess = new IAnnotationAccess() {

        @Override
        public Object getType(Annotation annotation) {
            return annotation.getType();
        }

        @Override
        public boolean isMultiLine(Annotation annotation) {
            return true;
        }

        @Override
        public boolean isTemporary(Annotation annotation) {
            return true;
        }
    };
    AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
    ((ITextViewerExtension2) viewer).addPainter(painter);
    // Register this annotation painter as CodeMining annotation painter.
    ((ISourceViewerExtension5) viewer).setCodeMiningAnnotationPainter(painter);
}
Also used : ITextViewerExtension2(org.eclipse.jface.text.ITextViewerExtension2) IAnnotationAccess(org.eclipse.jface.text.source.IAnnotationAccess) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) AnnotationPainter(org.eclipse.jface.text.source.AnnotationPainter) Annotation(org.eclipse.jface.text.source.Annotation)

Aggregations

IAnnotationAccess (org.eclipse.jface.text.source.IAnnotationAccess)6 Iterator (java.util.Iterator)3 Annotation (org.eclipse.jface.text.source.Annotation)3 AnnotationPainter (org.eclipse.jface.text.source.AnnotationPainter)3 DefaultMarkerAnnotationAccess (org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess)3 ITextViewerExtension2 (org.eclipse.jface.text.ITextViewerExtension2)2 ISharedTextColors (org.eclipse.jface.text.source.ISharedTextColors)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 AnnotationPreference (org.eclipse.ui.texteditor.AnnotationPreference)2 MarkerAnnotationPreferences (org.eclipse.ui.texteditor.MarkerAnnotationPreferences)2 SourceViewerDecorationSupport (org.eclipse.ui.texteditor.SourceViewerDecorationSupport)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ColorRegistry (org.eclipse.jface.resource.ColorRegistry)1 Document (org.eclipse.jface.text.Document)1 ITextListener (org.eclipse.jface.text.ITextListener)1 TextEvent (org.eclipse.jface.text.TextEvent)1 AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)1 CompositeRuler (org.eclipse.jface.text.source.CompositeRuler)1