]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/SCLAnnotationAccessNew.java
Externalize strings in org.simantics.scl.ui
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / editor / SCLAnnotationAccessNew.java
1 package org.simantics.scl.ui.editor;
2
3 import org.eclipse.jface.resource.ImageDescriptor;
4 import org.eclipse.jface.resource.ImageRegistry;
5 import org.eclipse.jface.text.source.Annotation;
6 import org.eclipse.jface.text.source.IAnnotationAccess;
7 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
8 import org.eclipse.jface.text.source.ImageUtilities;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.graphics.GC;
11 import org.eclipse.swt.graphics.Image;
12 import org.eclipse.swt.graphics.Rectangle;
13 import org.eclipse.swt.widgets.Canvas;
14
15 final class SCLAnnotationAccessNew implements IAnnotationAccess, IAnnotationAccessExtension {
16
17     ImageRegistry registry;
18     
19     public SCLAnnotationAccessNew(ImageRegistry registry) {
20         this.registry = registry;
21     }
22
23     @Override
24     public Object getType(Annotation annotation) {
25         return annotation.getType();
26     }
27
28     @Override
29     public boolean isMultiLine(Annotation annotation) {
30         return true;
31     }
32
33     @Override
34     public boolean isTemporary(Annotation annotation) {
35         return !annotation.isPersistent();
36     }
37
38     @Override
39     public String getTypeLabel(Annotation annotation) {
40         return annotation.getType();
41     }
42
43     @Override
44     public int getLayer(Annotation annotation) {
45         return 0;
46     }
47
48     @Override
49     public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) {
50         Image image = registry.get("error"); //$NON-NLS-1$
51         if(image == null) {
52             registry.put("error", ImageDescriptor.createFromFile(getClass(), "error_tsk.gif")); //$NON-NLS-1$ //$NON-NLS-2$
53             image = registry.get("error"); //$NON-NLS-1$
54         }
55         ImageUtilities.drawImage(image, gc, canvas, bounds, SWT.CENTER, SWT.TOP);
56     }
57
58     @Override
59     public boolean isPaintable(Annotation annotation) {
60         return true;
61     }
62
63     @Override
64     public boolean isSubtype(Object annotationType, Object potentialSupertype) {
65         return annotationType.equals(potentialSupertype);
66     }
67
68     @Override
69     public Object[] getSupertypes(Object annotationType) {
70         return new Object[0];
71     }
72 }