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.AlignCalcManagerI2;
24 import jalview.api.AlignCalcWorkerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.Annotation;
31 import java.util.List;
34 * Base class for alignment calculation workers
39 public abstract class AlignCalcWorker implements AlignCalcWorkerI
42 * manager and data source for calculations
44 protected AlignViewportI alignViewport;
46 protected AlignCalcManagerI2 calcMan;
48 protected AlignmentViewPanel ap;
50 protected List<AlignmentAnnotation> ourAnnots;
52 public AlignCalcWorker(AlignViewportI alignViewport,
53 AlignmentViewPanel alignPanel)
55 this.alignViewport = alignViewport;
56 calcMan = alignViewport.getCalcManager();
60 protected void abortAndDestroy()
64 calcMan.cancelWorker(this);
65 calcMan.removeWorker(this);
74 public boolean involves(AlignmentAnnotation i)
76 return ourAnnots != null && ourAnnots.contains(i);
80 * Permanently removes from the alignment all annotation rows managed by this
84 public void removeAnnotation()
86 if (ourAnnots != null && alignViewport != null)
88 AlignmentI alignment = alignViewport.getAlignment();
89 synchronized (ourAnnots)
91 for (AlignmentAnnotation aa : ourAnnots)
93 alignment.deleteAnnotation(aa, true);
100 // TODO: allow GUI to query workers associated with annotation to add items to
101 // annotation label panel popup menu
104 public boolean isDeletable()
110 * Calculate min and max values of annotations and set as graphMin, graphMax
111 * on the AlignmentAnnotation. This is needed because otherwise, well, bad
117 protected void setGraphMinMax(AlignmentAnnotation ann, Annotation[] anns)
119 // TODO feels like this belongs inside AlignmentAnnotation!
120 float max = Float.MIN_VALUE;
121 float min = Float.MAX_VALUE;
123 for (Annotation a : anns)
129 max = Math.max(max, val);
130 min = Math.min(min, val);
140 public AlignViewportI getAlignViewport()
142 return alignViewport;