X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fworkers%2FAnnotationWorker.java;fp=src%2Fjalview%2Fworkers%2FAnnotationWorker.java;h=fbf7531dd97e00f3fa0fe721ef3eb9cc3833ae02;hb=99d5f1d805e530f23a53dad4484d44ecd0fbfdf3;hp=0000000000000000000000000000000000000000;hpb=e6134bccddc2c7faad28fad1a4e77ccd0ceb3d84;p=jalview.git diff --git a/src/jalview/workers/AnnotationWorker.java b/src/jalview/workers/AnnotationWorker.java new file mode 100644 index 0000000..fbf7531 --- /dev/null +++ b/src/jalview/workers/AnnotationWorker.java @@ -0,0 +1,136 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.workers; + +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.gui.AlignFrame; +import jalview.gui.AlignmentPanel; +import jalview.gui.FeatureRenderer; + +import java.util.ArrayList; +import java.util.List; + +/** + * A class to create and update one or more alignment annotations, given a + * 'calculator'. + * + */ +class AnnotationWorker extends AlignCalcWorker +{ + /* + * the provider of the annotation calculations + */ + AnnotationProviderI counter; + + /** + * Constructor + * + * @param af + * @param counter + */ + public AnnotationWorker(AlignFrame af, AnnotationProviderI counter) + { + super(af.getViewport(), af.alignPanel); + ourAnnots = new ArrayList(); + this.counter = counter; + calcMan.registerWorker(this); + } + + @Override + public void run() + { + try + { + calcMan.notifyStart(this); + + while (!calcMan.notifyWorking(this)) + { + try + { + Thread.sleep(200); + } catch (InterruptedException ex) + { + ex.printStackTrace(); + } + } + if (alignViewport.isClosed()) + { + abortAndDestroy(); + return; + } + + removeAnnotations(); + AlignmentI alignment = alignViewport.getAlignment(); + if (alignment != null) + { + try + { + List anns = counter.calculateAnnotation( + alignment, new FeatureRenderer((AlignmentPanel) ap)); + for (AlignmentAnnotation ann : anns) + { + ann.showAllColLabels = true; + ann.graph = AlignmentAnnotation.BAR_GRAPH; + ourAnnots.add(ann); + alignment.addAnnotation(ann); + } + } catch (IndexOutOfBoundsException x) + { + // probable race condition. just finish and return without any fuss. + return; + } + } + } catch (OutOfMemoryError error) + { + ap.raiseOOMWarning("calculating annotations", error); + calcMan.workerCannotRun(this); + } finally + { + calcMan.workerComplete(this); + } + + if (ap != null) + { + ap.adjustAnnotationHeight(); + ap.paintAlignment(true); + } + + } + + /** + * Remove all our annotations before re-calculating them + */ + void removeAnnotations() + { + for (AlignmentAnnotation ann : ourAnnots) + { + alignViewport.getAlignment().deleteAnnotation(ann); + } + ourAnnots.clear(); + } + + @Override + public void updateAnnotation() + { + // do nothing + } +}