JAL-2360 ColourSchemes holds configured schemes, AlignFrame colour menu
[jalview.git] / src / jalview / schemes / AnnotationColourGradient.java
index 60a20fa..e3ef391 100755 (executable)
@@ -53,16 +53,18 @@ public class AnnotationColourGradient extends FollowerColourScheme
   private boolean predefinedColours = false;
 
   private boolean seqAssociated = false;
+
   /**
    * false if the scheme was constructed without a minColour and maxColour used
    * to decide if existing colours should be taken from annotation elements when
    * they exist
    */
   private boolean noGradient = false;
+
   IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
     AnnotationColourGradient acg = new AnnotationColourGradient(annotation,
@@ -114,6 +116,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
     bb = 0;
 
     noGradient = true;
+    checkLimits();
   }
 
   /**
@@ -140,10 +143,17 @@ public class AnnotationColourGradient extends FollowerColourScheme
     bb = maxColour.getBlue() - b1;
 
     noGradient = false;
+    checkLimits();
+  }
+
+  private void checkLimits()
+  {
     aamax = annotation.graphMax;
     aamin = annotation.graphMin;
     if (annotation.isRNA())
     {
+      // reset colour palette
+      ColourSchemeProperty.resetRnaHelicesShading();
       ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax);
     }
   }
@@ -167,7 +177,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
       // resolve the context containing all the annotation for the sequence
       AnnotatedCollectionI alcontext = alignment instanceof AlignmentI ? alignment
               : alignment.getContext();
-      boolean f = true,rna=false;
+      boolean f = true, rna = false;
       for (AlignmentAnnotation alan : alcontext.findAnnotation(annotation
               .getCalcId()))
       {
@@ -193,13 +203,13 @@ public class AnnotationColourGradient extends FollowerColourScheme
       }
       if (rna)
       {
-        ColourSchemeProperty.resetRnaHelicesShading();
         ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax);
       }
     }
   }
 
   float aamin = 0f, aamax = 0f;
+
   public String getAnnotation()
   {
     return annotation.label;
@@ -240,6 +250,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Color findColour(char c)
   {
     return Color.red;
@@ -259,8 +270,8 @@ public class AnnotationColourGradient extends FollowerColourScheme
   public Color findColour(char c, int j, SequenceI seq)
   {
     Color currentColour = Color.white;
-    AlignmentAnnotation annotation = (seqAssociated && seqannot!=null ? seqannot.get(seq)
-            : this.annotation);
+    AlignmentAnnotation annotation = (seqAssociated && seqannot != null ? seqannot
+            .get(seq) : this.annotation);
     if (annotation == null)
     {
       return currentColour;
@@ -389,6 +400,7 @@ public class AnnotationColourGradient extends FollowerColourScheme
     return new Color(dr, dg, db);
 
   }
+
   public boolean isPredefinedColours()
   {
     return predefinedColours;
@@ -408,4 +420,10 @@ public class AnnotationColourGradient extends FollowerColourScheme
   {
     seqAssociated = sassoc;
   }
+
+  @Override
+  public String getSchemeName()
+  {
+    return "Annotation";
+  }
 }