From: Jim Procter Date: Sun, 25 Sep 2016 09:47:00 +0000 (+0100) Subject: JAL-2228 base interface for FeatureCounters and factory constructors for FeatureSetCo... X-Git-Tag: Release_2_10_2~3^2~93^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=32c324c89959217982ef49bbf68bf198fa30f785;p=jalview.git JAL-2228 base interface for FeatureCounters and factory constructors for FeatureSetCounterI --- diff --git a/src/jalview/workers/AlignmentAnnotationFactory.java b/src/jalview/workers/AlignmentAnnotationFactory.java index 2b7d9e1..8a86ce0 100644 --- a/src/jalview/workers/AlignmentAnnotationFactory.java +++ b/src/jalview/workers/AlignmentAnnotationFactory.java @@ -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); } diff --git a/src/jalview/workers/FeatureCounterI.java b/src/jalview/workers/FeatureCounterI.java index aa4a283..153f89f 100644 --- a/src/jalview/workers/FeatureCounterI.java +++ b/src/jalview/workers/FeatureCounterI.java @@ -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