JAL-2094 new classes ColorI, Colour added
[jalview.git] / src / jalview / workers / AlignmentAnnotationFactory.java
1 package jalview.workers;
2
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.Annotation;
5 import jalview.gui.AlignFrame;
6 import jalview.gui.Desktop;
7
8 import java.awt.Color;
9
10 /**
11  * Factory class with methods which allow clients (including external scripts
12  * such as Groovy) to 'register and forget' an alignment annotation calculator. <br>
13  * Currently supports two flavours of calculator:
14  * <ul>
15  * <li>a 'feature counter' which can count any desired property derivable from
16  * residue value and any sequence features at each position of the alignment</li>
17  * <li>a 'general purpose' calculator which computes one more complete
18  * AlignmentAnnotation objects</li>
19  * </ul>
20  */
21 public class AlignmentAnnotationFactory
22 {
23   /**
24    * Constructs and registers a new alignment annotation worker
25    * 
26    * @param counter
27    *          provider of feature counts per alignment position
28    */
29   public static void newCalculator(FeatureCounterI counter)
30   {
31     if (Desktop.getCurrentAlignFrame() != null)
32     {
33       newCalculator(Desktop.getCurrentAlignFrame(), counter);
34     }
35     else
36     {
37       System.err
38               .println("Can't register calculator as no alignment window has focus");
39     }
40   }
41
42   /**
43    * Constructs and registers a new alignment annotation worker
44    * 
45    * @param af
46    *          the AlignFrame for which the annotation is to be calculated
47    * @param counter
48    *          provider of feature counts per alignment position
49    */
50   public static void newCalculator(AlignFrame af, FeatureCounterI counter)
51   {
52     new ColumnCounterWorker(af, counter);
53   }
54
55   /**
56    * Constructs and registers a new alignment annotation worker
57    * 
58    * @param calculator
59    *          provider of AlignmentAnnotation for the alignment
60    */
61   public static void newCalculator(AnnotationProviderI calculator)
62   {
63     if (Desktop.getCurrentAlignFrame() != null)
64     {
65       newCalculator(Desktop.getCurrentAlignFrame(), calculator);
66     }
67     else
68     {
69       System.err
70               .println("Can't register calculator as no alignment window has focus");
71     }
72   }
73
74   /**
75    * Constructs and registers a new alignment annotation worker
76    * 
77    * @param af
78    *          the AlignFrame for which the annotation is to be calculated
79    * @param calculator
80    *          provider of AlignmentAnnotation for the alignment
81    */
82   public static void newCalculator(AlignFrame af,
83           AnnotationProviderI calculator)
84   {
85     new AnnotationWorker(af, calculator);
86   }
87
88   /**
89    * Factory method to construct an Annotation object
90    * 
91    * @param displayChar
92    * @param desc
93    * @param secondaryStructure
94    * @param val
95    * @param color
96    * @return
97    */
98   public static Annotation newAnnotation(String displayChar, String desc,
99           char secondaryStructure, float val, Color color)
100   {
101     return new Annotation(displayChar, desc, secondaryStructure, val, color);
102   }
103
104   /**
105    * Factory method to construct an AlignmentAnnotation object
106    * 
107    * @param name
108    * @param desc
109    * @param anns
110    * @return
111    */
112   public static AlignmentAnnotation newAlignmentAnnotation(String name,
113           String desc, Annotation[] anns)
114   {
115     return new AlignmentAnnotation(name, desc, anns);
116   }
117 }