9c9ea830301ff0b83b53a6953142ed9556faec41
[jalview.git] / src / jalview / workers / AlignmentAnnotationFactory.java
1 package jalview.workers;
2
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;
9
10 import java.awt.Color;
11
12 /**
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:
16  * <ul>
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>
21  * </ul>
22  */
23 public class AlignmentAnnotationFactory
24 {
25   /**
26    * Constructs and registers a new alignment annotation worker
27    * 
28    * @param counter
29    *          provider of feature counts per alignment position
30    */
31   public static void newCalculator(FeatureCounterI counter)
32   {
33     // TODO need an interface for AlignFrame by which to access
34     // its AlignViewportI and AlignmentViewPanel
35     AlignmentViewPanel currentAlignFrame = Jalview.getCurrentAlignFrame().alignPanel;
36     if (currentAlignFrame != null)
37     {
38       newCalculator(currentAlignFrame.getAlignViewport(),
39               currentAlignFrame, counter);
40     }
41     else
42     {
43       System.err
44               .println("Can't register calculator as no alignment window has focus");
45     }
46   }
47
48   /**
49    * Constructs and registers a new alignment annotation worker
50    * 
51    * @param viewport
52    * @param panel
53    * @param counter
54    *          provider of feature counts per alignment position
55    */
56   public static void newCalculator(AlignViewportI viewport,
57           AlignmentViewPanel panel, FeatureCounterI counter)
58   {
59     new ColumnCounterWorker(viewport, panel, counter);
60   }
61
62   /**
63    * Constructs and registers a new alignment annotation worker
64    * 
65    * @param calculator
66    *          provider of AlignmentAnnotation for the alignment
67    */
68   public static void newCalculator(AnnotationProviderI calculator)
69   {
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)
74     {
75       newCalculator(currentAlignFrame.getViewport(), currentAlignFrame
76               .getAlignPanels().get(0), calculator);
77     }
78     else
79     {
80       System.err
81               .println("Can't register calculator as no alignment window has focus");
82     }
83   }
84
85   /**
86    * Constructs and registers a new alignment annotation worker
87    * 
88    * @param viewport
89    * @param panel
90    * @param calculator
91    *          provider of AlignmentAnnotation for the alignment
92    */
93   public static void newCalculator(AlignViewportI viewport,
94           AlignmentViewPanel panel, AnnotationProviderI calculator)
95   {
96     new AnnotationWorker(viewport, panel, calculator);
97   }
98
99   /**
100    * Factory method to construct an Annotation object
101    * 
102    * @param displayChar
103    * @param desc
104    * @param secondaryStructure
105    * @param val
106    * @param color
107    * @return
108    */
109   public static Annotation newAnnotation(String displayChar, String desc,
110           char secondaryStructure, float val, Color color)
111   {
112     return new Annotation(displayChar, desc, secondaryStructure, val, color);
113   }
114
115   /**
116    * Factory method to construct an AlignmentAnnotation object
117    * 
118    * @param name
119    * @param desc
120    * @param anns
121    * @return
122    */
123   public static AlignmentAnnotation newAlignmentAnnotation(String name,
124           String desc, Annotation[] anns)
125   {
126     return new AlignmentAnnotation(name, desc, anns);
127   }
128 }