1 package eu
.etaxonomy
.taxeditor
.editor
.name
.container
;
3 import org
.apache
.logging
.log4j
.LogManager
;import org
.apache
.logging
.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
.cdm
.strategy
.parser
.ParserProblem
;
16 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
17 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
20 * <p>EditorAnnotation class.</p>
24 public class EditorAnnotation
extends Annotation
implements IAnnotationPresentation
{
26 @SuppressWarnings("unused")
27 private static final Logger logger
= LogManager
.getLogger(EditorAnnotation
.class);
28 private final IMarker marker
;
31 private Position position
;
33 public enum EditorAnnotationType
{
34 WARNING(ImageResources
.WARNING_ANNOTATION_ICON
, 244, 200, 45),
35 ERROR(ImageResources
.ERROR_ANNOTATION_ICON
, 255, 0, 0);
40 EditorAnnotationType(String imageResource
, int r
, int g
, int b
){
41 image
= ImageResources
.getImage(imageResource
);
42 color
= new RGB(r
, g
, b
);
49 public static EditorAnnotationType
getTypeByProblem(
50 ParserProblem problem
) {
51 if (problem
.isWarning()) {
53 }else if (problem
.isError()) {
61 // // error identifiers, images and colors
62 // /** Constant <code>ERROR_TYPE="editor.error.type"</code> */
63 // public static String ERROR_TYPE = "editor.error.type";
64 // /** Constant <code>ERROR_IMAGE</code> */
65 // public static Image ERROR_IMAGE = ImageResources.getImage(ImageResources.ERROR_ANNOTATION_ICON);
66 // /** Constant <code>ERROR_RGB</code> */
67 // public static final RGB ERROR_RGB = new RGB(255, 0, 0);
69 // /** Constant <code>WARNING_TYPE="editor.warning.type"</code> */
70 // public static String WARNING_TYPE = "editor.warning.type";
71 // /** Constant <code>WARNING_IMAGE</code> */
72 // public static Image WARNING_IMAGE = ImageResources.getImage(ImageResources.WARNING_ANNOTATION_ICON);
73 // /** Constant <code>WARNING_RGB</code> */
74 // public static final RGB WARNING_RGB = new RGB(244, 200, 45);
77 public EditorAnnotation(ParserProblem problem
){
78 this(EditorAnnotationType
.getTypeByProblem(problem
), 0, problem
.getMessage());
83 * <p>Constructor for EditorAnnotation.</p>
85 * @param marker a org.eclipse.core.resources.IMarker object.
87 public EditorAnnotation(IMarker marker
) {
92 * <p>Constructor for EditorAnnotation.</p>
95 * @param text a {@link java.lang.String} object.
97 public EditorAnnotation(int line
, String text
) {
98 this(EditorAnnotationType
.ERROR
, line
, text
);
102 * <p>Constructor for EditorAnnotation.</p>
104 * @param type a {@link java.lang.String} object.
106 * @param text a {@link java.lang.String} object.
108 public EditorAnnotation(EditorAnnotationType type
, int line
, String text
) {
109 super(type
.name(), false, text
);
116 * <p>Getter for the field <code>marker</code>.</p>
118 * @return a org.eclipse.core.resources.IMarker object.
120 public IMarker
getMarker() {
125 * <p>Getter for the field <code>line</code>.</p>
129 public int getLine() {
134 * <p>Getter for the field <code>text</code>.</p>
136 * @return a {@link java.lang.String} object.
139 public String
getText() {
140 if (EditorAnnotationType
.ERROR
.name().equals(getType())) {
141 return Messages
.EditorAnnotation_ERROR
+ text
;
143 if (EditorAnnotationType
.WARNING
.name().equals(getType())) {
144 return Messages
.EditorAnnotation_WARNING
+ text
;
146 return super.getText();
152 private Image
getImage() {
153 return EditorAnnotationType
.valueOf(getType()).image
;
162 public int getLayer() {
168 * <p>Getter for the field <code>position</code>.</p>
170 * @return a {@link org.eclipse.jface.text.Position} object.
172 public Position
getPosition() {
177 * <p>Setter for the field <code>position</code>.</p>
179 * @param position a {@link org.eclipse.jface.text.Position} object.
181 public void setPosition(Position position
) {
182 this.position
= position
;
186 public void paint(GC gc
, Canvas canvas
, Rectangle bounds
) {
187 Point canvasSize
= canvas
.getSize();
192 int h
= bounds
.height
;
194 if (y
+ h
> canvasSize
.y
) {
207 Image image
= getImage();
213 Rectangle r
= image
.getBounds();
215 int destX
= x
+ w
- r
.width
;
216 int destY
= y
+ h
- r
.height
;
218 gc
.drawImage(image
, 0, 0, r
.width
, r
.height
, destX
, destY
, r
.width
, r
.height
);