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.util.List;
25 import swingjs.JSThread;
27 import jalview.api.AlignCalcManagerI;
28 import jalview.api.AlignCalcWorkerI;
29 import jalview.api.AlignViewportI;
30 import jalview.api.AlignmentViewPanel;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
35 * Base class for alignment calculation workers
40 public abstract class AlignCalcWorker extends JSThread implements AlignCalcWorkerI
43 * manager and data source for calculations
45 protected final static int LOOP_STANDBY = DONE + 1;
46 protected final static int LOOP_CALCULATE = DONE + 2;
50 protected int nPer = 2;
52 protected final static int MS_MAX = 500;
54 protected long started;
55 protected AlignmentI alignment;
58 protected AlignViewportI alignViewport;
60 protected AlignCalcManagerI calcMan;
62 protected AlignmentViewPanel ap;
64 protected List<AlignmentAnnotation> ourAnnots = null;
66 public AlignCalcWorker(AlignViewportI alignViewport,
67 AlignmentViewPanel alignPanel)
69 super(null, "AlignCalcWorker");
70 this.alignViewport = alignViewport;
71 calcMan = alignViewport.getCalcManager();
75 protected void abortAndDestroy()
79 calcMan.workerComplete(this);
87 public boolean involves(AlignmentAnnotation i)
89 return ourAnnots != null && ourAnnots.contains(i);
93 * permanently remove from the alignment all annotation rows managed by this
97 public void removeOurAnnotation()
99 if (ourAnnots != null && alignViewport != null)
101 AlignmentI alignment = alignViewport.getAlignment();
102 synchronized (ourAnnots)
104 for (AlignmentAnnotation aa : ourAnnots)
106 alignment.deleteAnnotation(aa, true);
111 // TODO: allow GUI to query workers associated with annotation to add items to
112 // annotation label panel popup menu
114 protected void notifyDone() {
116 ap.paintAlignment(true);
119 * e.g. ArrayIndexOutOfBoundsException can happen due to a race
120 * condition - alignment was edited at same time as calculation was
123 calcMan.workerComplete(this);