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.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.renderer.seqfeatures.FeatureRenderer;
29 import java.util.ArrayList;
30 import java.util.List;
33 * A class to create and update one or more alignment annotations, given a
34 * 'calculator'. Intended to support a 'plug-in' annotation worker which
35 * implements the AnnotationProviderI interface.
37 class AnnotationWorker extends AlignCalcWorker
40 * the provider of the annotation calculations
42 AnnotationProviderI counter;
50 public AnnotationWorker(AlignViewportI viewport, AlignmentViewPanel panel,
51 AnnotationProviderI counter)
53 super(viewport, panel);
54 ourAnnots = new ArrayList<>();
55 this.counter = counter;
56 calcMan.registerWorker(this);
62 if (alignViewport.isClosed())
68 // removeAnnotation();
69 AlignmentI alignment = alignViewport.getAlignment();
70 if (alignment != null)
74 List<AlignmentAnnotation> anns = counter.calculateAnnotation(
75 alignment, new FeatureRenderer(alignViewport));
76 for (AlignmentAnnotation ann : anns)
78 AlignmentAnnotation theAnn = alignment.findOrCreateAnnotation(
79 ann.label, ann.description, false, null, null);
80 theAnn.showAllColLabels = true;
81 theAnn.graph = AlignmentAnnotation.BAR_GRAPH;
82 theAnn.scaleColLabel = true;
83 theAnn.annotations = ann.annotations;
84 setGraphMinMax(theAnn, theAnn.annotations);
85 theAnn.validateRangeAndDisplay();
86 if (!ourAnnots.contains(theAnn))
88 ourAnnots.add(theAnn);
90 // alignment.addAnnotation(ann);
92 } catch (IndexOutOfBoundsException x)
94 // probable race condition. just finish and return without any fuss.
101 ap.adjustAnnotationHeight();
102 // TODO: only need to update colour and geometry if panel height changes
103 // and view is coloured by annotation, and the annotation is actually
105 ap.paintAlignment(true, true);
110 public void updateAnnotation()
116 * Answers true to indicate that if this worker's annotation is deleted from
117 * the display, the worker should also be removed. This prevents it running
118 * and recreating the annotation when the alignment changes.
121 public boolean isDeletable()