1 package eu
.etaxonomy
.taxeditor
.editor
.name
;
3 import org
.apache
.log4j
.Logger
;
4 import org
.eclipse
.core
.resources
.IMarker
;
5 import org
.eclipse
.jface
.text
.Position
;
6 import org
.eclipse
.jface
.text
.source
.Annotation
;
7 import org
.eclipse
.jface
.text
.source
.IAnnotationPresentation
;
8 import org
.eclipse
.swt
.graphics
.GC
;
9 import org
.eclipse
.swt
.graphics
.Image
;
10 import org
.eclipse
.swt
.graphics
.Point
;
11 import org
.eclipse
.swt
.graphics
.RGB
;
12 import org
.eclipse
.swt
.graphics
.Rectangle
;
13 import org
.eclipse
.swt
.widgets
.Canvas
;
15 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
18 * <p>EditorAnnotation class.</p>
23 public class EditorAnnotation
extends Annotation
implements IAnnotationPresentation
{
24 private static final Logger logger
= Logger
25 .getLogger(EditorAnnotation
.class);
26 private IMarker marker
;
29 private Position position
;
31 // error identifiers, images and colors
32 /** Constant <code>ERROR_TYPE="editor.error.type"</code> */
33 public static String ERROR_TYPE
= "editor.error.type";
34 /** Constant <code>ERROR_IMAGE</code> */
35 public static Image ERROR_IMAGE
= ImageResources
.getImage(ImageResources
.ERROR_ANNOTATION_ICON
);
36 /** Constant <code>ERROR_RGB</code> */
37 public static final RGB ERROR_RGB
= new RGB(255, 0, 0);
39 /** Constant <code>WARNING_TYPE="editor.warning.type"</code> */
40 public static String WARNING_TYPE
= "editor.warning.type";
41 /** Constant <code>WARNING_IMAGE</code> */
42 public static Image WARNING_IMAGE
= ImageResources
.getImage(ImageResources
.WARNING_ANNOTATION_ICON
);
43 /** Constant <code>WARNING_RGB</code> */
44 public static final RGB WARNING_RGB
= new RGB(244, 200, 45);
47 * <p>Constructor for EditorAnnotation.</p>
49 * @param marker a org.eclipse.core.resources.IMarker object.
51 public EditorAnnotation(IMarker marker
) {
56 * <p>Constructor for EditorAnnotation.</p>
59 * @param text a {@link java.lang.String} object.
61 public EditorAnnotation(int line
, String text
) {
62 this(ERROR_TYPE
, line
, text
);
66 * <p>Constructor for EditorAnnotation.</p>
68 * @param type a {@link java.lang.String} object.
70 * @param text a {@link java.lang.String} object.
72 public EditorAnnotation(String type
, int line
, String text
) {
73 super(type
, false, text
);
80 * <p>Getter for the field <code>marker</code>.</p>
82 * @return a org.eclipse.core.resources.IMarker object.
84 public IMarker
getMarker() {
89 * <p>Getter for the field <code>line</code>.</p>
93 public int getLine() {
98 * <p>Getter for the field <code>text</code>.</p>
100 * @return a {@link java.lang.String} object.
102 public String
getText() {
103 if (ERROR_TYPE
.equals(getType())) {
104 return "Error: " + text
;
106 if (WARNING_TYPE
.equals(getType())) {
107 return "Warning: " + text
;
109 return super.getText();
115 private Image
getImage() {
116 if (ERROR_TYPE
.equals(getType())) {
119 if (WARNING_TYPE
.equals(getType())) {
120 return WARNING_IMAGE
;
122 logger
.warn("No image for type " + getType());
131 public int getLayer() {
137 * <p>Getter for the field <code>position</code>.</p>
139 * @return a {@link org.eclipse.jface.text.Position} object.
141 public Position
getPosition() {
146 * <p>Setter for the field <code>position</code>.</p>
148 * @param position a {@link org.eclipse.jface.text.Position} object.
150 public void setPosition(Position position
) {
151 this.position
= position
;
156 public void paint(GC gc
, Canvas canvas
, Rectangle bounds
) {
157 Point canvasSize
= canvas
.getSize();
162 int h
= bounds
.height
;
164 if (y
+ h
> canvasSize
.y
)
175 Image image
= getImage();
181 Rectangle r
= image
.getBounds();
183 int destX
= x
+ w
- r
.width
;
184 int destY
= y
+ h
- r
.height
;
186 gc
.drawImage(image
, 0, 0, r
.width
, r
.height
, destX
, destY
, r
.width
, r
.height
);