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;
13 * Factory class with methods which allow clients (including external scripts
14 * such as Groovy) to 'register and forget' an alignment annotation calculator. <br>
15 * Currently supports two flavours of calculator:
17 * <li>a simple 'feature counter' which counts any desired score derivable from
18 * residue value and any sequence features at each position of the alignment</li>
19 * <li>a 'general purpose' calculator which computes one or more complete
20 * AlignmentAnnotation objects</li>
23 public class AlignmentAnnotationFactory
26 * Constructs and registers a new alignment annotation worker
29 * provider of feature counts per alignment position
31 public static void newCalculator(FeatureCounterI counter)
33 // TODO need an interface for AlignFrame by which to access
34 // its AlignViewportI and AlignmentViewPanel
35 AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame() ;
36 if (currentAlignFrame != null)
38 newCalculator(currentAlignFrame.getViewport(), currentAlignFrame
39 .getAlignPanels().get(0), counter);
44 .println("Can't register calculator as no alignment window has focus");
49 * Constructs and registers a new alignment annotation worker
54 * provider of feature counts per alignment position
56 public static void newCalculator(AlignViewportI viewport,
57 AlignmentViewPanel panel, FeatureCounterI counter)
59 new ColumnCounterWorker(viewport, panel, counter);
63 * Constructs and registers a new alignment annotation worker
66 * provider of AlignmentAnnotation for the alignment
68 public static void newCalculator(AnnotationProviderI calculator)
70 // TODO need an interface for AlignFrame by which to access
71 // its AlignViewportI and AlignmentViewPanel
72 AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame() ;
73 if (currentAlignFrame != null)
75 newCalculator(currentAlignFrame.getViewport(), currentAlignFrame
76 .getAlignPanels().get(0), calculator);
81 .println("Can't register calculator as no alignment window has focus");
86 * Constructs and registers a new alignment annotation worker
91 * provider of AlignmentAnnotation for the alignment
93 public static void newCalculator(AlignViewportI viewport,
94 AlignmentViewPanel panel,
95 AnnotationProviderI calculator)
97 new AnnotationWorker(viewport, panel, calculator);
101 * Factory method to construct an Annotation object
105 * @param secondaryStructure
110 public static Annotation newAnnotation(String displayChar, String desc,
111 char secondaryStructure, float val, Color color)
113 return new Annotation(displayChar, desc, secondaryStructure, val, color);
117 * Factory method to construct an AlignmentAnnotation object
124 public static AlignmentAnnotation newAlignmentAnnotation(String name,
125 String desc, Annotation[] anns)
127 return new AlignmentAnnotation(name, desc, anns);