JAL-1432 updated copyright notices
[jalview.git] / src / jalview / workers / AlignCalcWorker.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 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  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.workers;
20
21 import java.util.List;
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 /**
31  * Base class for alignment calculation workers
32  * 
33  * @author jimp
34  * 
35  */
36 public abstract class AlignCalcWorker implements AlignCalcWorkerI
37 {
38   /**
39    * manager and data source for calculations
40    */
41   protected AlignViewportI alignViewport;
42
43   protected AlignCalcManagerI calcMan;
44
45   protected AlignmentViewPanel ap;
46
47   protected List<AlignmentAnnotation> ourAnnots = null;
48
49   public AlignCalcWorker(AlignViewportI alignViewport,
50           AlignmentViewPanel alignPanel)
51   {
52     this.alignViewport = alignViewport;
53     calcMan = alignViewport.getCalcManager();
54     ap = alignPanel;
55   }
56
57   protected void abortAndDestroy()
58   {
59     if (calcMan != null)
60     {
61       calcMan.workerComplete(this);
62     }
63     alignViewport = null;
64     calcMan = null;
65     ap = null;
66
67   }
68
69   public boolean involves(AlignmentAnnotation i)
70   {
71     return ourAnnots != null && ourAnnots.contains(i);
72   }
73
74   /**
75    * permanently remove from the alignment all annotation rows managed by this
76    * worker
77    */
78   @Override
79   public void removeOurAnnotation()
80   {
81     if (ourAnnots != null && alignViewport != null)
82     {
83       AlignmentI alignment = alignViewport.getAlignment();
84       synchronized (ourAnnots)
85       {
86         for (AlignmentAnnotation aa : ourAnnots)
87         {
88           alignment.deleteAnnotation(aa, true);
89         }
90       }
91     }
92   }
93   // TODO: allow GUI to query workers associated with annotation to add items to
94   // annotation label panel popup menu
95
96 }