X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;h=d1bccd8643f5219bfb7378e7652fb6639db0a082;hb=362f2db1b01f3562784864a1d6ac5f7b9be0a18a;hp=0fb84280810ec54fc77b726aed9541990afd2abf;hpb=27de1236a81237ca094abd34661ee156c1bdb521;p=jalview.git diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 0fb8428..d1bccd8 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -1,5 +1,5 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. @@ -22,23 +22,44 @@ import java.util.*; import MCview.*; import jalview.analysis.*; +import jalview.api.AlignmentViewPanel; +import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.*; public class StructureSelectionManager { - static StructureSelectionManager instance; + static IdentityHashMap instances; StructureMapping[] mappings; + /** + * debug function - write all mappings to stdout + */ + public void reportMapping() { + if (mappings==null) + { + System.err.println("reportMapping: No PDB/Sequence mappings."); + }else{ + System.err.println("reportMapping: There are "+mappings.length+" mappings."); + for (int m=0;m(); + } + StructureSelectionManager instance=instances.get(context); + if (instance==null) + { + instances.put(context, instance=new StructureSelectionManager()); } - return instance; } @@ -73,6 +94,10 @@ public class StructureSelectionManager Vector listeners = new Vector(); + /** + * register a listener for alignment sequence mouseover events + * @param svl + */ public void addStructureViewerListener(Object svl) { if (!listeners.contains(svl)) @@ -209,7 +234,9 @@ public class StructureSelectionManager maxChain.transferRESNUMFeatures(sequence[s], null); - int[][] mapping = new int[sequence[s].getEnd() + 2][2]; + // allocate enough slots to store the mapping from positions in + // sequence[s] to the associated chain + int[][] mapping = new int[sequence[s].findPosition(sequence[s].getLength()) + 2][2]; int resNum = -10000; int index = 0; @@ -253,6 +280,17 @@ public class StructureSelectionManager public void removeStructureViewerListener(Object svl, String[] pdbfiles) { listeners.removeElement(svl); + if (svl instanceof SequenceListener) + { + for (int i=0;i 0) + if (results!=null) { for (int i = 0; i < listeners.size(); i++) { @@ -359,7 +404,8 @@ public class StructureSelectionManager * the sequence position (if -1, seq.findPosition is called to * resolve the residue number) */ - public void mouseOverSequence(SequenceI seq, int indexpos, int index) + public void mouseOverSequence(SequenceI seq, int indexpos, int index, + VamsasSource source) { boolean hasSequenceListeners = handlingVamsasMo || seqmappings != null; SearchResults results = null; @@ -442,8 +488,8 @@ public class StructureSelectionManager // index); // pass the mouse over and absolute position onto the // VamsasListener(s) - ((VamsasListener) listeners.elementAt(i)) - .mouseOver(seq, indexpos); + ((VamsasListener) listeners.elementAt(i)).mouseOver(seq, + indexpos, source); } } } @@ -464,14 +510,15 @@ public class StructureSelectionManager * @param position * in an alignment sequence */ - public void mouseOverVamsasSequence(SequenceI sequenceI, int position) + public void mouseOverVamsasSequence(SequenceI sequenceI, int position, + VamsasSource source) { handlingVamsasMo = true; long msg = sequenceI.hashCode() * (1 + position); if (lastmsg != msg) { lastmsg = msg; - mouseOverSequence(sequenceI, position, -1); + mouseOverSequence(sequenceI, position, -1, source); } handlingVamsasMo = false; } @@ -634,7 +681,7 @@ public class StructureSelectionManager modifySeqMappingList(true, codonFrames); } - Vector sel_listeners = new Vector(); + Vector sel_listeners = new Vector(); public void addSelectionListener(SelectionListener selecter) { @@ -671,4 +718,67 @@ public class StructureSelectionManager } } } + + Vector view_listeners=new Vector(); + public synchronized void sendViewPosition(jalview.api.AlignmentViewPanel source, int startRes, + int endRes, int startSeq, int endSeq) + { + + if (view_listeners != null && view_listeners.size() > 0) + { + Enumeration listeners = view_listeners.elements(); + while (listeners.hasMoreElements()) + { + AlignmentViewPanelListener slis = listeners + .nextElement(); + if (slis != source) + { + slis.viewPosition(startRes, endRes, startSeq, endSeq, source); + } + ; + } + } + } + + + public void finalize() throws Throwable { + if (listeners!=null) { + listeners.clear(); + listeners=null; + } + if (mappingData!=null) + { + mappingData.clear(); + mappingData=null; + } + if (sel_listeners!=null) + { + sel_listeners.clear(); + sel_listeners=null; + } + if (view_listeners!=null) + { + view_listeners.clear(); + view_listeners=null; + } + mappings=null; + seqmappingrefs=null; + } + + /** + * release all references associated with this manager provider + * @param jalviewLite + */ + public static void release(StructureSelectionManagerProvider jalviewLite) + { + StructureSelectionManager mnger=(instances.get(jalviewLite)); + if (mnger!=null) + { + instances.remove(jalviewLite); + try { + mnger.finalize(); + } catch (Throwable x){}; + } + } + }