v2
[jalview.git] / src / jalview / renderer / AnnotationRenderer.java
index 96b433d..8694ecd 100644 (file)
@@ -34,6 +34,7 @@ public class AnnotationRenderer
           int lastSSX, int x, int y, int iconOffset, int startRes,
           int column, boolean validRes, boolean validEnd)
   {
+       
     g.setColor(STEM_COLOUR);
     int sCol = (lastSSX / charWidth) + startRes;
     int x1 = lastSSX;
@@ -52,6 +53,7 @@ public class AnnotationRenderer
     // If a closing base pair half of the stem, display a backward arrow
     if (column > 0 && closeparen.search(dc))
     {
+       
       if (diffupstream)
       // if (validRes && column>1 && row_annotations[column-2]!=null &&
       // dc.equals(row_annotations[column-2].displayCharacter))
@@ -68,6 +70,7 @@ public class AnnotationRenderer
     }
     else
     {
+       
       // display a forward arrow
       if (diffdownstream)
       {
@@ -125,6 +128,64 @@ public class AnnotationRenderer
    */
   private int imgWidth;
 
+  
+  public void drawNotCanonicalAnnot(Graphics g, Annotation[] row_annotations,
+          int lastSSX, int x, int y, int iconOffset, int startRes,
+          int column, boolean validRes, boolean validEnd)
+  {
+       
+    g.setColor(NOTCANONICAL_COLOUR);
+    int sCol = (lastSSX / charWidth) + startRes;
+    int x1 = lastSSX;
+    int x2 = (x * charWidth);
+    Regex closeparen = new Regex("(}|]|a|b|c|d)");
+    
+    String dc = (column == 0 || row_annotations[column - 1] == null) ? ""
+            : 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))//  closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) )
+    {
+       
+      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 (diffdownstream)
+      {
+        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);
+  }
   // public void updateFromAnnotationPanel(FontMetrics annotFM, AlignViewportI
   // av)
   public void updateFromAwtRenderPanel(AwtRenderPanelI annotPanel,
@@ -212,20 +273,25 @@ public class AnnotationRenderer
   }
 
   /**
-   * DOCUMENT ME!
-   *
-   * @param annotationPanel
-   *          TODO
+   * Render the annotation rows associated with an alignment.
+   * @param annotPanel
+   *          container frame
+   * @param av
+   *          data and view settings to render
    * @param g
-   *          DOCUMENT ME!
+   *          destination for graphics
+   * @param activeRow
+   *          row where a mouse event occured (or -1)
    * @param startRes
-   *          DOCUMENT ME!
+   *          first column that will be drawn
    * @param endRes
-   *          DOCUMENT ME!
+   *          last column that will be drawn
+   * @return true if the fadedImage was used for any alignment annotation rows currently being calculated
    */
-  public void drawComponent(AwtRenderPanelI annotPanel, AlignViewportI av,
+  public boolean drawComponent(AwtRenderPanelI annotPanel, AlignViewportI av,
           Graphics g, int activeRow, int startRes, int endRes)
   {
+    boolean usedFaded=false;
     // NOTES:
     // AnnotationPanel needs to implement: ImageObserver, access to
     // AlignViewport
@@ -289,10 +355,10 @@ public class AnnotationRenderer
         iconOffset = 0;
       }
 
-      if (aa[i].autoCalculated && av.isCalculationInProgress(aa[i]))
+      if (row.autoCalculated && av.isCalculationInProgress(row))
       {
         y += charHeight;
-
+        usedFaded=true;
         g.drawImage(fadedImage, 0, y - row.height, imgWidth, y, 0, y
                 - row.height, imgWidth, y, annotationPanel);
         g.setColor(Color.black);
@@ -436,12 +502,22 @@ public class AnnotationRenderer
         {
           char ss = validRes ? row_annotations[column].secondaryStructure
                   : ' ';
+          
           if (ss == 'S')
           {
             // distinguish between forward/backward base-pairing
             if (row_annotations[column].displayCharacter.indexOf(')') > -1)
             {
               ss = 's';
+              
+            }
+          }
+           if (ss == 'C')
+          {
+            if ((row_annotations[column].displayCharacter.indexOf(']') > -1) || (row_annotations[column].displayCharacter.indexOf('}') > -1))
+            {
+                ss = 'c';
+                
             }
           }
           if (!validRes || (ss != lastSS))
@@ -465,7 +541,11 @@ public class AnnotationRenderer
                 drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
                         column, validRes, validEnd);
                 break;
-
+              case 'C':
+              case 'c':
+                 drawNotCanonicalAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
+                          column, validRes, validEnd);
+                 break;
               default:
                 g.setColor(Color.gray);
                 g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth)
@@ -530,6 +610,11 @@ public class AnnotationRenderer
           drawStemAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
                   column, validRes, validEnd);
           break;
+        case 'c':
+        case 'C': 
+         drawNotCanonicalAnnot(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
+                    column, validRes, validEnd);
+         break;
         default:
           drawGlyphLine(g, row_annotations, lastSSX, x, y, iconOffset, startRes,
                   column, validRes, validEnd);
@@ -600,6 +685,7 @@ public class AnnotationRenderer
         y += aa[i].height;
       }
     }
+    return !usedFaded;
   }
 
   private final Color GLYPHLINE_COLOR = Color.gray;
@@ -609,6 +695,8 @@ public class AnnotationRenderer
   private final Color HELIX_COLOUR = Color.red;
 
   private final Color STEM_COLOUR = Color.blue;
+  
+  private final Color NOTCANONICAL_COLOUR = Color.red;
 
   public void drawGlyphLine(Graphics g, Annotation[] row,
           int lastSSX, int x, int y, int iconOffset, int startRes,
@@ -619,6 +707,7 @@ public class AnnotationRenderer
   }
 
   public void drawSheetAnnot(Graphics g, Annotation[] row,
+
           int lastSSX, int x, int y, int iconOffset, int startRes,
           int column, boolean validRes, boolean validEnd)
   {