JAL-2228 base interface for FeatureCounters and factory constructors for FeatureSetCo...
authorJim Procter <jprocter@issues.jalview.org>
Sun, 25 Sep 2016 09:47:00 +0000 (10:47 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 25 Sep 2016 09:47:00 +0000 (10:47 +0100)
src/jalview/workers/AlignmentAnnotationFactory.java
src/jalview/workers/FeatureCounterI.java

index 2b7d9e1..8a86ce0 100644 (file)
@@ -8,6 +8,7 @@ import jalview.datamodel.Annotation;
 import jalview.gui.AlignFrame;
 
 import java.awt.Color;
+import java.lang.reflect.Method;
 
 /**
  * Factory class with methods which allow clients (including external scripts
@@ -28,15 +29,48 @@ public class AlignmentAnnotationFactory
    * @param counter
    *          provider of feature counts per alignment position
    */
-  public static void newCalculator(FeatureCounterI counter)
+  public static void newCalculator(ColumnCounterI counter)
   {
     // TODO need an interface for AlignFrame by which to access
     // its AlignViewportI and AlignmentViewPanel
     AlignmentViewPanel currentAlignFrame = Jalview.getCurrentAlignFrame().alignPanel;
     if (currentAlignFrame != null)
     {
-      newCalculator(currentAlignFrame.getAlignViewport(),
-              currentAlignFrame, counter);
+      Method newCalcMethod = null;
+      try
+      {
+        for (Method m : AlignmentAnnotationFactory.class.getMethods())
+        {
+          if (m.getName().equals("newCalculator"))
+          {
+            if (m.getParameterCount() == 3
+                    && m.getParameterTypes()[2].isInstance(counter))
+            {
+              newCalcMethod = m;
+              break;
+            }
+          }
+        }
+      } catch (Exception q)
+      {
+      }
+      if (newCalcMethod == null)
+      {
+
+        System.err
+                .println("Couldn't find a newCalculator method for ColumnCounterI type "
+                        + counter.getClass().getName());
+      }
+      try
+      {
+        newCalcMethod.invoke(null, currentAlignFrame.getAlignViewport(),
+                currentAlignFrame, counter);
+      } catch (Exception ie)
+      {
+        System.err
+                .println("Exception when reporting newCalculator method for ColumnCounterI type "
+                        + counter.getClass().getName());
+      }
     }
     else
     {
@@ -60,6 +94,21 @@ public class AlignmentAnnotationFactory
   }
 
   /**
+   * Constructs and registers a new alignment annotation worker for a set of
+   * column counters
+   * 
+   * @param viewport
+   * @param panel
+   * @param counter
+   *          provider of feature counts per alignment position
+   */
+  public static void newCalculator(AlignViewportI viewport,
+          AlignmentViewPanel panel, FeatureSetCounterI counter)
+  {
+    new ColumnCounterSetWorker(viewport, panel, counter);
+  }
+
+  /**
    * Constructs and registers a new alignment annotation worker
    * 
    * @param calculator
@@ -69,7 +118,7 @@ public class AlignmentAnnotationFactory
   {
     // TODO need an interface for AlignFrame by which to access
     // its AlignViewportI and AlignmentViewPanel
-    AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame() ;
+    AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame();
     if (currentAlignFrame != null)
     {
       newCalculator(currentAlignFrame.getViewport(), currentAlignFrame
@@ -91,8 +140,7 @@ public class AlignmentAnnotationFactory
    *          provider of AlignmentAnnotation for the alignment
    */
   public static void newCalculator(AlignViewportI viewport,
-          AlignmentViewPanel panel,
-          AnnotationProviderI calculator)
+          AlignmentViewPanel panel, AnnotationProviderI calculator)
   {
     new AnnotationWorker(viewport, panel, calculator);
   }
index aa4a283..153f89f 100644 (file)
@@ -10,7 +10,7 @@ import java.util.List;
  * features present at that position
  * 
  */
-public interface FeatureCounterI
+public interface FeatureCounterI extends ColumnCounterI
 {
   /**
    * Returns a count of some property of interest, for example