JAL-2228 removed FeatureCounterI in favour of FeatureSetCounterI with
[jalview.git] / src / jalview / workers / AlignmentAnnotationFactory.java
1 package jalview.workers;
2
3 import jalview.api.AlignmentViewPanel;
4 import jalview.bin.Jalview;
5 import jalview.datamodel.AlignmentAnnotation;
6 import jalview.datamodel.Annotation;
7 import jalview.gui.AlignFrame;
8
9 import java.awt.Color;
10
11 /**
12  * Factory class with methods which allow clients (including external scripts
13  * such as Groovy) to 'register and forget' an alignment annotation calculator. <br>
14  * Currently supports two flavours of calculator:
15  * <ul>
16  * <li>a simple 'feature counter' which counts any desired score derivable from
17  * residue value and any sequence features at each position of the alignment</li>
18  * <li>a 'general purpose' calculator which computes one or more complete
19  * AlignmentAnnotation objects</li>
20  * </ul>
21  */
22 public class AlignmentAnnotationFactory
23 {
24   /**
25    * Constructs and registers a new alignment annotation worker
26    * 
27    * @param counter
28    *          provider of feature counts per alignment position
29    */
30   public static void newCalculator(FeatureSetCounterI counter)
31   {
32     AlignmentViewPanel currentAlignFrame = Jalview.getCurrentAlignFrame().alignPanel;
33     if (currentAlignFrame == null)
34     {
35       System.err
36               .println("Can't register calculator as no alignment window has focus");
37       return;
38     }
39     new ColumnCounterSetWorker(currentAlignFrame.getAlignViewport(),
40             currentAlignFrame, counter);
41   }
42
43   /**
44    * Constructs and registers a new alignment annotation worker
45    * 
46    * @param calculator
47    *          provider of AlignmentAnnotation for the alignment
48    */
49   public static void newCalculator(AnnotationProviderI calculator)
50   {
51     AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame();
52     if (currentAlignFrame != null)
53     {
54       new AnnotationWorker(currentAlignFrame.getViewport(),
55               currentAlignFrame.getAlignPanels().get(0), calculator);
56     }
57     else
58     {
59       System.err
60               .println("Can't register calculator as no alignment window has focus");
61     }
62   }
63
64   /**
65    * Factory method to construct an Annotation object
66    * 
67    * @param displayChar
68    * @param desc
69    * @param secondaryStructure
70    * @param val
71    * @param color
72    * @return
73    */
74   public static Annotation newAnnotation(String displayChar, String desc,
75           char secondaryStructure, float val, Color color)
76   {
77     return new Annotation(displayChar, desc, secondaryStructure, val, color);
78   }
79
80   /**
81    * Factory method to construct an AlignmentAnnotation object
82    * 
83    * @param name
84    * @param desc
85    * @param anns
86    * @return
87    */
88   public static AlignmentAnnotation newAlignmentAnnotation(String name,
89           String desc, Annotation[] anns)
90   {
91     return new AlignmentAnnotation(name, desc, anns);
92   }
93 }