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