X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;h=59d8631b0a1be73c9c04ba957ccbb2558204701c;hb=d1aade87dce0266a471dfa1e96d5a94499d5d262;hp=ef4a7a5c89ca284262a40af65414717ee8387c07;hpb=b6d073bedc4b28e1a0e5a3a899cfb0e32349087e;p=jalview.git diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index ef4a7a5..59d8631 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -20,6 +20,22 @@ */ package jalview.structure; +import jalview.analysis.AlignSeq; +import jalview.api.StructureSelectionManagerProvider; +import jalview.commands.CommandI; +import jalview.commands.EditCommand; +import jalview.commands.OrderCommand; +import jalview.datamodel.AlignedCodonFrame; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Annotation; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.util.MappingUtils; +import jalview.util.MessageManager; + import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; @@ -37,22 +53,6 @@ import MCview.Atom; import MCview.PDBChain; import MCview.PDBfile; -import jalview.analysis.AlignSeq; -import jalview.api.StructureSelectionManagerProvider; -import jalview.commands.CommandI; -import jalview.commands.EditCommand; -import jalview.commands.OrderCommand; -import jalview.datamodel.AlignedCodonFrame; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.Annotation; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SearchResults; -import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; -import jalview.util.MappingUtils; -import jalview.util.MessageManager; - public class StructureSelectionManager { public final static String NEWLINE = System.lineSeparator(); @@ -70,13 +70,7 @@ public class StructureSelectionManager /* * Set of any registered mappings between (dataset) sequences. */ - Set seqmappings = new LinkedHashSet(); - - /* - * Reference counters for the above mappings. Remove mappings when ref count - * goes to zero. - */ - Map seqMappingRefCounts = new HashMap(); + public Set seqmappings = new LinkedHashSet(); private List commandListeners = new ArrayList(); @@ -491,8 +485,8 @@ public class StructureSelectionManager mappingDetails.append(String.valueOf(maxAlignseq.seq2start)).append( " "); mappingDetails.append(String.valueOf(maxAlignseq.seq2end)); - mappingDetails.append(NEWLINE).append("SEQ start/end "); + // TODO JAL-1887 should be fixed from here mappingDetails.append( String.valueOf(maxAlignseq.seq1start + seq.getStart() - 1)) .append(" "); @@ -518,8 +512,13 @@ public class StructureSelectionManager if (resNum != tmp.resNumber && tmp.alignmentMapping != -1) { resNum = tmp.resNumber; - mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber; - mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex; + if (tmp.alignmentMapping >= -1) + { + // TODO (JAL-1836) address root cause: negative residue no in PDB + // file + mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber; + mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex; + } } index++; @@ -727,7 +726,10 @@ public class StructureSelectionManager results.addResult(seq, index, index); } - seqListener.highlightSequence(results); + if (!results.isEmpty()) + { + seqListener.highlightSequence(results); + } } } } @@ -739,7 +741,7 @@ public class StructureSelectionManager else if (listener instanceof SecondaryStructureListener) { ((SecondaryStructureListener) listener).mouseOverSequence(seq, - indexpos); + indexpos, index); } } } @@ -756,6 +758,10 @@ public class StructureSelectionManager protected void highlightStructure(StructureListener sl, SequenceI seq, int index) { + if (!sl.isListeningFor(seq)) + { + return; + } int atomNo; List atoms = new ArrayList(); for (StructureMapping sm : mappings) @@ -904,80 +910,89 @@ public class StructureSelectionManager } /** - * Decrement the reference counter for each of the given mappings, and remove - * it entirely if its reference counter reduces to zero. + * Remove the given mapping * - * @param set + * @param acf */ - public void removeMappings(Set set) + public void deregisterMapping(AlignedCodonFrame acf) { - if (set != null) + if (acf != null) { - for (AlignedCodonFrame acf : set) - { - removeMapping(acf); + boolean removed = seqmappings.remove(acf); + if (removed && seqmappings.isEmpty()) + { // debug + System.out.println("All mappings removed"); } } } /** - * Decrement the reference counter for the given mapping, and remove it - * entirely if its reference counter reduces to zero. + * Add each of the given codonFrames to the stored set, if not aready present. * - * @param acf + * @param set */ - public void removeMapping(AlignedCodonFrame acf) + public void registerMappings(Set set) { - if (acf != null && seqmappings.contains(acf)) + if (set != null) { - int count = seqMappingRefCounts.get(acf); - count--; - if (count > 0) - { - seqMappingRefCounts.put(acf, count); - } - else + for (AlignedCodonFrame acf : set) { - seqmappings.remove(acf); - seqMappingRefCounts.remove(acf); + registerMapping(acf); } } } /** - * Add each of the given codonFrames to the stored set. If not aready present, - * increments its reference count instead. - * - * @param set + * Add the given mapping to the stored set, unless already stored. */ - public void addMappings(Set set) + public void registerMapping(AlignedCodonFrame acf) { - if (set != null) + if (acf != null) { - for (AlignedCodonFrame acf : set) + if (!seqmappings.contains(acf)) { - addMapping(acf); + seqmappings.add(acf); } } } /** - * Add the given mapping to the stored set, or if already stored, increment - * its reference counter. + * Resets this object to its initial state by removing all registered + * listeners, codon mappings, PDB file mappings */ - public void addMapping(AlignedCodonFrame acf) + public void resetAll() { - if (acf != null) + if (mappings != null) { - if (seqmappings.contains(acf)) - { - seqMappingRefCounts.put(acf, seqMappingRefCounts.get(acf) + 1); - } - else - { - seqmappings.add(acf); - seqMappingRefCounts.put(acf, 1); - } + mappings.clear(); + } + if (seqmappings != null) + { + seqmappings.clear(); + } + if (sel_listeners != null) + { + sel_listeners.clear(); + } + if (listeners != null) + { + listeners.clear(); + } + if (commandListeners != null) + { + commandListeners.clear(); + } + if (view_listeners != null) + { + view_listeners.clear(); + } + if (pdbFileNameId != null) + { + pdbFileNameId.clear(); + } + if (pdbIdFileName != null) + { + pdbIdFileName.clear(); } }