uima-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r808425 - in /incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor: annotation/BackgroundDrawingStrategy.java util/Span.java
Date Thu, 27 Aug 2009 14:18:59 GMT
Author: joern
Date: Thu Aug 27 14:18:58 2009
New Revision: 808425

URL: http://svn.apache.org/viewvc?rev=808425&view=rev
Log:
UIMA-1408 Annotation highlightning does not work with background drawing strategy

Modified:
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/annotation/BackgroundDrawingStrategy.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/util/Span.java

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/annotation/BackgroundDrawingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/annotation/BackgroundDrawingStrategy.java?rev=808425&r1=808424&r2=808425&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/annotation/BackgroundDrawingStrategy.java
(original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/annotation/BackgroundDrawingStrategy.java
Thu Aug 27 14:18:58 2009
@@ -19,11 +19,18 @@
 
 package org.apache.uima.caseditor.editor.annotation;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.caseditor.editor.util.Span;
 import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy;
+import org.eclipse.swt.custom.StyleRange;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 
 /**
@@ -44,18 +51,81 @@
           Color color) {
     if (length != 0) {
       if (gc != null) {
-        Rectangle bounds = textWidget.getTextBounds(offset, offset + length - 1);
-
+    	int annotationBegin = offset;
+    	int annotationEnd = offset + length;
+    	  
+        Rectangle bounds = textWidget.getTextBounds(annotationBegin, annotationEnd - 1);
+
+        // Selection in the text widget are drawn before the annotation are drawn,
+        // to make a selection visible the selection is redrawn over the background
+        // rectangle
+        //
+        //
+        // The annotation background to be drawn is a span which has a begin and end offset.
+        // Inside the background are areas (spans) which should not be over drawn. 
+        // That can be visualized like this:
+        //
+        // zzzzXXXzzzzXXXXzzzXX
+        //
+        // The z offsets should be drawn, the X offsets should not be overdrawn. That is
solved
+        // by drawing for every z offset area one background rectangle.
+        
+        List<Span> dontOverDrawSpans = new ArrayList<Span>();
+        
+        Span annotationSpan = new Span(offset, length);
+        
+        // add all style ranges to the list in the range of the annotation
+        for (StyleRange styleRange : textWidget.getStyleRanges(offset, length)) {
+        	Span styleRangeSpan = new Span(styleRange.start, styleRange.length);
+        	if (styleRangeSpan.getLength() > 0)
+        	    dontOverDrawSpans.add(styleRangeSpan);
+        }
+        
+        // add text selection to the list if intersects with annotation
+        Point selection = textWidget.getSelection();
+        Span selectionSpan = new Span(selection.x, selection.y - selection.x);
+        if (annotationSpan.isIntersecting(selectionSpan) && selectionSpan.getLength()
> 0) {
+          dontOverDrawSpans.add(selectionSpan);
+        }
+        
+        Collections.sort(dontOverDrawSpans);
+        // TODO: Asks on mailing list for help ...
+        // strange that we need that here ...
+        Collections.reverse(dontOverDrawSpans); 
+        
         gc.setBackground(color);
-        gc.fillRectangle(bounds);
-
+        
+        if (dontOverDrawSpans.size() > 0) {
+	        int zBegin = offset;
+	    	for (Span xSpan : dontOverDrawSpans) {
+	    	  if (xSpan.getLength()> 0 && zBegin < xSpan.getStart()) {
+	    		  Rectangle selectionBounds = textWidget.getTextBounds(zBegin, xSpan.getStart() -1);
+	    		  gc.fillRectangle(selectionBounds);
+	    	   }
+	    	  
+	    	  if (zBegin < xSpan.getEnd())
+	    	      zBegin = xSpan.getEnd(); 
+	    	}
+	    	
+	    	// If the annotation ends with z offsets these must still be drawn
+	    	if (zBegin < annotationEnd) {
+	    		  Rectangle selectionBounds = textWidget.getTextBounds(zBegin, annotationEnd -1);
+	    		  gc.fillRectangle(selectionBounds);
+	    	}
+        }
+        else {
+  		  Rectangle selectionBounds = textWidget.getTextBounds(annotationBegin, annotationEnd
-1);
+		  gc.fillRectangle(selectionBounds);
+        }
+        
         int start = offset;
         int end = offset + length - 1;
 
         gc.setForeground(new Color(gc.getDevice(), 0, 0, 0));
-
+        
         gc.drawText(textWidget.getText(start, end), bounds.x, bounds.y, true);
-      } else {
+      } 
+      else {
         textWidget.redrawRange(offset, length, true);
       }
     }

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/util/Span.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/util/Span.java?rev=808425&r1=808424&r2=808425&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/util/Span.java
(original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/util/Span.java
Thu Aug 27 14:18:58 2009
@@ -20,7 +20,7 @@
 package org.apache.uima.caseditor.editor.util;
 
 /**
- * This class usually specifies an continus are of text. This area has an start and end index.
The
+ * This class usually specifies an continous are of text. This area has an start and end
index. The
  * difference of the end and start is the length of the area.
  */
 public class Span implements Comparable<Span> {
@@ -93,6 +93,13 @@
     return true;
   }
 
+  public boolean isIntersecting(Span s) {
+    int sstart = s.getStart();
+    return this.isContaining(s) || s.isContaining(this) ||
+	   getStart() <= sstart && sstart < getEnd() ||
+	   sstart <= getStart() && getStart() < s.getEnd();
+  }
+  
   /**
    * Compares the current instance to another {@link Span} object.
    */



Mime
View raw message