Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java51
1 files changed, 44 insertions, 7 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
index bd0f1833249..731176378eb 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
@@ -52,11 +52,15 @@ public abstract class AbstractInlinedAnnotation extends Annotation {
*/
private InlinedAnnotationSupport support;
+ int fX;
+
+ int fY;
+
/**
* Inlined annotation constructor.
*
* @param position the position where the annotation must be drawn.
- * @param viewer the {@link ISourceViewer} where the annotation must be drawn.
+ * @param viewer the {@link ISourceViewer} where the annotation must be drawn.
*/
protected AbstractInlinedAnnotation(Position position, ISourceViewer viewer) {
super(TYPE, false, ""); //$NON-NLS-1$
@@ -112,13 +116,13 @@ public abstract class AbstractInlinedAnnotation extends Annotation {
* Draw the inlined annotation. By default it draw the text of the annotation with gray color.
* User can override this method to draw anything.
*
- * @param gc the graphics context
+ * @param gc the graphics context
* @param textWidget the text widget to draw on
- * @param offset the offset of the line
- * @param length the length of the line
- * @param color the color of the line
- * @param x the x position of the annotation
- * @param y the y position of the annotation
+ * @param offset the offset of the line
+ * @param length the length of the line
+ * @param color the color of the line
+ * @param x the x position of the annotation
+ * @param y the y position of the annotation
*/
public void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
gc.setForeground(color);
@@ -191,4 +195,37 @@ public abstract class AbstractInlinedAnnotation extends Annotation {
Font getFont(int style) {
return support.getFont(style);
}
+
+ /**
+ * Set the location where the annotation is drawn.
+ *
+ * @param x the x coordinate where draw of annotation starts.
+ * @param y the y coordinate where draw of annotation starts.
+ */
+ void setLocation(int x, int y) {
+ this.fX= x;
+ this.fY= y;
+ }
+
+ /**
+ * Returns <code>true</code> if the point specified by the arguments is inside the annotation
+ * specified by the receiver, and <code>false</code> otherwise.
+ *
+ * @param x the x coordinate of the point to test for containment
+ * @param y the y coordinate of the point to test for containment
+ * @return <code>true</code> if the annotation contains the point and <code>false</code>
+ * otherwise
+ */
+ boolean contains(int x, int y) {
+ StyledText styledText= getTextWidget();
+ GC gc= null;
+ try {
+ gc= new GC(styledText);
+ return x >= fX && y >= fY && y <= fY + styledText.getLineHeight(position.getOffset()) && x <= fX + gc.stringExtent(getText()).x + 2 * gc.getFontMetrics().getAverageCharacterWidth();
+ } finally {
+ if (gc != null) {
+ gc.dispose();
+ }
+ }
+ }
}

Back to the top