2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.workers;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.util.Collections;
26 import java.util.HashSet;
27 import java.util.List;
30 import jalview.api.AlignViewportI;
31 import jalview.api.FeaturesDisplayedI;
32 import jalview.datamodel.SequenceFeature;
33 import jalview.gui.FeatureRenderer;
35 public class VisibleFeaturesAnnotationTracks implements FeatureSetCounterI
37 AlignViewportI ourViewport = null;
39 jalview.api.FeatureRenderer ourFr = null;
41 PropertyChangeListener ourListener = new PropertyChangeListener()
45 public void propertyChange(PropertyChangeEvent evt)
47 if (ourViewport != null) // could check source is
48 // ourFr.getChangeSupport...
50 updateFeatureAnnotationTracks();
55 public VisibleFeaturesAnnotationTracks(AlignViewportI viewport,
58 ourViewport = viewport;
63 void registerListener()
65 ourFr.addPropertyChangeListener(ourListener);
72 ourFr.removePropertyChangeListener(ourListener);
74 if (ourViewport != null && ourViewport.getCalcManager() != null)
76 if (ourWorker != null)
78 ourWorker.abortAndDestroy();
79 ourViewport.getCalcManager()
80 .removeRegisteredWorkersOfClass(ourWorker.getClass());
87 public void updateFeatureAnnotationTracks()
89 // if tracks are turned off, this returns null.
90 FeaturesDisplayedI featuresDisp = ourViewport
91 .isShowSequenceFeatureCounts()
92 ? ourViewport.getFeaturesDisplayed()
94 Set<String> visibleFeatures = new HashSet();
95 if (featuresDisp != null)
97 visibleFeatures.addAll(featuresDisp.getVisibleFeatures());
99 if (dispFeatures.equals(visibleFeatures))
101 // all the same features displayed
104 // otherwise set up tracks accordingly
107 * and register the counter
109 if (ourWorker != null)
111 Set<String> toRemove = new HashSet<String>(),
112 toAdd = new HashSet<String>();
113 toRemove.addAll(dispFeatures);
114 toRemove.removeAll(visibleFeatures);
115 dispFeatures = visibleFeatures;
116 ourWorker.removeOldAnnotations(toRemove.toArray(new String[0]));
121 dispFeatures = visibleFeatures;
122 ourWorker = new ColumnCounterSetWorker(ourViewport,
123 ourFr.getAlignPanel(), this);
125 ourViewport.getCalcManager().registerWorker(ourWorker);
126 ourViewport.getCalcManager().startWorker(ourWorker);
129 ColumnCounterSetWorker ourWorker = null;
131 Set<String> dispFeatures = Collections.EMPTY_SET;
134 public int[] count(String residue, List<SequenceFeature> features)
136 final Set<String> ourDispFeatures = dispFeatures;
137 int[] obs = new int[ourDispFeatures.size()];
138 SequenceFeature[] sfs = features.toArray(new SequenceFeature[0]);
139 for (SequenceFeature sf : sfs)
142 * Here we inspect the type of the sequence feature.
143 * You can also test sf.description, sf.score, sf.featureGroup,
144 * sf.strand, sf.phase, sf.begin, sf.end
145 * or sf.getValue(attributeName) for GFF 'column 9' properties
148 for (String type : ourDispFeatures)
150 if (type.equals(sf.type))
161 public String[] getNames()
163 return dispFeatures.toArray(new String[0]);
167 public String[] getDescriptions()
169 return dispFeatures.toArray(new String[0]);
173 public int[] getMaxColour()
175 return new int[] { 0, 0, 255 };
179 public int[] getMinColour()
181 return new int[] { 0, 255, 255 };