Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2003-12-01 15:34:27 +0000
committerKai Maetzel2003-12-01 15:34:27 +0000
commit1d7b3b9a6614b95886bdf5f7f99870940d570dac (patch)
treeffd5f99a3dd2ff4c411c5868e9b12cf340321d91
parente69ea6e9616ec87eccde0e7995bb3a5071db8e51 (diff)
downloadeclipse.platform.text-1d7b3b9a6614b95886bdf5f7f99870940d570dac.tar.gz
eclipse.platform.text-1d7b3b9a6614b95886bdf5f7f99870940d570dac.tar.xz
eclipse.platform.text-1d7b3b9a6614b95886bdf5f7f99870940d570dac.zip
delegate UI part of annotations to annotation access
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java53
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java26
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java31
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java42
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DefaultMarkerAnnotationAccess.java18
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction.java20
8 files changed, 145 insertions, 49 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
index d5215d5b53f..df4df5379bc 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
@@ -113,6 +113,7 @@ public abstract class Annotation {
* Returns the annotations drawing layer.
*
* @return the annotations drawing layer
+ * @deprecated use <code>IAnnotationAccessExtension.getLayer(Annotation)</code>
*/
public int getLayer() {
return fLayer;
@@ -125,6 +126,7 @@ public abstract class Annotation {
* @param GC the drawing GC
* @param canvas the canvas to draw on
* @param bounds the bounds inside the canvas to draw on
+ * @deprecated use <code>IAnnotationAccessExtension.paint(Annotation, GC, Canvas, Rectangle)</code>
*/
public abstract void paint(GC gc, Canvas canvas, Rectangle bounds);
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
index 867d1539855..a6d8612c959 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
@@ -62,8 +62,6 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
private Position fPosition;
/** The color of this decoration */
private Color fColor;
- /** Indicates whether this decoration might span multiple lines */
- private boolean fMultiLine;
/**
* The annotation's layer
* @since 3.0
@@ -228,8 +226,12 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
Decoration pp= new Decoration();
pp.fPosition= position;
pp.fColor= color;
- pp.fMultiLine= fAnnotationAccess.isMultiLine(annotation);
- pp.fLayer= annotation.getLayer();
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
+ IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+ pp.fLayer= extension.getLayer(annotation);
+ } else {
+ pp.fLayer= IAnnotationAccessExtension.DEFAULT_LAYER;
+ }
if (isDrawingSquiggles)
fDecorations.add(pp);
@@ -516,36 +518,27 @@ public class AnnotationPainter implements IPainter, PaintListener, IAnnotationMo
Position p= pp.fPosition;
if (p.overlapsWith(vOffset, vLength)) {
-
- if (!pp.fMultiLine) {
-
- IRegion widgetRange= getWidgetRange(p);
- if (widgetRange != null)
- draw(gc, widgetRange.getOffset(), widgetRange.getLength(), pp.fColor);
- } else {
+ IDocument document= fSourceViewer.getDocument();
+ try {
- IDocument document= fSourceViewer.getDocument();
- try {
-
- int startLine= document.getLineOfOffset(p.getOffset());
- int lastInclusive= Math.max(p.getOffset(), p.getOffset() + p.getLength() - 1);
- int endLine= document.getLineOfOffset(lastInclusive);
-
- for (int i= startLine; i <= endLine; i++) {
- IRegion line= document.getLineInformation(i);
- int paintStart= Math.max(line.getOffset(), p.getOffset());
- int paintEnd= Math.min(line.getOffset() + line.getLength(), p.getOffset() + p.getLength());
- if (paintEnd > paintStart) {
- // otherwise inside a line delimiter
- IRegion widgetRange= getWidgetRange(new Position(paintStart, paintEnd - paintStart));
- if (widgetRange != null)
- draw(gc, widgetRange.getOffset(), widgetRange.getLength(), pp.fColor);
- }
- }
+ int startLine= document.getLineOfOffset(p.getOffset());
+ int lastInclusive= Math.max(p.getOffset(), p.getOffset() + p.getLength() - 1);
+ int endLine= document.getLineOfOffset(lastInclusive);
- } catch (BadLocationException x) {
+ for (int i= startLine; i <= endLine; i++) {
+ IRegion line= document.getLineInformation(i);
+ int paintStart= Math.max(line.getOffset(), p.getOffset());
+ int paintEnd= Math.min(line.getOffset() + line.getLength(), p.getOffset() + p.getLength());
+ if (paintEnd > paintStart) {
+ // otherwise inside a line delimiter
+ IRegion widgetRange= getWidgetRange(new Position(paintStart, paintEnd - paintStart));
+ if (widgetRange != null)
+ draw(gc, widgetRange.getOffset(), widgetRange.getLength(), pp.fColor);
+ }
}
+
+ } catch (BadLocationException x) {
}
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
index 96df8901980..47548481234 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
@@ -326,6 +326,10 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
if (fModel == null || fCachedTextViewer == null)
return;
+
+ IAnnotationAccessExtension annotationAccessExtension= null;
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension)
+ annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess;
int topLeft= getInclusiveTopIndexStartOffset();
int bottomRight;
@@ -372,10 +376,12 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
while (iter.hasNext()) {
Annotation annotation= (Annotation) iter.next();
- if (fAnnotationAccess != null && skip(fAnnotationAccess.getType(annotation)))
+ if (skip(fAnnotationAccess.getType(annotation)))
continue;
- int lay= annotation.getLayer();
+ int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
+ if (annotationAccessExtension != null)
+ lay= annotationAccessExtension.getLayer(annotation);
maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
if (lay != layer) // wrong layer: skip annotation
continue;
@@ -417,8 +423,8 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
lines= -lines;
r.height= (lines+1) * lineheight;
- if (r.y < dimension.y) // annotation within visible area
- annotation.paint(gc, fCanvas, r);
+ if (r.y < dimension.y && annotationAccessExtension != null) // annotation within visible area
+ annotationAccessExtension.paint(annotation, gc, fCanvas, r);
} catch (BadLocationException e) {
}
@@ -436,6 +442,10 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
if (fModel == null || fCachedTextViewer == null)
return;
+
+ IAnnotationAccessExtension annotationAccessExtension= null;
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension)
+ annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess;
ITextViewerExtension3 extension= (ITextViewerExtension3) fCachedTextViewer;
@@ -457,7 +467,9 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
if (fAnnotationAccess != null && skip(fAnnotationAccess.getType(annotation)))
continue;
- int lay= annotation.getLayer();
+ int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
+ if (annotationAccessExtension != null)
+ lay= annotationAccessExtension.getLayer(annotation);
maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
if (lay != layer) // wrong layer: skip annotation
continue;
@@ -486,8 +498,8 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn {
lines= -lines;
r.height= (lines+1) * lineheight;
- if (r.y < dimension.y) // annotation within visible area
- annotation.paint(gc, fCanvas, r);
+ if (r.y < dimension.y && annotationAccessExtension != null) // annotation within visible area
+ annotationAccessExtension.paint(annotation, gc, fCanvas, r);
}
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
index a1f8f0c37eb..d7d96ebdc42 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
@@ -33,6 +33,8 @@ public interface IAnnotationAccess {
* @param annotation the annotation
* @return <code>true</code> if the annotation spans multiple lines,
* <code>false</code> otherwise
+ *
+ * @deprecated assumed to always return <code>true</code>
*/
boolean isMultiLine(Annotation annotation);
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
index b304ed73680..aee0a7c8515 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
@@ -11,6 +11,10 @@
package org.eclipse.jface.text.source;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+
/**
* Extension interface for <code>IAnnotationAccess</code>.
* Allows to get a label for the annotation's type.
@@ -19,6 +23,12 @@ package org.eclipse.jface.text.source;
* @since 3.0
*/
public interface IAnnotationAccessExtension {
+
+ /**
+ * The default annotation layer.
+ */
+ static final int DEFAULT_LAYER= 0;
+
/**
* Returns the label for the given annotation's type.
@@ -27,4 +37,25 @@ public interface IAnnotationAccessExtension {
* @return the label the given annotation's type or <code>null</code> if no such label exists
*/
String getTypeLabel(Annotation annotation);
+
+ /**
+ * Returns the layer for given annotation. Annotations are considered
+ * being located at layers and are considered being painted starting with
+ * layer 0 upwards. Thus an annotation at layer 5 will be drawn on top of
+ * all co-located annotations at the layers 4 - 0.
+ *
+ * @param annotation the annotation
+ * @return the layer of the given annotation
+ */
+ int getLayer(Annotation annotation);
+
+ /**
+ * Draws a graphical representation of the given annotation within the given bounds.
+ *
+ * @param annotation the given annotation
+ * @param GC the drawing GC
+ * @param canvas the canvas to draw on
+ * @param bounds the bounds inside the canvas to draw on
+ */
+ void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds);
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java
index 13cf8b04e4a..dc7e41a32cd 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java
@@ -100,7 +100,11 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
private InternalListener fInternalListener= new InternalListener();
/** The width of this vertical ruler */
private int fWidth;
-
+ /**
+ * The annotation access of this vertical ruler
+ * @since 3.0
+ */
+ private IAnnotationAccess fAnnotationAccess;
/**
* Constructs a vertical ruler with the given width.
@@ -108,7 +112,19 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
* @param width the width of the vertical ruler
*/
public VerticalRuler(int width) {
+ this(width, null);
+ }
+
+ /**
+ * Constructs a vertical ruler with the given width and the given annotation
+ * access.
+ *
+ * @param width the width of the vertical ruler
+ * @param annotationAcccess the annotation access
+ */
+ public VerticalRuler(int width, IAnnotationAccess annotationAcccess) {
fWidth= width;
+ fAnnotationAccess= annotationAcccess;
}
/*
@@ -256,6 +272,10 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
if (fModel == null || fTextViewer == null)
return;
+
+ IAnnotationAccessExtension annotationAccessExtension= null;
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension)
+ annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess;
StyledText styledText= fTextViewer.getTextWidget();
IDocument doc= fTextViewer.getDocument();
@@ -288,7 +308,9 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
while (iter.hasNext()) {
Annotation annotation= (Annotation) iter.next();
- int lay= annotation.getLayer();
+ int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
+ if (annotationAccessExtension != null)
+ lay= annotationAccessExtension.getLayer(annotation);
maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
if (lay != layer) // wrong layer: skip annotation
continue;
@@ -326,8 +348,8 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
lines= -lines;
r.height= (lines+1) * lineheight;
- if (r.y < d.y) // annotation within visible area
- annotation.paint(gc, fCanvas, r);
+ if (r.y < d.y && annotationAccessExtension != null) // annotation within visible area
+ annotationAccessExtension.paint(annotation, gc, fCanvas, r);
} catch (BadLocationException e) {
}
@@ -346,6 +368,10 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
if (fModel == null || fTextViewer == null)
return;
+
+ IAnnotationAccessExtension annotationAccessExtension= null;
+ if (fAnnotationAccess instanceof IAnnotationAccessExtension)
+ annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess;
ITextViewerExtension3 extension= (ITextViewerExtension3) fTextViewer;
StyledText textWidget= fTextViewer.getTextWidget();
@@ -365,7 +391,9 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
Annotation annotation= (Annotation) iter.next();
- int lay= annotation.getLayer();
+ int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
+ if (annotationAccessExtension != null)
+ lay= annotationAccessExtension.getLayer(annotation);
maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
if (lay != layer) // wrong layer: skip annotation
continue;
@@ -394,8 +422,8 @@ public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtens
lines= -lines;
r.height= (lines+1) * lineheight;
- if (r.y < dimension.y) // annotation within visible area
- annotation.paint(gc, fCanvas, r);
+ if (r.y < dimension.y && annotationAccessExtension != null) // annotation within visible area
+ annotationAccessExtension.paint(annotation, gc, fCanvas, r);
}
}
}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DefaultMarkerAnnotationAccess.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DefaultMarkerAnnotationAccess.java
index 1e5318afeb1..42792d788bc 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DefaultMarkerAnnotationAccess.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/DefaultMarkerAnnotationAccess.java
@@ -15,6 +15,10 @@ import java.util.Iterator;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.IAnnotationAccessExtension;
@@ -141,4 +145,18 @@ public class DefaultMarkerAnnotationAccess implements IAnnotationAccess, IAnnota
return null;
}
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationAccessExtension#getLayer(org.eclipse.jface.text.source.Annotation)
+ */
+ public int getLayer(Annotation annotation) {
+ return annotation.getLayer();
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationAccessExtension#paint(org.eclipse.jface.text.source.Annotation, org.eclipse.swt.graphics.GC, org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
+ */
+ public void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds) {
+ annotation.paint(gc, canvas, bounds);
+ }
}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction.java
index a765d6c8a63..3cabadd5fea 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction.java
@@ -18,8 +18,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
-import org.eclipse.swt.widgets.Shell;
-
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
@@ -29,15 +27,20 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.widgets.Shell;
+
import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
+
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.IAnnotationAccessExtension;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
-import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IViewPart;
@@ -134,6 +137,10 @@ public class SelectMarkerRulerAction extends ResourceAction implements IUpdate {
protected IMarker chooseMarker(List markers) {
AbstractMarkerAnnotationModel model= getAnnotationModel();
+ IAnnotationAccessExtension access= null;
+ Object adapter= fTextEditor.getAdapter(IAnnotationAccess.class);
+ if (adapter instanceof IAnnotationAccessExtension)
+ access= (IAnnotationAccessExtension) adapter;
IMarker marker= null;
int maxLayer= 0;
@@ -142,9 +149,12 @@ public class SelectMarkerRulerAction extends ResourceAction implements IUpdate {
while (iter.hasNext()) {
IMarker m= (IMarker) iter.next();
Annotation a= model.getMarkerAnnotation(m);
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=18960
if (a != null) {
- int l= a.getLayer();
+ if (access == null) {
+ marker= m;
+ break;
+ }
+ int l= access.getLayer(a);
if (l == maxLayer) {
if (marker == null)
marker= m;

Back to the top