2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.workers;
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;
30 import java.awt.Color;
33 * Factory class with methods which allow clients (including external scripts
34 * such as Groovy) to 'register and forget' an alignment annotation calculator. <br>
35 * Currently supports two flavours of calculator:
37 * <li>a simple 'feature counter' which counts any desired score derivable from
38 * residue value and any sequence features at each position of the alignment</li>
39 * <li>a 'general purpose' calculator which computes one or more complete
40 * AlignmentAnnotation objects</li>
43 public class AlignmentAnnotationFactory
46 * Constructs and registers a new alignment annotation worker
49 * provider of feature counts per alignment position
51 public static void newCalculator(FeatureCounterI counter)
53 // TODO need an interface for AlignFrame by which to access
54 // its AlignViewportI and AlignmentViewPanel
55 AlignmentViewPanel currentAlignFrame = Jalview.getCurrentAlignFrame().alignPanel;
56 if (currentAlignFrame != null)
58 newCalculator(currentAlignFrame.getAlignViewport(),
59 currentAlignFrame, counter);
64 .println("Can't register calculator as no alignment window has focus");
69 * Constructs and registers a new alignment annotation worker
74 * provider of feature counts per alignment position
76 public static void newCalculator(AlignViewportI viewport,
77 AlignmentViewPanel panel, FeatureCounterI counter)
79 new ColumnCounterWorker(viewport, panel, counter);
83 * Constructs and registers a new alignment annotation worker
86 * provider of AlignmentAnnotation for the alignment
88 public static void newCalculator(AnnotationProviderI calculator)
90 // TODO need an interface for AlignFrame by which to access
91 // its AlignViewportI and AlignmentViewPanel
92 AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame();
93 if (currentAlignFrame != null)
95 newCalculator(currentAlignFrame.getViewport(), currentAlignFrame
96 .getAlignPanels().get(0), calculator);
101 .println("Can't register calculator as no alignment window has focus");
106 * Constructs and registers a new alignment annotation worker
111 * provider of AlignmentAnnotation for the alignment
113 public static void newCalculator(AlignViewportI viewport,
114 AlignmentViewPanel panel, AnnotationProviderI calculator)
116 new AnnotationWorker(viewport, panel, calculator);
120 * Factory method to construct an Annotation object
124 * @param secondaryStructure
129 public static Annotation newAnnotation(String displayChar, String desc,
130 char secondaryStructure, float val, Color color)
132 return new Annotation(displayChar, desc, secondaryStructure, val, color);
136 * Factory method to construct an AlignmentAnnotation object
143 public static AlignmentAnnotation newAlignmentAnnotation(String name,
144 String desc, Annotation[] anns)
146 return new AlignmentAnnotation(name, desc, anns);