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.
36 * Currently supports two flavours of calculator:
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
41 * <li>a 'general purpose' calculator which computes one or more complete
42 * AlignmentAnnotation objects</li>
45 public class AlignmentAnnotationFactory
48 * Constructs and registers a new alignment annotation worker
51 * provider of feature counts per alignment position
53 public static void newCalculator(FeatureSetCounterI counter)
55 AlignmentViewPanel currentAlignFrame = Jalview
56 .getCurrentAlignFrame().alignPanel;
57 if (currentAlignFrame == null)
60 "Can't register calculator as no alignment window has focus");
63 new ColumnCounterSetWorker(currentAlignFrame.getAlignViewport(),
64 currentAlignFrame, counter);
68 * Constructs and registers a new alignment annotation worker
71 * provider of AlignmentAnnotation for the alignment
73 public static void newCalculator(AnnotationProviderI calculator)
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)
80 new AnnotationWorker(currentAlignFrame.getViewport(),
81 currentAlignFrame.getAlignPanels().get(0), calculator);
86 "Can't register calculator as no alignment window has focus");
91 * Constructs and registers a new alignment annotation worker
96 * provider of AlignmentAnnotation for the alignment
98 public static void newCalculator(AlignViewportI viewport,
99 AlignmentViewPanel panel, AnnotationProviderI calculator)
101 new AnnotationWorker(viewport, panel, calculator);
105 * Factory method to construct an Annotation object
109 * @param secondaryStructure
114 public static Annotation newAnnotation(String displayChar, String desc,
115 char secondaryStructure, float val, Color color)
117 return new Annotation(displayChar, desc, secondaryStructure, val,
122 * Factory method to construct an AlignmentAnnotation object
129 public static AlignmentAnnotation newAlignmentAnnotation(String name,
130 String desc, Annotation[] anns)
132 return new AlignmentAnnotation(name, desc, anns);