c9dbba6ec9494f0785532bab2f3631b6b7ad3ba4
[jalview.git] / src / jalview / workers / AlignCalcWorker.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.workers;
19
20 import java.util.List;
21
22 import jalview.api.AlignCalcManagerI;
23 import jalview.api.AlignCalcWorkerI;
24 import jalview.api.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28
29 /**
30  * Base class for alignment calculation workers
31  * 
32  * @author jimp
33  * 
34  */
35 public abstract class AlignCalcWorker implements AlignCalcWorkerI
36 {
37   /**
38    * manager and data source for calculations
39    */
40   protected AlignViewportI alignViewport;
41
42   protected AlignCalcManagerI calcMan;
43
44   protected AlignmentViewPanel ap;
45
46   protected List<AlignmentAnnotation> ourAnnots = null;
47
48   public AlignCalcWorker(AlignViewportI alignViewport,
49           AlignmentViewPanel alignPanel)
50   {
51     this.alignViewport = alignViewport;
52     calcMan = alignViewport.getCalcManager();
53     ap = alignPanel;
54   }
55
56   protected void abortAndDestroy()
57   {
58     if (calcMan != null)
59     {
60       calcMan.workerComplete(this);
61     }
62     alignViewport = null;
63     calcMan = null;
64     ap = null;
65
66   }
67
68   public boolean involves(AlignmentAnnotation i)
69   {
70     return ourAnnots != null && ourAnnots.contains(i);
71   }
72
73   /**
74    * permanently remove from the alignment all annotation rows managed by this
75    * worker
76    */
77   @Override
78   public void removeOurAnnotation()
79   {
80     if (ourAnnots != null && alignViewport != null)
81     {
82       AlignmentI alignment = alignViewport.getAlignment();
83       synchronized (ourAnnots)
84       {
85         for (AlignmentAnnotation aa : ourAnnots)
86         {
87           alignment.deleteAnnotation(aa, true);
88         }
89       }
90     }
91   }
92   // TODO: allow GUI to query workers associated with annotation to add items to
93   // annotation label panel popup menu
94
95 }