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 java.awt.Color;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.bin.Jalview;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.Annotation;
30 import jalview.gui.AlignFrame;
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.getInstance()
56 .getCurrentAlignFrame().alignPanel;
57 if (currentAlignFrame == null)
59 jalview.bin.Console.errPrintln(
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.getInstance()
78 .getCurrentAlignFrame();
79 if (currentAlignFrame != null)
81 new AnnotationWorker(currentAlignFrame.getViewport(),
82 currentAlignFrame.getAlignPanels().get(0), calculator);
86 jalview.bin.Console.errPrintln(
87 "Can't register calculator as no alignment window has focus");
92 * Constructs and registers a new alignment annotation worker
97 * provider of AlignmentAnnotation for the alignment
99 public static void newCalculator(AlignViewportI viewport,
100 AlignmentViewPanel panel, AnnotationProviderI calculator)
102 new AnnotationWorker(viewport, panel, calculator);
106 * Factory method to construct an Annotation object
110 * @param secondaryStructure
115 public static Annotation newAnnotation(String displayChar, String desc,
116 char secondaryStructure, float val, Color color)
118 return new Annotation(displayChar, desc, secondaryStructure, val,
123 * Factory method to construct an AlignmentAnnotation object
130 public static AlignmentAnnotation newAlignmentAnnotation(String name,
131 String desc, Annotation[] anns)
133 return new AlignmentAnnotation(name, desc, anns);