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