JAL-1421 typed map / lists, explicit imports, method refactoring
[jalview.git] / src / jalview / viewmodel / seqfeatures / FeatureRendererModel.java
index e912720..848f565 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.viewmodel.seqfeatures;
 
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
 import jalview.api.FeaturesDisplayedI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceFeature;
@@ -58,7 +59,7 @@ public abstract class FeatureRendererModel implements
   protected Object currentColour;
 
   /*
-   * ordering of rendering, where last means on top
+   * feature types in ordering of rendering, where last means on top
    */
   protected String[] renderOrder;
 
@@ -67,6 +68,12 @@ public abstract class FeatureRendererModel implements
 
   protected AlignmentViewport av;
 
+  /*
+   * map holds per feature type, {{min, max}, {min, max}} feature score
+   * values for positional and non-positional features respectively
+   */
+  private Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
+
   @Override
   public AlignViewportI getViewport()
   {
@@ -193,9 +200,7 @@ public abstract class FeatureRendererModel implements
     renderOrder = neworder;
   }
 
-  protected Hashtable minmax = new Hashtable();
-
-  public Hashtable getMinMax()
+  public Map<String, float[][]> getMinMax()
   {
     return minmax;
   }
@@ -209,7 +214,7 @@ public abstract class FeatureRendererModel implements
    */
   protected final byte[] normaliseScore(SequenceFeature sequenceFeature)
   {
-    float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0];
+    float[] mm = minmax.get(sequenceFeature.type)[0];
     final byte[] r = new byte[] { 0, (byte) 255 };
     if (mm != null)
     {
@@ -340,7 +345,7 @@ public abstract class FeatureRendererModel implements
     }
     if (minmax == null)
     {
-      minmax = new Hashtable();
+      minmax = new Hashtable<String, float[][]>();
     }
     AlignmentI alignment = av.getAlignment();
     for (int i = 0; i < alignment.getHeight(); i++)
@@ -395,7 +400,7 @@ public abstract class FeatureRendererModel implements
         if (!Float.isNaN(features[index].score))
         {
           int nonpos = features[index].getBegin() >= 1 ? 0 : 1;
-          float[][] mm = (float[][]) minmax.get(features[index].getType());
+          float[][] mm = minmax.get(features[index].getType());
           if (mm == null)
           {
             mm = new float[][] { null, null };
@@ -632,9 +637,18 @@ public abstract class FeatureRendererModel implements
     // Object c = featureColours.get(featureType);
     // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
     // !((GraduatedColor)c).getMaxColor().equals(_col)))
+    if (col instanceof FeatureColourI)
     {
-      featureColours.put(featureType, col);
+      if (((FeatureColourI) col).isGraduatedColour())
+      {
+        col = new GraduatedColor((FeatureColourI) col);
+      }
+      else
+      {
+        col = ((FeatureColourI) col).getColour();
+      }
     }
+      featureColours.put(featureType, col);
   }
 
   public void setTransparency(float value)
@@ -809,7 +823,7 @@ public abstract class FeatureRendererModel implements
     changeSupport.removePropertyChangeListener(listener);
   }
 
-  public Set getAllFeatureColours()
+  public Set<String> getAllFeatureColours()
   {
     return featureColours.keySet();
   }