949b7979f655c2c68ba8771588c39fe7ff7b6f2d
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / ErrorAnnotation.java
1 package eu.etaxonomy.taxeditor.editor;
2
3 import org.eclipse.core.resources.IMarker;
4 import org.eclipse.jface.text.Position;
5 import org.eclipse.jface.text.source.Annotation;
6 import org.eclipse.jface.text.source.IAnnotationPresentation;
7 import org.eclipse.swt.graphics.GC;
8 import org.eclipse.swt.graphics.Image;
9 import org.eclipse.swt.graphics.Point;
10 import org.eclipse.swt.graphics.RGB;
11 import org.eclipse.swt.graphics.Rectangle;
12 import org.eclipse.swt.widgets.Canvas;
13
14 import eu.etaxonomy.taxeditor.store.model.ImageResources;
15
16 public class ErrorAnnotation extends Annotation implements IAnnotationPresentation {
17 private IMarker marker;
18 private String text;
19 private int line;
20 private Position position;
21
22 // error identifiers, images and colors
23 public static String ERROR_TYPE = "error.type";
24 public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ACTIVE_DELETE_ICON);
25 public static final RGB ERROR_RGB = new RGB(255, 0, 0);
26
27 public ErrorAnnotation(IMarker marker) {
28 this.marker = marker;
29 }
30
31 public ErrorAnnotation(int line, String text) {
32 super(ERROR_TYPE, false, text);
33 this.marker = null;
34 this.line = line;
35 this.text = text;
36 }
37
38 public IMarker getMarker() {
39 return marker;
40 }
41
42 public int getLine() {
43 return line;
44 }
45
46 public String getText() {
47 return "Error in the string " + text;
48 }
49
50 public int getLayer() {
51 return 3;
52 }
53
54 public String getType() {
55 return ERROR_TYPE;
56 }
57
58 public Position getPosition() {
59 return position;
60 }
61
62 public void setPosition(Position position) {
63 this.position = position;
64 }
65
66
67 public void paint(GC gc, Canvas canvas, Rectangle bounds) {
68 Point canvasSize= canvas.getSize();
69
70 int x= 0;
71 int y= bounds.y;
72 int w= canvasSize.x;
73 int h= bounds.height;
74
75 if (y + h > canvasSize.y)
76 h= canvasSize.y - y;
77
78 if (y < 0) {
79 h= h + y;
80 y= 0;
81 }
82
83 if (h <= 0)
84 return;
85
86 Image image = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON);
87
88 Rectangle r = image.getBounds();
89
90 int destX = x + w - r.width;
91 int destY = y + h - r.height;
92
93 gc.drawImage(image, 0, 0, r.width, r.height, destX, destY, r.width, r.height);
94 }
95 }