X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=6b797d79a939a5c50af6b41e05916e96956185e5;hb=9e926ac4305fd9dff38b6e079e55b4f50664d544;hp=46c802f9c4e17a108524c35ea802b78e162a50fe;hpb=163ed5b997bbda48e4cdd950e87a8fe01baae7fb;p=jalview.git diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 46c802f..6b797d7 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -27,7 +27,10 @@ import jalview.renderer.ResidueShaderI; import jalview.schemes.ColourSchemeI; import java.awt.Color; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -39,6 +42,26 @@ import java.util.Map; */ public class SequenceGroup implements AnnotatedCollectionI { + // TODO ideally this event notification functionality should be separated into + // a + // subclass of ViewportProperties similarly to ViewportRanges. Done here as + // quick fix for JAL-2665 + public static final String SEQ_GROUP_CHANGED = "Sequence group changed"; + + protected PropertyChangeSupport changeSupport = new PropertyChangeSupport( + this); + + public void addPropertyChangeListener(PropertyChangeListener listener) + { + changeSupport.addPropertyChangeListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) + { + changeSupport.removePropertyChangeListener(listener); + } + // end of event notification functionality initialisation + String groupName; String description; @@ -496,6 +519,8 @@ public class SequenceGroup implements AnnotatedCollectionI if (s != null && !sequences.contains(s)) { sequences.add(s); + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, + sequences.size() - 1, sequences.size()); } if (recalc) @@ -620,8 +645,10 @@ public class SequenceGroup implements AnnotatedCollectionI conservation.description = "Conservation for group " + getName() + " less than " + consPercGaps + "% gaps"; // preserve width if already set - int aWidth = (conservation.annotations != null) ? (endRes < conservation.annotations.length ? conservation.annotations.length - : endRes + 1) + int aWidth = (conservation.annotations != null) + ? (endRes < conservation.annotations.length + ? conservation.annotations.length + : endRes + 1) : endRes + 1; conservation.annotations = null; conservation.annotations = new Annotation[aWidth]; // should be alignment @@ -641,8 +668,10 @@ public class SequenceGroup implements AnnotatedCollectionI consensus.description = "Percent Identity"; consensusData = cnsns; // preserve width if already set - int aWidth = (consensus.annotations != null) ? (endRes < consensus.annotations.length ? consensus.annotations.length - : endRes + 1) + int aWidth = (consensus.annotations != null) + ? (endRes < consensus.annotations.length + ? consensus.annotations.length + : endRes + 1) : endRes + 1; consensus.annotations = null; consensus.annotations = new Annotation[aWidth]; // should be alignment width @@ -689,6 +718,8 @@ public class SequenceGroup implements AnnotatedCollectionI synchronized (sequences) { sequences.remove(s); + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, + sequences.size() + 1, sequences.size()); if (recalc) { @@ -725,7 +756,9 @@ public class SequenceGroup implements AnnotatedCollectionI */ public void setStartRes(int i) { + int before = startRes; startRes = i; + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, startRes); } /** @@ -735,7 +768,9 @@ public class SequenceGroup implements AnnotatedCollectionI */ public void setEndRes(int i) { + int before = endRes; endRes = i; + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, endRes); } /** @@ -1282,38 +1317,16 @@ public class SequenceGroup implements AnnotatedCollectionI @Override public Iterable findAnnotation(String calcId) { - List aa = new ArrayList<>(); - if (calcId == null) - { - return aa; - } - for (AlignmentAnnotation a : getAlignmentAnnotation()) - { - if (calcId.equals(a.getCalcId())) - { - aa.add(a); - } - } - return aa; + return AlignmentAnnotation.findAnnotation( + Arrays.asList(getAlignmentAnnotation()), calcId); } @Override public Iterable findAnnotations(SequenceI seq, String calcId, String label) { - ArrayList aa = new ArrayList<>(); - for (AlignmentAnnotation ann : getAlignmentAnnotation()) - { - if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId() - .equals(calcId))) - && (seq == null || (ann.sequenceRef != null && ann.sequenceRef == seq)) - && (label == null || (ann.label != null && ann.label - .equals(label)))) - { - aa.add(ann); - } - } - return aa; + return AlignmentAnnotation.findAnnotations( + Arrays.asList(getAlignmentAnnotation()), seq, calcId, label); } /** @@ -1324,17 +1337,8 @@ public class SequenceGroup implements AnnotatedCollectionI */ public boolean hasAnnotation(String calcId) { - if (calcId != null && !"".equals(calcId)) - { - for (AlignmentAnnotation a : getAlignmentAnnotation()) - { - if (a.getCalcId() == calcId) - { - return true; - } - } - } - return false; + return AlignmentAnnotation + .hasAnnotation(Arrays.asList(getAlignmentAnnotation()), calcId); } /** @@ -1344,7 +1348,10 @@ public class SequenceGroup implements AnnotatedCollectionI { synchronized (sequences) { + int before = sequences.size(); sequences.clear(); + changeSupport.firePropertyChange(SEQ_GROUP_CHANGED, before, + sequences.size()); } } @@ -1432,7 +1439,8 @@ public class SequenceGroup implements AnnotatedCollectionI @Override public boolean isNucleotide() { - if (context != null) { + if (context != null) + { return context.isNucleotide(); } return false;