formatting
[jalview.git] / src / jalview / workers / AlignCalcWorker.java
1 /**
2  * 
3  */
4 package jalview.workers;
5
6 import java.util.List;
7
8 import jalview.api.AlignCalcManagerI;
9 import jalview.api.AlignCalcWorkerI;
10 import jalview.api.AlignViewportI;
11 import jalview.api.AlignmentViewPanel;
12 import jalview.datamodel.AlignmentAnnotation;
13 import jalview.datamodel.AlignmentI;
14
15 /**
16  * Base class for alignment calculation workers
17  * 
18  * @author jimp
19  * 
20  */
21 public abstract class AlignCalcWorker implements AlignCalcWorkerI
22 {
23   /**
24    * manager and data source for calculations
25    */
26   protected AlignViewportI alignViewport;
27
28   protected AlignCalcManagerI calcMan;
29
30   protected AlignmentViewPanel ap;
31
32   protected List<AlignmentAnnotation> ourAnnots = null;
33
34   public AlignCalcWorker(AlignViewportI alignViewport,
35           AlignmentViewPanel alignPanel)
36   {
37     this.alignViewport = alignViewport;
38     calcMan = alignViewport.getCalcManager();
39     ap = alignPanel;
40   }
41
42   protected void abortAndDestroy()
43   {
44     if (calcMan != null)
45     {
46       calcMan.workerComplete(this);
47     }
48     alignViewport = null;
49     calcMan = null;
50     ap = null;
51
52   }
53
54   public boolean involves(AlignmentAnnotation i)
55   {
56     return ourAnnots != null && ourAnnots.contains(i);
57   }
58
59   /**
60    * permanently remove from the alignment all annotation rows managed by this
61    * worker
62    */
63   @Override
64   public void removeOurAnnotation()
65   {
66     if (ourAnnots != null && alignViewport != null)
67     {
68       AlignmentI alignment = alignViewport.getAlignment();
69       synchronized (ourAnnots)
70       {
71         for (AlignmentAnnotation aa : ourAnnots)
72         {
73           alignment.deleteAnnotation(aa, true);
74         }
75       }
76     }
77   }
78   // TODO: allow GUI to query workers associated with annotation to add items to
79   // annotation label panel popup menu
80
81 }