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.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.AlignmentI;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.AlignmentPanel;
27 import jalview.gui.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
37 class AnnotationWorker extends AlignCalcWorker
40 * the provider of the annotation calculations
42 AnnotationProviderI counter;
50 public AnnotationWorker(AlignFrame af, AnnotationProviderI counter)
52 super(af.getViewport(), af.alignPanel);
53 ourAnnots = new ArrayList<AlignmentAnnotation>();
54 this.counter = counter;
55 calcMan.registerWorker(this);
63 calcMan.notifyStart(this);
65 while (!calcMan.notifyWorking(this))
70 } catch (InterruptedException ex)
75 if (alignViewport.isClosed())
82 AlignmentI alignment = alignViewport.getAlignment();
83 if (alignment != null)
87 List<AlignmentAnnotation> anns = counter.calculateAnnotation(
88 alignment, new FeatureRenderer((AlignmentPanel) ap));
89 for (AlignmentAnnotation ann : anns)
91 ann.showAllColLabels = true;
92 ann.graph = AlignmentAnnotation.BAR_GRAPH;
94 alignment.addAnnotation(ann);
96 } catch (IndexOutOfBoundsException x)
98 // probable race condition. just finish and return without any fuss.
102 } catch (OutOfMemoryError error)
104 ap.raiseOOMWarning("calculating annotations", error);
105 calcMan.workerCannotRun(this);
108 calcMan.workerComplete(this);
113 ap.adjustAnnotationHeight();
114 ap.paintAlignment(true);
120 * Remove all our annotations before re-calculating them
122 void removeAnnotations()
124 for (AlignmentAnnotation ann : ourAnnots)
126 alignViewport.getAlignment().deleteAnnotation(ann);
132 public void updateAnnotation()