From 09d20e2d35ff88017de4e008a81abe90ebd9cfa4 Mon Sep 17 00:00:00 2001 From: Oleksandr Krutko Date: Sat, 27 Jan 2024 10:43:48 +0200 Subject: [PATCH] update InlinedAnnotationDemo to get rid off depricated methods Signed-off-by: Oleksandr Krutko --- .../inlined/InlinedAnnotationDemo.java | 75 ++++++++++++++----- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/examples/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java b/examples/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java index 6820c25b328..cbafe2767b1 100644 --- a/examples/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java +++ b/examples/org.eclipse.jface.text.examples/src/org/eclipse/jface/text/examples/sources/inlined/InlinedAnnotationDemo.java @@ -31,6 +31,7 @@ import org.eclipse.jface.text.source.AnnotationModel; import org.eclipse.jface.text.source.AnnotationPainter; import org.eclipse.jface.text.source.IAnnotationAccess; +import org.eclipse.jface.text.source.IAnnotationAccessExtension; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation; @@ -41,7 +42,10 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -105,6 +109,58 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { display.dispose(); } + /** + * Create annotation access by implementing annotation access extension. + * + * @return annotation access. + */ + private static class AnnotationAccessExtension implements IAnnotationAccess, IAnnotationAccessExtension { + + @Override + public String getTypeLabel(Annotation annotation) { + return annotation.getText(); + } + + @Override + public int getLayer(Annotation annotation) { + return IAnnotationAccessExtension.DEFAULT_LAYER; + } + + @Override + public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) { + } + + @Override + public boolean isPaintable(Annotation annotation) { + return true; + } + + @Override + public boolean isSubtype(Object annotationType, Object potentialSupertype) { + return false; + } + + @Override + public Object[] getSupertypes(Object annotationType) { + return null; + } + + @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; + } + + } /** * Create annotation painter. * @@ -113,24 +169,7 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { * @return annotation painter. */ private static AnnotationPainter createAnnotationPainter(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); + AnnotationPainter painter = new AnnotationPainter(viewer, new AnnotationAccessExtension()); ((ITextViewerExtension2) viewer).addPainter(painter); return painter; }