JAL-2348 contact map renderer refactored from hacked version of matrix row renderer
[jalview.git] / src / jalview / renderer / AnnotationRenderer.java
index 5083ac8..096c6a7 100644 (file)
@@ -29,6 +29,8 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.ProfilesI;
+import jalview.renderer.api.AnnotationRendererFactoryI;
+import jalview.renderer.api.AnnotationRowRendererI;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 import jalview.util.Platform;
@@ -150,6 +152,7 @@ public class AnnotationRenderer
     hStrucConsensus = null;
     fadedImage = null;
     annotationPanel = null;
+    rendererFactoryI = null;
   }
 
   void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
@@ -400,6 +403,8 @@ public class AnnotationRenderer
 
   boolean rna = false;
 
+  private AnnotationRendererFactoryI rendererFactoryI;
+
   /**
    * Render the annotation rows associated with an alignment.
    * 
@@ -1029,17 +1034,22 @@ public class AnnotationRenderer
           }
           else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
           {
-            if (row.autoCalculated && row.label != null
-                    && row.label.startsWith("Consen"))
-            {
-              drawProfileDensity(g, row, row_annotations, startRes, endRes,
-                      row.graphMin, row.graphMax, y);
-            }
-            else
-            {
             drawBarGraph(g, row, row_annotations, startRes, endRes,
                     row.graphMin, row.graphMax, y, renderHistogram,
                     renderProfile, normaliseProfile);
+          }
+          else
+          {
+            AnnotationRowRendererI renderer = rendererFactoryI
+                    .getRendererFor(row);
+            if (renderer != null)
+            {
+              renderer.renderRow(g, charWidth, charHeight,
+                      hasHiddenColumns, av, columnSelection, row,
+                      row_annotations, startRes, endRes, row.graphMin,
+                      row.graphMax, y);
+              System.err.println("rendered with "
+                      + renderer.getClass().toString());
             }
           }
         }
@@ -1627,129 +1637,4 @@ public class AnnotationRenderer
 
     }
   }
-
-  void drawProfileDensity(Graphics g, AlignmentAnnotation _aa,
-          Annotation[] aa_annotations, int sRes, int eRes, float min,
-          float max, int y)
-  {
-    if (sRes > aa_annotations.length)
-    {
-      return;
-    }
-    Font ofont = g.getFont();
-    eRes = Math.min(eRes, aa_annotations.length);
-
-    int x = 0, y2 = y;
-
-
-
-    g.setColor(Color.pink);
-
-    g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
-
-    int column;
-    int aaMax = aa_annotations.length - 1;
-    while (x < eRes - sRes)
-    {
-      column = sRes + x;
-      if (hasHiddenColumns)
-      {
-        column = columnSelection.adjustForHiddenColumns(column);
-      }
-
-      if (column > aaMax)
-      {
-        break;
-      }
-
-      if (aa_annotations[column] == null)
-      {
-        x++;
-        continue;
-      }
-      if (aa_annotations[column].colour == null)
-      {
-        g.setColor(Color.black);
-      }
-      else
-      {
-        g.setColor(aa_annotations[column].colour);
-      }
-
-
-      /*
-       * {profile type, #values, total count, char1, pct1, char2, pct2...}
-       */
-      int profl[] = getProfileFor(_aa, column);
-
-      // just try to draw the logo if profl is not null
-      if (profl != null && profl[2] != 0)
-      {
-        boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
-        boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
-        float ht = y2; // - _aa.graphHeight;
-        char[] dc;
-
-        /**
-         * Render a single base for a sequence profile, a base pair for
-         * structure profile, and a triplet for a cdna profile
-         */
-        dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
-
-        double scale = _aa.graphHeight / (profl[1]);
-
-        /*
-         * Traverse the character(s)/percentage data in the array
-         */
-        int c = 3;
-        int valuesProcessed = 0;
-        // profl[1] is the number of values in the profile
-
-        while (valuesProcessed < profl[1])
-        {
-          if (isStructureProfile)
-          {
-            // todo can we encode a structure pair as an int, like codons?
-            dc[0] = (char) profl[c++];
-            dc[1] = (char) profl[c++];
-          }
-          else if (isCdnaProfile)
-          {
-            dc = CodingUtils.decodeCodon(profl[c++]);
-          }
-          else
-          {
-            dc[0] = (char) profl[c++];
-          }
-
-          ht -= scale;
-          // next profl[] position is profile % for the character(s)
-          // render boxes
-          g.setColor(jalview.util.ColorUtils.getGraduatedColour(profl[c++],
-                  0f, Color.gray, 100, Color.blue));
-          // g.setColor(profcolour.findColour(dc[0]).darker());
-
-          g.fillRect(x * charWidth, (int) ht, charWidth, (int) scale);
-          valuesProcessed++;
-        }
-        g.setFont(ofont);
-      }
-      x++;
-
-    }
-
-    // if (_aa.threshold != null)
-    // {
-    // g.setColor(_aa.threshold.colour);
-    // Graphics2D g2 = (Graphics2D) g;
-    // g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
-    // BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
-    //
-    // y2 = (int) (y - ((_aa.threshold.value - min) / range)
-    // * _aa.graphHeight);
-    // g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
-    // g2.setStroke(new BasicStroke());
-    // }
-  }
-
 }