*/
package jalview.workers;
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
-import jalview.gui.AlignFrame;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.FeatureRenderer;
+import jalview.renderer.seqfeatures.FeatureRenderer;
import java.util.ArrayList;
import java.util.List;
/**
* A class to create and update one or more alignment annotations, given a
- * 'calculator'.
- *
+ * 'calculator'. Intended to support a 'plug-in' annotation worker which
+ * implements the AnnotationProviderI interface.
*/
class AnnotationWorker extends AlignCalcWorker
{
* @param af
* @param counter
*/
- public AnnotationWorker(AlignFrame af, AnnotationProviderI counter)
+ public AnnotationWorker(AlignViewportI viewport, AlignmentViewPanel panel,
+ AnnotationProviderI counter)
{
- super(af.getViewport(), af.alignPanel);
- ourAnnots = new ArrayList<AlignmentAnnotation>();
+ super(viewport, panel);
+ ourAnnots = new ArrayList<>();
this.counter = counter;
calcMan.registerWorker(this);
}
@Override
public void run()
{
- try
+ if (alignViewport.isClosed())
{
- calcMan.notifyStart(this);
-
- while (!calcMan.notifyWorking(this))
- {
- try
- {
- Thread.sleep(200);
- } catch (InterruptedException ex)
- {
- ex.printStackTrace();
- }
- }
- if (alignViewport.isClosed())
- {
- abortAndDestroy();
- return;
- }
+ abortAndDestroy();
+ return;
+ }
- removeAnnotations();
+ // removeAnnotation();
AlignmentI alignment = alignViewport.getAlignment();
- if (alignment != null)
+ if (alignment != null)
+ {
+ try
{
- try
+ List<AlignmentAnnotation> anns = counter.calculateAnnotation(
+ alignment, new FeatureRenderer(alignViewport));
+ for (AlignmentAnnotation ann : anns)
{
- List<AlignmentAnnotation> anns = counter.calculateAnnotation(
- alignment, new FeatureRenderer((AlignmentPanel) ap));
- for (AlignmentAnnotation ann : anns)
+ AlignmentAnnotation theAnn = alignment.findOrCreateAnnotation(
+ ann.label, ann.description, false, null, null);
+ theAnn.showAllColLabels = true;
+ theAnn.graph = AlignmentAnnotation.BAR_GRAPH;
+ theAnn.scaleColLabel = true;
+ theAnn.annotations = ann.annotations;
+ setGraphMinMax(theAnn, theAnn.annotations);
+ theAnn.validateRangeAndDisplay();
+ if (!ourAnnots.contains(theAnn))
{
- ann.showAllColLabels = true;
- ann.graph = AlignmentAnnotation.BAR_GRAPH;
- ourAnnots.add(ann);
- alignment.addAnnotation(ann);
+ ourAnnots.add(theAnn);
}
- } catch (IndexOutOfBoundsException x)
- {
- // probable race condition. just finish and return without any fuss.
- return;
+ // 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);
+ // TODO: only need to update colour and geometry if panel height changes
+ // and view is coloured by annotation, and the annotation is actually
+ // changed!
+ ap.paintAlignment(true, true);
}
-
}
- /**
- * Remove all our annotations before re-calculating them
- */
- void removeAnnotations()
+ @Override
+ public void updateAnnotation()
{
- for (AlignmentAnnotation ann : ourAnnots)
- {
- alignViewport.getAlignment().deleteAnnotation(ann);
- }
- ourAnnots.clear();
+ // do nothing
}
+ /**
+ * Answers true to indicate that if this worker's annotation is deleted from
+ * the display, the worker should also be removed. This prevents it running
+ * and recreating the annotation when the alignment changes.
+ */
@Override
- public void updateAnnotation()
+ public boolean isDeletable()
{
- // do nothing
+ return true;
}
}