/*
* 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 java.util.List;
import swingjs.JSThread;
import jalview.api.AlignCalcManagerI;
import jalview.api.AlignCalcWorkerI;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
/**
* Base class for alignment calculation workers
*
* @author jimp
*
*/
public abstract class AlignCalcWorker extends JSThread implements AlignCalcWorkerI
{
/**
* manager and data source for calculations
*/
protected final static int LOOP_STANDBY = DONE + 1;
protected final static int LOOP_CALCULATE = DONE + 2;
protected int iFirst;
protected int iLast;
protected int nPer = 2;
protected final static int MS_MAX = 500;
protected long started;
protected AlignmentI alignment;
protected int aWidth;
protected AlignViewportI alignViewport;
protected AlignCalcManagerI calcMan;
protected AlignmentViewPanel ap;
protected List ourAnnots = null;
public AlignCalcWorker(AlignViewportI alignViewport,
AlignmentViewPanel alignPanel)
{
super(null, "AlignCalcWorker");
this.alignViewport = alignViewport;
calcMan = alignViewport.getCalcManager();
ap = alignPanel;
}
protected void abortAndDestroy()
{
if (calcMan != null)
{
calcMan.workerComplete(this);
}
alignViewport = null;
calcMan = null;
ap = null;
}
public boolean involves(AlignmentAnnotation i)
{
return ourAnnots != null && ourAnnots.contains(i);
}
/**
* permanently remove from the alignment all annotation rows managed by this
* worker
*/
@Override
public void removeOurAnnotation()
{
if (ourAnnots != null && alignViewport != null)
{
AlignmentI alignment = alignViewport.getAlignment();
synchronized (ourAnnots)
{
for (AlignmentAnnotation aa : ourAnnots)
{
alignment.deleteAnnotation(aa, true);
}
}
}
}
// TODO: allow GUI to query workers associated with annotation to add items to
// annotation label panel popup menu
protected void notifyDone() {
if (ap != null) {
ap.paintAlignment(true);
}
/*
* e.g. ArrayIndexOutOfBoundsException can happen due to a race
* condition - alignment was edited at same time as calculation was
* running
*/
calcMan.workerComplete(this);
}
}