1 package jalview.workers;
3 import jalview.api.AlignViewportI;
4 import jalview.api.AlignmentViewPanel;
5 import jalview.bin.Jalview;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.Annotation;
8 import jalview.gui.AlignFrame;
10 import java.awt.Color;
11 import java.lang.reflect.Method;
14 * Factory class with methods which allow clients (including external scripts
15 * such as Groovy) to 'register and forget' an alignment annotation calculator. <br>
16 * Currently supports two flavours of calculator:
18 * <li>a simple 'feature counter' which counts any desired score derivable from
19 * residue value and any sequence features at each position of the alignment</li>
20 * <li>a 'general purpose' calculator which computes one or more complete
21 * AlignmentAnnotation objects</li>
24 public class AlignmentAnnotationFactory
27 * Constructs and registers a new alignment annotation worker
30 * provider of feature counts per alignment position
32 public static void newCalculator(ColumnCounterI counter)
34 // TODO need an interface for AlignFrame by which to access
35 // its AlignViewportI and AlignmentViewPanel
36 AlignmentViewPanel currentAlignFrame = Jalview.getCurrentAlignFrame().alignPanel;
37 if (currentAlignFrame != null)
39 Method newCalcMethod = null;
42 for (Method m : AlignmentAnnotationFactory.class.getMethods())
44 if (m.getName().equals("newCalculator"))
46 if (m.getParameterTypes().length == 3
47 && m.getParameterTypes()[2].isInstance(counter))
57 if (newCalcMethod == null)
61 .println("Couldn't find a newCalculator method for ColumnCounterI type "
62 + counter.getClass().getName());
66 newCalcMethod.invoke(null, currentAlignFrame.getAlignViewport(),
67 currentAlignFrame, counter);
68 } catch (Exception ie)
71 .println("Exception when reporting newCalculator method for ColumnCounterI type "
72 + counter.getClass().getName());
78 .println("Can't register calculator as no alignment window has focus");
83 * Constructs and registers a new alignment annotation worker
88 * provider of feature counts per alignment position
90 public static void newCalculator(AlignViewportI viewport,
91 AlignmentViewPanel panel, FeatureCounterI counter)
93 new ColumnCounterWorker(viewport, panel, counter);
97 * Constructs and registers a new alignment annotation worker for a set of
103 * provider of feature counts per alignment position
105 public static void newCalculator(AlignViewportI viewport,
106 AlignmentViewPanel panel, FeatureSetCounterI counter)
108 new ColumnCounterSetWorker(viewport, panel, counter);
112 * Constructs and registers a new alignment annotation worker
115 * provider of AlignmentAnnotation for the alignment
117 public static void newCalculator(AnnotationProviderI calculator)
119 // TODO need an interface for AlignFrame by which to access
120 // its AlignViewportI and AlignmentViewPanel
121 AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame();
122 if (currentAlignFrame != null)
124 newCalculator(currentAlignFrame.getViewport(), currentAlignFrame
125 .getAlignPanels().get(0), calculator);
130 .println("Can't register calculator as no alignment window has focus");
135 * Constructs and registers a new alignment annotation worker
140 * provider of AlignmentAnnotation for the alignment
142 public static void newCalculator(AlignViewportI viewport,
143 AlignmentViewPanel panel, AnnotationProviderI calculator)
145 new AnnotationWorker(viewport, panel, calculator);
149 * Factory method to construct an Annotation object
153 * @param secondaryStructure
158 public static Annotation newAnnotation(String displayChar, String desc,
159 char secondaryStructure, float val, Color color)
161 return new Annotation(displayChar, desc, secondaryStructure, val, color);
165 * Factory method to construct an AlignmentAnnotation object
172 public static AlignmentAnnotation newAlignmentAnnotation(String name,
173 String desc, Annotation[] anns)
175 return new AlignmentAnnotation(name, desc, anns);