JAL-896 - patch to ensure arrows in different directions are visually
authorjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 4 Aug 2011 18:01:18 +0000 (19:01 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 4 Aug 2011 18:01:18 +0000 (19:01 +0100)
distinct. Raises new bug - JAL-897 - test with RF00011 to demonstrate
problem.

src/jalview/gui/AnnotationPanel.java

index 050e9f2..827540a 100755 (executable)
@@ -1057,8 +1057,17 @@ public class AnnotationPanel extends JPanel implements MouseListener,
         }
         if (row.hasIcons)
         {
+          char ss=row.annotations[column].secondaryStructure;
+          if (ss=='S')
+          {
+            // distinguish between forward/backward base-pairing
+            if (row.annotations[column].displayCharacter.indexOf(')')>-1)
+            {
+              ss='s';
+            }
+          }
           if (!validRes
-                  || (row.annotations[column].secondaryStructure != lastSS))
+                  || (ss != lastSS))
           {
             if (x > -1)
             {
@@ -1075,6 +1084,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                 break;
 
               case 'S': // Stem case for RNA secondary structure
+              case 's': // and opposite direction
                 drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
                         column, validRes, validEnd);
                 break;
@@ -1089,7 +1099,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
             }
             if (validRes)
             {
-              lastSS = row.annotations[column].secondaryStructure;
+              lastSS = ss;
             }
             else
             {
@@ -1131,6 +1141,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
           drawSheetAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
                   column, validRes, validEnd);
           break;
+        case 's':
         case 'S': // Stem case for RNA secondary structure
           drawStemAnnot(g, row, lastSSX, x, y, iconOffset, startRes,
                   column, validRes, validEnd);
@@ -1211,42 +1222,55 @@ public class AnnotationPanel extends JPanel implements MouseListener,
           int lastSSX, int x, int y, int iconOffset, int startRes,
           int column, boolean validRes, boolean validEnd)
   {
-    g.setColor(STEM_COLOUR); 
+    g.setColor(STEM_COLOUR);
     int sCol = (lastSSX / av.charWidth) + startRes;
     int x1 = lastSSX;
     int x2 = (x * av.charWidth);
     Regex closeparen = new Regex("(\\))");
-
-    String dc="";
+    
+    String dc = column==0 ? "" : row.annotations[column - 1].displayCharacter;
+    
+    boolean diffupstream=sCol == 0 || row.annotations[sCol - 1] == null
+            || !dc.equals(row.annotations[sCol - 1].displayCharacter);
+    boolean diffdownstream=!validRes || !validEnd || row.annotations[column] == null
+            || !dc.equals(row.annotations[column].displayCharacter);
+    System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
     // If a closing base pair half of the stem, display a backward arrow
-    if (column>0 && closeparen.search(dc=row.annotations[column - 1].displayCharacter))
+    if (column > 0
+            && closeparen
+                    .search(dc))
     {
-      if (sCol == 0 || row.annotations[sCol - 1] == null
-              || !dc.equals(row.annotations[sCol - 1].displayCharacter))
-      //if (validRes && column>1 && row.annotations[column-2]!=null && dc.equals(row.annotations[column-2].displayCharacter))
-      {      g.fillPolygon(new int[]
-      { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
-      { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
-      x1+=5;
+      if (diffupstream)
+      // if (validRes && column>1 && row.annotations[column-2]!=null &&
+      // dc.equals(row.annotations[column-2].displayCharacter))
+      {
+        g.fillPolygon(new int[]
+        { lastSSX + 5, lastSSX + 5, lastSSX }, new int[]
+        { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
+        x1 += 5;
+      }
+      if (diffdownstream)
+      {
+        x2-=1;
       }
     }
     else
     {
       // display a forward arrow
-      if (!validRes  || row.annotations[column] == null
-              || !dc.equals(row.annotations[column].displayCharacter))
+      if (diffdownstream)
       {
-      g.fillPolygon(
-              new int[]
-              { x2 - 5, x2 - 5,
-                  x2 }, new int[]
-              { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset },
-              3);
-      x2-=5;
+        g.fillPolygon(new int[]
+        { x2 - 5, x2 - 5, x2 }, new int[]
+        { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3);
+        x2 -= 5;
+      }
+      if (diffupstream)
+      {
+        x1+=1;
       }
     }
     // draw arrow body
-    g.fillRect(x1, y + 4 + iconOffset, x2-x1, 7);
+    g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7);
   }
 
   private void drawGlyphLine(Graphics g, AlignmentAnnotation row,