diff options
author | Kai Maetzel | 2004-05-27 16:32:54 +0000 |
---|---|---|
committer | Kai Maetzel | 2004-05-27 16:32:54 +0000 |
commit | 9f72014b1e1e1699b560e87257eed2520b128a8e (patch) | |
tree | b8a0441f29dbff966fc84c67c63317c44899a0ca /org.eclipse.jface.text/src/org | |
parent | 45f2fd29e3edabe7bfbebad8232a57a14f2e80e1 (diff) | |
download | eclipse.platform.text-9f72014b1e1e1699b560e87257eed2520b128a8e.tar.gz eclipse.platform.text-9f72014b1e1e1699b560e87257eed2520b128a8e.tar.xz eclipse.platform.text-9f72014b1e1e1699b560e87257eed2520b128a8e.zip |
#64327v20040527_1600
Diffstat (limited to 'org.eclipse.jface.text/src/org')
-rw-r--r-- | org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java | 50 |
1 files changed, 43 insertions, 7 deletions
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 5ddafcbce56..75ed7420715 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 @@ -13,6 +13,8 @@ package org.eclipse.jface.text.source; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -123,6 +125,36 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul } } + /** + * Pair of an annotation and their associated position. Used inside the paint method + * for sorting annotations based on the offset of their position. + * @since 3.0 + */ + private static class Tuple { + Annotation annotation; + Position position; + + Tuple(Annotation annotation, Position position) { + this.annotation= annotation; + this.position= position; + } + } + + /** + * Comparator for <code>Tuple</code>s. + * @since 3.0 + */ + private static class TupleComparator implements Comparator { + /* + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + public int compare(Object o1, Object o2) { + Position p1= ((Tuple) o1).position; + Position p2= ((Tuple) o2).position; + return p1.getOffset() - p2.getOffset(); + } + } + /** This column's parent ruler */ private CompositeRuler fParentRuler; /** The cached text viewer */ @@ -171,6 +203,11 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul */ private List fCachedAnnotations= new ArrayList(); /** + * The comparator for sorting annotations according to the offset of their position. + * @since 3.0 + */ + private Comparator fTupleComparator= new TupleComparator(); + /** * The hit detection cursor. * @since 3.0 */ @@ -715,16 +752,15 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul minLayer= Math.min(minLayer, lay); maxLayer= Math.max(maxLayer, lay); - fCachedAnnotations.add(annotation); + fCachedAnnotations.add(new Tuple(annotation, position)); } - + Collections.sort(fCachedAnnotations, fTupleComparator); + for (int layer= minLayer; layer <= maxLayer; layer++) { for (int i= 0, n= fCachedAnnotations.size(); i < n; i++) { - Annotation annotation= (Annotation) fCachedAnnotations.get(i); - - Position position= fModel.getPosition(annotation); - if (position == null) - continue; + Tuple tuple= (Tuple) fCachedAnnotations.get(i); + Annotation annotation= tuple.annotation; + Position position= tuple.position; int lay= IAnnotationAccessExtension.DEFAULT_LAYER; if (fAnnotationAccessExtension != null) |