JAL-3130 Replaced deprecated Class.newInstance() with Class.getDeclaredConstructor...
[jalview.git] / src / jalview / schemes / RNAHelicesColour.java
index 6448898..33b275d 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.schemes;
 
+import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
@@ -45,7 +46,7 @@ public class RNAHelicesColour extends ResidueColourScheme
    * Maps sequence positions to the RNA helix they belong to. Key: position,
    * Value: helix TODO: Revise or drop in favour of annotation position numbers
    */
-  public Hashtable<Integer, String> positionsToHelix = new Hashtable<Integer, String>();
+  public Hashtable<Integer, String> positionsToHelix = new Hashtable<>();
 
   /**
    * Number of helices in the RNA secondary structure
@@ -55,6 +56,14 @@ public class RNAHelicesColour extends ResidueColourScheme
   public AlignmentAnnotation annotation;
 
   /**
+   * Default constructor (required for ColourSchemes cache)
+   */
+  public RNAHelicesColour()
+  {
+
+  }
+
+  /**
    * Creates a new RNAHelicesColour object.
    */
   public RNAHelicesColour(AlignmentAnnotation annotation)
@@ -117,14 +126,14 @@ public class RNAHelicesColour extends ResidueColourScheme
   public void refresh()
   {
 
-    if (annotation != null
-            && ((annotation._rnasecstr == null || lastrefresh != annotation._rnasecstr
-                    .hashCode()) && annotation.isValidStruc()))
+    if (annotation != null && ((annotation._rnasecstr == null
+            || lastrefresh != annotation._rnasecstr.hashCode())
+            && annotation.isValidStruc()))
     {
       annotation.getRNAStruc();
       lastrefresh = annotation._rnasecstr.hashCode();
       numHelix = 0;
-      positionsToHelix = new Hashtable<Integer, String>();
+      positionsToHelix = new Hashtable<>();
 
       // Figure out number of helices
       // Length of rnasecstr is the number of pairs of positions that base pair
@@ -143,11 +152,11 @@ public class RNAHelicesColour extends ResidueColourScheme
         positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
                 this.annotation._rnasecstr[x].getFeatureGroup());
 
-        if (Integer.parseInt(this.annotation._rnasecstr[x]
-                .getFeatureGroup()) > numHelix)
+        if (Integer.parseInt(
+                this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
         {
-          numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
-                  .getFeatureGroup());
+          numHelix = Integer.parseInt(
+                  this.annotation._rnasecstr[x].getFeatureGroup());
         }
 
       }
@@ -198,10 +207,10 @@ public class RNAHelicesColour extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
-          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  public ColourSchemeI getInstance(AlignViewportI view,
+          AnnotatedCollectionI sg)
   {
-    return new RNAHelicesColour(this);
+    return new RNAHelicesColour(sg);
   }
 
   @Override
@@ -216,15 +225,14 @@ public class RNAHelicesColour extends ResidueColourScheme
   @Override
   public boolean isApplicableTo(AnnotatedCollectionI ac)
   {
-    AnnotatedCollectionI context = ac.getContext();
-    if (context == null)
-    {
-      context = ac;
-    }
-    if (context instanceof AlignmentI)
+    if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
     {
-      return ((AlignmentI) context).hasRNAStructure();
+      return true;
     }
+
+    /*
+     * not currently supporting this option for group annotation / colouring
+     */
     return false;
   }
 
@@ -233,4 +241,10 @@ public class RNAHelicesColour extends ResidueColourScheme
   {
     return JalviewColourScheme.RNAHelices.toString();
   }
+
+  @Override
+  public boolean isSimple()
+  {
+    return false;
+  }
 }