JAL-2418 source formatting
[jalview.git] / src / jalview / workers / AlignmentAnnotationFactory.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.workers;
22
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.bin.Jalview;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.Annotation;
28 import jalview.gui.AlignFrame;
29
30 import java.awt.Color;
31
32 /**
33  * Factory class with methods which allow clients (including external scripts
34  * such as Groovy) to 'register and forget' an alignment annotation calculator.
35  * <br>
36  * Currently supports two flavours of calculator:
37  * <ul>
38  * <li>a simple 'feature counter' which counts any desired score derivable from
39  * residue value and any sequence features at each position of the
40  * alignment</li>
41  * <li>a 'general purpose' calculator which computes one or more complete
42  * AlignmentAnnotation objects</li>
43  * </ul>
44  */
45 public class AlignmentAnnotationFactory
46 {
47   /**
48    * Constructs and registers a new alignment annotation worker
49    * 
50    * @param counter
51    *          provider of feature counts per alignment position
52    */
53   public static void newCalculator(FeatureSetCounterI counter)
54   {
55     AlignmentViewPanel currentAlignFrame = Jalview
56             .getCurrentAlignFrame().alignPanel;
57     if (currentAlignFrame == null)
58     {
59       System.err.println(
60               "Can't register calculator as no alignment window has focus");
61       return;
62     }
63     new ColumnCounterSetWorker(currentAlignFrame.getAlignViewport(),
64             currentAlignFrame, counter);
65   }
66
67   /**
68    * Constructs and registers a new alignment annotation worker
69    * 
70    * @param calculator
71    *          provider of AlignmentAnnotation for the alignment
72    */
73   public static void newCalculator(AnnotationProviderI calculator)
74   {
75     // TODO need an interface for AlignFrame by which to access
76     // its AlignViewportI and AlignmentViewPanel
77     AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame();
78     if (currentAlignFrame != null)
79     {
80       new AnnotationWorker(currentAlignFrame.getViewport(),
81               currentAlignFrame.getAlignPanels().get(0), calculator);
82     }
83     else
84     {
85       System.err.println(
86               "Can't register calculator as no alignment window has focus");
87     }
88   }
89
90   /**
91    * Constructs and registers a new alignment annotation worker
92    * 
93    * @param viewport
94    * @param panel
95    * @param calculator
96    *          provider of AlignmentAnnotation for the alignment
97    */
98   public static void newCalculator(AlignViewportI viewport,
99           AlignmentViewPanel panel, AnnotationProviderI calculator)
100   {
101     new AnnotationWorker(viewport, panel, calculator);
102   }
103
104   /**
105    * Factory method to construct an Annotation object
106    * 
107    * @param displayChar
108    * @param desc
109    * @param secondaryStructure
110    * @param val
111    * @param color
112    * @return
113    */
114   public static Annotation newAnnotation(String displayChar, String desc,
115           char secondaryStructure, float val, Color color)
116   {
117     return new Annotation(displayChar, desc, secondaryStructure, val,
118             color);
119   }
120
121   /**
122    * Factory method to construct an AlignmentAnnotation object
123    * 
124    * @param name
125    * @param desc
126    * @param anns
127    * @return
128    */
129   public static AlignmentAnnotation newAlignmentAnnotation(String name,
130           String desc, Annotation[] anns)
131   {
132     return new AlignmentAnnotation(name, desc, anns);
133   }
134 }