Merge branch 'develop' into spike/matrix_annot
[jalview.git] / src / jalview / renderer / AnnotationRenderer.java
index adcedcb..f5562d7 100644 (file)
@@ -28,9 +28,13 @@ import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.Profile;
+import jalview.datamodel.ProfilesI;
+import jalview.renderer.api.AnnotationRendererFactoryI;
+import jalview.renderer.api.AnnotationRowRendererI;
 import jalview.schemes.ColourSchemeI;
+import jalview.schemes.NucleotideColourScheme;
 import jalview.schemes.ResidueProperties;
+import jalview.schemes.ZappoColourScheme;
 import jalview.util.Platform;
 
 import java.awt.BasicStroke;
@@ -70,11 +74,11 @@ public class AnnotationRenderer
   boolean av_renderHistogram = true, av_renderProfile = true,
           av_normaliseProfile = false;
 
-  ColourSchemeI profcolour = null;
+  ResidueShaderI profcolour = null;
 
   private ColumnSelection columnSelection;
 
-  private Profile[] hconsensus;
+  private ProfilesI hconsensus;
 
   private Hashtable[] complementConsensus;
 
@@ -150,6 +154,7 @@ public class AnnotationRenderer
     hStrucConsensus = null;
     fadedImage = null;
     annotationPanel = null;
+    rendererFactoryI = null;
   }
 
   void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
@@ -299,6 +304,7 @@ public class AnnotationRenderer
       useClip = false;
     }
 
+    rendererFactoryI = AnnotationRendererFactory.getRendererFactory();
     updateFromAlignViewport(av);
   }
 
@@ -312,13 +318,17 @@ public class AnnotationRenderer
     av_renderHistogram = av.isShowConsensusHistogram();
     av_renderProfile = av.isShowSequenceLogo();
     av_normaliseProfile = av.isNormaliseSequenceLogo();
-    profcolour = av.getGlobalColourScheme();
-    if (profcolour == null)
+    profcolour = av.getResidueShading();
+    if (profcolour == null || profcolour.getColourScheme() == null)
     {
-      // Set the default colour for sequence logo if the alignnent has no
-      // colourscheme set
-      profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
-              : new jalview.schemes.ZappoColourScheme();
+      /*
+       * Use default colour for sequence logo if 
+       * the alignment has no colourscheme set
+       * (would like to use user preference but n/a for applet)
+       */
+      ColourSchemeI col = av.getAlignment().isNucleotide() ? new NucleotideColourScheme()
+              : new ZappoColourScheme();
+      profcolour = new ResidueShader(col);
     }
     columnSelection = av.getColumnSelection();
     hconsensus = av.getSequenceConsensusHash();
@@ -352,7 +362,7 @@ public class AnnotationRenderer
       {
         // TODO? group consensus for cDNA complement
         return AAFrequency.extractProfile(
-                aa.groupRef.consensusData[column],
+                aa.groupRef.consensusData.get(column),
                 aa.groupRef.getIgnoreGapsConsensus());
       }
       // TODO extend annotation row to enable dynamic and static profile data to
@@ -366,7 +376,7 @@ public class AnnotationRenderer
         }
         else
         {
-          return AAFrequency.extractProfile(hconsensus[column],
+          return AAFrequency.extractProfile(hconsensus.get(column),
                   av_ignoreGapsConsensus);
         }
       }
@@ -400,6 +410,8 @@ public class AnnotationRenderer
 
   boolean rna = false;
 
+  private AnnotationRendererFactoryI rendererFactoryI;
+
   /**
    * Render the annotation rows associated with an alignment.
    * 
@@ -1033,6 +1045,32 @@ public class AnnotationRenderer
                     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);
+            }
+            if (debugRedraw)
+            {
+              if (renderer == null)
+              {
+                System.err.println("No renderer found for "
+                        + row.toString());
+              }
+              else
+              {
+                System.err.println("rendered with "
+                        + renderer.getClass().toString());
+              }
+            }
+
+          }
         }
       }
       else