From 362f2db1b01f3562784864a1d6ac5f7b9be0a18a Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 17 May 2011 13:49:57 +0100 Subject: [PATCH] refactor to allow distinct StructureSelectionManager instances for each jalview context in a JVM (JAL-621, JAL-569, JAL-731, JAL-735, JAL-832) --- src/MCview/AppletPDBCanvas.java | 2 +- src/MCview/PDBCanvas.java | 2 +- src/jalview/api/AlignmentViewPanel.java | 3 +- src/jalview/appletgui/AlignFrame.java | 13 ++- src/jalview/appletgui/AlignViewport.java | 10 ++- src/jalview/appletgui/AlignmentPanel.java | 58 ++++++++++--- src/jalview/appletgui/AppletJmol.java | 9 +- src/jalview/appletgui/AppletJmolBinding.java | 7 +- src/jalview/appletgui/ExtJmol.java | 4 +- src/jalview/appletgui/SeqPanel.java | 15 +++- src/jalview/appletgui/TreePanel.java | 6 ++ src/jalview/bin/JalviewLite.java | 88 ++++++++++++++++---- src/jalview/ext/jmol/JalviewJmolBinding.java | 25 ++++-- src/jalview/gui/AlignViewport.java | 14 +++- src/jalview/gui/AlignmentPanel.java | 19 +++-- src/jalview/gui/AppJmol.java | 13 ++- src/jalview/gui/AppJmolBinding.java | 5 +- src/jalview/gui/Desktop.java | 4 +- src/jalview/gui/Jalview2XML.java | 5 +- src/jalview/gui/PopupMenu.java | 5 +- src/jalview/gui/SeqPanel.java | 4 +- src/jalview/gui/VamsasApplication.java | 2 +- src/jalview/io/VamsasAppDatastore.java | 2 +- src/jalview/io/vamsas/Sequencemapping.java | 3 +- src/jalview/javascript/JSFunctionExec.java | 27 ++++-- .../javascript/MouseOverStructureListener.java | 29 +++++-- .../structure/StructureSelectionManager.java | 83 ++++++++++++++++-- 27 files changed, 345 insertions(+), 112 deletions(-) mode change 100755 => 100644 src/MCview/AppletPDBCanvas.java mode change 100755 => 100644 src/MCview/PDBCanvas.java mode change 100755 => 100644 src/jalview/appletgui/AlignFrame.java mode change 100755 => 100644 src/jalview/appletgui/AlignViewport.java mode change 100755 => 100644 src/jalview/appletgui/AlignmentPanel.java mode change 100755 => 100644 src/jalview/appletgui/SeqPanel.java mode change 100755 => 100644 src/jalview/appletgui/TreePanel.java mode change 100755 => 100644 src/jalview/bin/JalviewLite.java mode change 100755 => 100644 src/jalview/gui/AlignViewport.java mode change 100755 => 100644 src/jalview/gui/AlignmentPanel.java mode change 100755 => 100644 src/jalview/gui/Desktop.java mode change 100755 => 100644 src/jalview/gui/Jalview2XML.java mode change 100755 => 100644 src/jalview/gui/PopupMenu.java mode change 100755 => 100644 src/jalview/gui/SeqPanel.java diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java old mode 100755 new mode 100644 index 39d0926..756f2a5 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -132,7 +132,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, this.pdbentry = pdbentry; this.sequence = seq; - ssm = StructureSelectionManager.getStructureSelectionManager(); + ssm = StructureSelectionManager.getStructureSelectionManager(ap.av.applet); try { diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java old mode 100755 new mode 100644 index f9461e1..ed4cc1b --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -124,7 +124,7 @@ public class PDBCanvas extends JPanel implements MouseListener, this.pdbentry = pdbentry; this.sequence = seq; - ssm = StructureSelectionManager.getStructureSelectionManager(); + ssm = ap.av.getStructureSelectionManager(); try { diff --git a/src/jalview/api/AlignmentViewPanel.java b/src/jalview/api/AlignmentViewPanel.java index 7b3d3cd..fcda077 100644 --- a/src/jalview/api/AlignmentViewPanel.java +++ b/src/jalview/api/AlignmentViewPanel.java @@ -4,6 +4,7 @@ package jalview.api; import jalview.datamodel.AlignmentI; +import jalview.structure.StructureSelectionManager; /** * abstract interface implemented by alignment panels holding an alignment view @@ -14,5 +15,5 @@ public interface AlignmentViewPanel { AlignmentI getAlignment(); - + StructureSelectionManager getStructureSelectionManager(); } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java old mode 100755 new mode 100644 index 4634142..3654e0c --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1174,8 +1174,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (PaintRefresher.components.size() == 0 && viewport.applet == null) { System.exit(0); + } else { } - + viewport = null; + alignPanel = null; this.dispose(); } @@ -2280,7 +2282,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } jalview.structure.StructureSelectionManager - .getStructureSelectionManager().sequenceColoursChanged( + .getStructureSelectionManager(viewport.applet).sequenceColoursChanged( alignPanel); alignPanel.paintAlignment(true); @@ -3511,7 +3513,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (applet.useXtrnalSviewer) { // register the association(s) and quit, don't create any windows. - if (StructureSelectionManager.getStructureSelectionManager().setMapping(seqs, chains, pdb.getFile(), protocol)==null) { + if (StructureSelectionManager.getStructureSelectionManager(applet).setMapping(seqs, chains, pdb.getFile(), protocol)==null) { System.err.println("Failed to map "+pdb.getFile()+" ("+protocol+") to any sequences"); } return; @@ -3572,4 +3574,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { alignPanel.seqPanel.selection(sel, csel, null); } + + public void scrollTo(int row, int column) + { + alignPanel.seqPanel.scrollTo(row, column); + } } diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java old mode 100755 new mode 100644 index 87566c6..264100e --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -26,6 +26,7 @@ import jalview.bin.*; import jalview.datamodel.*; import jalview.schemes.*; import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; import jalview.structure.VamsasSource; public class AlignViewport implements SelectionSource, VamsasSource @@ -144,6 +145,13 @@ public class AlignViewport implements SelectionSource, VamsasSource String sequenceSetID; Hashtable hiddenRepSequences; + + public void finalize() { + applet=null; + quality=null; + alignment=null; + colSel=null; + } public AlignViewport(AlignmentI al, JalviewLite applet) { @@ -1617,7 +1625,7 @@ public class AlignViewport implements SelectionSource, VamsasSource public void sendSelection() { jalview.structure.StructureSelectionManager - .getStructureSelectionManager().sendSelection( + .getStructureSelectionManager(applet).sendSelection( new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this); } diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java old mode 100755 new mode 100644 index e4b9b59..9bb3e4d --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -24,6 +24,7 @@ import java.util.Vector; import jalview.api.AlignmentViewPanel; import jalview.datamodel.*; +import jalview.structure.StructureSelectionManager; public class AlignmentPanel extends Panel implements AdjustmentListener, AlignmentViewPanel { @@ -48,7 +49,19 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme // this value is set false when selection area being dragged boolean fastPaint = true; - + + public void finalize() { + alignFrame=null; + av=null; + seqPanel=null; + seqPanelHolder=null; + sequenceHolderPanel=null; + scalePanel=null; + scalePanelHolder=null; + annotationPanel=null; + annotationPanelHolder=null; + annotationSpaceFillerHolder=null; + } public AlignmentPanel(AlignFrame af, final AlignViewport av) { try @@ -94,6 +107,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme setScrollValues(av.getStartRes(), av.getStartSeq()); repaint(); } + }); Dimension d = calculateIdWidth(); @@ -283,7 +297,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme } if (av.applet.debug) { // DEBUG - System.out.println("DEBUG: scroll didn't happen: start=" + r[0] + System.out.println("DEBUG: scroll: start=" + r[0] + " av.getStartRes()=" + av.getStartRes() + " end=" + r[1] + " seq.end=" + seq.getEnd() + " av.getEndRes()=" + av.getEndRes() + " hextent=" + hextent); @@ -298,17 +312,24 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { return false; } - if (av.hasHiddenColumns) + return scrollTo(start, end, seqIndex, false, redrawOverview); + } + return true; + } + public boolean scrollTo(int ostart, int end, int seqIndex, boolean scrollToNearest, boolean redrawOverview) + { + int start=-1; + if (av.hasHiddenColumns) + { + start = av.getColumnSelection().findColumnPosition(ostart); + end = av.getColumnSelection().findColumnPosition(end); + if (start == end) { - start = av.getColumnSelection().findColumnPosition(start); - end = av.getColumnSelection().findColumnPosition(end); - if (start == end) + if (!scrollToNearest && !av.colSel.isVisible(ostart)) { - if (!av.colSel.isVisible(r[0])) - { - // don't scroll - position isn't visible - return false; - } + // don't scroll - position isn't visible + return false; + } } } if (!av.wrapAlignment) @@ -341,7 +362,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { scrollToWrappedVisible(start); } - } if (redrawOverview && overviewPanel != null) { overviewPanel.setBoxPosition(); @@ -581,6 +601,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { overviewPanel.setBoxPosition(); } + sendViewPosition(); + } @@ -658,8 +680,13 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme annotationPanel.fastPaint(av.getStartRes() - oldX); } } + sendViewPosition(); } + private void sendViewPosition() + { + StructureSelectionManager.getStructureSelectionManager(av.applet).sendViewPosition(this, av.startRes, av.endRes, av.startSeq, av.endSeq); + } public void paintAlignment(boolean updateOverview) { @@ -668,7 +695,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme if (updateOverview) { jalview.structure.StructureSelectionManager - .getStructureSelectionManager().sequenceColoursChanged(this); + .getStructureSelectionManager(av.applet).sequenceColoursChanged(this); if (overviewPanel != null) { @@ -896,5 +923,10 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { return av.alignment; } + @Override + public StructureSelectionManager getStructureSelectionManager() + { + return StructureSelectionManager.getStructureSelectionManager(av.applet); + } } diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 5b31db8..0ff2467 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -132,7 +132,7 @@ public class AppletJmol extends EmbmenuFrame implements AlignmentPanel ap, String protocol) { this.ap = ap; - jmb = new AppletJmolBinding(this, new PDBEntry[] + jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(), new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }, new String[][] { chains }, protocol); @@ -157,12 +157,12 @@ public class AppletJmol extends EmbmenuFrame implements } String alreadyMapped = StructureSelectionManager - .getStructureSelectionManager().alreadyMappedToFile( + .getStructureSelectionManager(ap.av.applet).alreadyMappedToFile( pdbentry.getId()); MCview.PDBfile reader = null; if (alreadyMapped != null) { - reader = StructureSelectionManager.getStructureSelectionManager() + reader = StructureSelectionManager.getStructureSelectionManager(ap.av.applet) .setMapping(seq, chains, pdbentry.getFile(), protocol); // PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW? // FOR NOW, LETS JUST OPEN A NEW WINDOW @@ -383,8 +383,7 @@ public class AppletJmol extends EmbmenuFrame implements { for (int s = 0; s < jmb.pdbentry.length; s++) { - sb.append(StructureSelectionManager - .getStructureSelectionManager().printMapping( + sb.append(jmb.printMapping( jmb.pdbentry[s].getFile())); sb.append("\n"); } diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 152ebe9..ffe00b5 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -24,6 +24,7 @@ import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.structure.StructureSelectionManager; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.api.JmolViewer; @@ -38,10 +39,10 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding */ private AppletJmol appletJmolBinding; - public AppletJmolBinding(AppletJmol appletJmol, PDBEntry[] pdbentry, + public AppletJmolBinding(AppletJmol appletJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains, String protocol) { - super(pdbentry, seq, chains, protocol); + super(sSm, pdbentry, seq, chains, protocol); appletJmolBinding = appletJmol; } @@ -175,8 +176,6 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding @Override public void releaseReferences(Object svl) { - // TODO Auto-generated method stub - } } diff --git a/src/jalview/appletgui/ExtJmol.java b/src/jalview/appletgui/ExtJmol.java index 5714ce9..e1734d0 100644 --- a/src/jalview/appletgui/ExtJmol.java +++ b/src/jalview/appletgui/ExtJmol.java @@ -48,13 +48,13 @@ public class ExtJmol extends JalviewJmolBinding PDBEntry[] pdbentry, SequenceI[][] seq, String[][] chains, String protocol) { - super(pdbentry, seq, chains, protocol); + super(alframe.alignPanel.getStructureSelectionManager(), pdbentry, seq, chains, protocol); } public ExtJmol(JmolViewer viewer, AlignmentPanel alignPanel, SequenceI[][] seqs) { - super(viewer); + super(alignPanel.getStructureSelectionManager(), viewer); ap = alignPanel; this.sequence = seqs; notifyFileLoaded(null, null, null, null, 0); diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java old mode 100755 new mode 100644 index 29164bb..ade0afd --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -91,7 +91,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, seqCanvas.addMouseMotionListener(this); seqCanvas.addMouseListener(this); - ssm = StructureSelectionManager.getStructureSelectionManager(); + ssm = StructureSelectionManager.getStructureSelectionManager(av.applet); ssm.addStructureViewerListener(this); seqCanvas.repaint(); @@ -1779,4 +1779,17 @@ public class SeqPanel extends Panel implements MouseMotionListener, } } + /** + * scroll to the given row/column - or nearest visible location + * @param row + * @param column + */ + public void scrollTo(int row, int column) + { + + row = row<0 ? ap.av.startSeq : row; + column = column<0 ? ap.av.startRes : column; + ap.scrollTo(row, row, column, true, true); + } + } diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java old mode 100755 new mode 100644 index d424367..7595a50 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -49,6 +49,12 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, { return tree; } + + public void finalize() throws Throwable { + ap=null; + av=null; + super.finalize(); + } /** * Creates a new TreePanel object. diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java old mode 100755 new mode 100644 index 8e22a1a..a4bebef --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -17,7 +17,9 @@ */ package jalview.bin; +import jalview.api.StructureSelectionManagerProvider; import jalview.appletgui.AlignFrame; +import jalview.appletgui.AlignViewport; import jalview.appletgui.EmbmenuFrame; import jalview.appletgui.FeatureSettings; import jalview.datamodel.Alignment; @@ -60,9 +62,9 @@ import netscape.javascript.JSObject; * Jalview Applet. Runs in Java 1.18 runtime * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.92 $ */ -public class JalviewLite extends Applet +public class JalviewLite extends Applet implements StructureSelectionManagerProvider { // ///////////////////////////////////////// @@ -182,12 +184,12 @@ public class JalviewLite extends Applet && (alignedPosition.trim().length() == 0 || alignedPosition .toLowerCase().indexOf("false") > -1)) { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .mouseOverVamsasSequence(sq, sq.findIndex(apos), null); } else { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .mouseOverVamsasSequence(sq, apos, null); } @@ -711,7 +713,7 @@ public class JalviewLite extends Applet setMouseoverListener(currentAlignFrame, listener); } - private Vector javascriptListeners = new Vector(); + private Vector javascriptListeners = new Vector(); public void setMouseoverListener(AlignFrame af, String listener) { @@ -728,7 +730,7 @@ public class JalviewLite extends Applet jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener( this, af, listener); javascriptListeners.addElement(mol); - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .addStructureViewerListener(mol); if (debug) { @@ -760,7 +762,7 @@ public class JalviewLite extends Applet jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender( this, af, listener); javascriptListeners.addElement(mol); - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .addSelectionListener(mol); if (debug) { @@ -787,7 +789,7 @@ public class JalviewLite extends Applet jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener( this, listener, separatorListToArray(modelSet)); javascriptListeners.addElement(mol); - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .addStructureViewerListener(mol); if (debug) { @@ -830,12 +832,12 @@ public class JalviewLite extends Applet msSize--; if (lstner instanceof SelectionListener) { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .removeSelectionListener((SelectionListener) lstner); } else { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .removeStructureViewerListener(lstner, null); } rprt = debug; @@ -858,25 +860,52 @@ public class JalviewLite extends Applet public void stop() { + System.err.println("Applet "+getName()+" stop()."); + tidyUp(); + } + public void destroy() + { + System.err.println("Applet "+getName()+" destroy()."); + tidyUp(); + } + private void tidyUp() + { + removeAll(); + if (currentAlignFrame!=null && currentAlignFrame.viewport!=null + && currentAlignFrame.viewport.applet!=null) + { + AlignViewport av = currentAlignFrame.viewport; + currentAlignFrame.closeMenuItem_actionPerformed(); + av.applet=null; + currentAlignFrame=null; + } if (javascriptListeners != null) { while (javascriptListeners.size() > 0) { - Object mol = javascriptListeners.elementAt(0); + jalview.javascript.JSFunctionExec mol = javascriptListeners.elementAt(0); javascriptListeners.removeElement(mol); if (mol instanceof SelectionListener) { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .removeSelectionListener((SelectionListener) mol); } else { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .removeStructureViewerListener(mol, null); } + mol.jvlite=null; } } - jsFunctionExec.stopQueue(); + if (jsFunctionExec!=null) { + jsFunctionExec.stopQueue(); + jsFunctionExec.jvlite=null; + } + initialAlignFrame=null; + jsFunctionExec = null; + javascriptListeners=null; + StructureSelectionManager.release(this); } private jalview.javascript.JSFunctionExec jsFunctionExec; /** @@ -892,7 +921,7 @@ public class JalviewLite extends Applet { try { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(this) .mouseOverStructure(new Integer(pdbResNum).intValue(), chain, pdbfile); if (debug) @@ -906,6 +935,24 @@ public class JalviewLite extends Applet + pdbResNum + "'"); } } + /** + * adjust horizontal/vertical scroll to the make the given location the top left hand corner for given current view + * + * @param alf + * @param topRow + * @param leftHandColumn + */ + public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn) + { + try { + alf.scrollTo(new Integer(topRow).intValue(), new Integer(leftHandColumn).intValue()); + + } catch (Exception ex) + { + System.err.println("Couldn't parse integer arguments (topRow='"+topRow+"' and leftHandColumn='"+leftHandColumn+"'"); + ex.printStackTrace(); + } + } // ////////////////////////////////////////////// // ////////////////////////////////////////////// @@ -1235,11 +1282,15 @@ public class JalviewLite extends Applet { if (frame instanceof AlignFrame) { + AlignViewport vp = ((AlignFrame) frame).viewport; ((AlignFrame) frame).closeMenuItem_actionPerformed(); - if (((AlignFrame) frame).viewport.applet.currentAlignFrame == frame) + if (vp.applet.currentAlignFrame == frame) { - ((AlignFrame) frame).viewport.applet.currentAlignFrame = null; + vp.applet.currentAlignFrame = null; } + vp.applet=null; + vp=null; + } lastFrameX -= 40; lastFrameY -= 40; @@ -1794,6 +1845,7 @@ public class JalviewLite extends Applet applet.remove(launcher); applet.repaint(); } + callInitCallback(); } /** @@ -2173,7 +2225,7 @@ public class JalviewLite extends Applet public void start() { - callInitCallback(); +// callInitCallback(); } private Hashtable jshashes=new Hashtable(); private Hashtable> jsmessages=new Hashtable>(); diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 8e1ede4..6747349 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -30,6 +30,7 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.api.SequenceStructureBinding; +import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.*; import jalview.structure.*; import jalview.io.*; @@ -45,7 +46,7 @@ import jalview.schemes.*; public abstract class JalviewJmolBinding implements StructureListener, JmolStatusListener, SequenceStructureBinding, - JmolSelectionListener, ComponentListener + JmolSelectionListener, ComponentListener, StructureSelectionManagerProvider { /** @@ -128,13 +129,14 @@ public abstract class JalviewJmolBinding implements StructureListener, */ public SequenceI[][] sequence; - StructureSelectionManager ssm; + public StructureSelectionManager ssm; public JmolViewer viewer; - public JalviewJmolBinding(PDBEntry[] pdbentry, SequenceI[][] sequenceIs, + public JalviewJmolBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, String protocol) { + this.ssm = ssm; this.sequence = sequenceIs; this.chains = chains; this.pdbentry = pdbentry; @@ -152,8 +154,9 @@ public abstract class JalviewJmolBinding implements StructureListener, */ } - public JalviewJmolBinding(JmolViewer viewer2) + public JalviewJmolBinding(StructureSelectionManager ssm, JmolViewer viewer2) { + this.ssm = ssm; viewer = viewer2; viewer.setJmolStatusListener(this); viewer.addSelectionListener(this); @@ -227,8 +230,7 @@ public abstract class JalviewJmolBinding implements StructureListener, { viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE); // remove listeners for all structures in viewer - StructureSelectionManager.getStructureSelectionManager() - .removeStructureViewerListener(this, this.getPdbFile()); + ssm.removeStructureViewerListener(this, this.getPdbFile()); // and shut down jmol viewer.evalStringQuiet("zap"); viewer.setJmolStatusListener(null); @@ -1044,7 +1046,6 @@ public abstract class JalviewJmolBinding implements StructureListener, chainFile = new Hashtable(); boolean notifyLoaded = false; String[] modelfilenames = getPdbFile(); - ssm = StructureSelectionManager.getStructureSelectionManager(); // first check if we've lost any structures if (oldmodels != null && oldmodels.length > 0) { @@ -1532,4 +1533,14 @@ public abstract class JalviewJmolBinding implements StructureListener, chains[pe] = null; } } + /** + * + * @param pdbfile + * @return text report of alignment between pdbfile and any associated alignment sequences + */ + public String printMapping(String pdbfile) + { + return ssm.printMapping(pdbfile); + } + } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java old mode 100755 new mode 100644 index 35743ab..af3ab95 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -40,6 +40,7 @@ import java.util.*; import java.awt.*; import jalview.analysis.*; +import jalview.api.StructureSelectionManagerProvider; import jalview.bin.*; @@ -54,7 +55,7 @@ import jalview.structure.VamsasSource; * DOCUMENT ME! * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.141 $ */ public class AlignViewport implements SelectionSource, VamsasSource { @@ -940,13 +941,13 @@ public class AlignViewport implements SelectionSource, VamsasSource { if (alignment != null && alignment.getCodonFrames() != null) { - StructureSelectionManager.getStructureSelectionManager() + StructureSelectionManager.getStructureSelectionManager(Desktop.instance) .removeMappings(alignment.getCodonFrames()); } this.alignment = align; if (alignment.getCodonFrames() != null) { - StructureSelectionManager.getStructureSelectionManager().addMappings( + StructureSelectionManager.getStructureSelectionManager(Desktop.instance).addMappings( alignment.getCodonFrames()); } } @@ -2050,7 +2051,7 @@ public class AlignViewport implements SelectionSource, VamsasSource public void sendSelection() { jalview.structure.StructureSelectionManager - .getStructureSelectionManager().sendSelection( + .getStructureSelectionManager(Desktop.instance).sendSelection( new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this); } @@ -2242,4 +2243,9 @@ public class AlignViewport implements SelectionSource, VamsasSource } } } + + public StructureSelectionManager getStructureSelectionManager() + { + return StructureSelectionManager.getStructureSelectionManager(Desktop.instance); + } } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java old mode 100755 new mode 100644 index 3ea6496..d2aa6d6 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -33,12 +33,13 @@ import jalview.datamodel.*; import jalview.jbgui.*; import jalview.schemes.*; import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; /** * DOCUMENT ME! * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.161 $ */ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable, AlignmentViewPanel @@ -683,8 +684,7 @@ public class AlignmentPanel extends GAlignmentPanel implements if (updateOverview) { - jalview.structure.StructureSelectionManager - .getStructureSelectionManager().sequenceColoursChanged(this); + av.getStructureSelectionManager().sequenceColoursChanged(this); if (overviewPanel != null) { @@ -1320,15 +1320,14 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public void closePanel() { - jalview.structure.StructureSelectionManager ssm = jalview.structure.StructureSelectionManager - .getStructureSelectionManager(); - ssm.removeStructureViewerListener(seqPanel, null); - ssm.removeSelectionListener(seqPanel); PaintRefresher.RemoveComponent(seqPanel.seqCanvas); PaintRefresher.RemoveComponent(idPanel.idCanvas); PaintRefresher.RemoveComponent(this); if (av != null) { + jalview.structure.StructureSelectionManager ssm = av.getStructureSelectionManager(); + ssm.removeStructureViewerListener(seqPanel, null); + ssm.removeSelectionListener(seqPanel); av.alignment = null; av = null; } @@ -1445,4 +1444,10 @@ public class AlignmentPanel extends GAlignmentPanel implements alignFrame.setDisplayedView(this); } } + + @Override + public StructureSelectionManager getStructureSelectionManager() + { + return av.getStructureSelectionManager(); + } } diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 62f4d13..fdf00c0 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -116,7 +116,7 @@ public class AppJmol extends GStructureViewer implements Runnable, } // / TODO: check if protocol is needed to be set, and if chains are // autodiscovered. - jmb = new AppJmolBinding(this, pdbentrys, seqs, null, null); + jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), pdbentrys, seqs, null, null); jmb.setLoadingFromArchive(true); addAlignmentPanel(ap); @@ -233,8 +233,7 @@ public class AppJmol extends GStructureViewer implements Runnable, progressBar = ap.alignFrame; // //////////////////////////////// // Is the pdb file already loaded? - String alreadyMapped = StructureSelectionManager - .getStructureSelectionManager().alreadyMappedToFile( + String alreadyMapped = jmb.ssm.alreadyMappedToFile( pdbentry.getId()); if (alreadyMapped != null) @@ -247,8 +246,7 @@ public class AppJmol extends GStructureViewer implements Runnable, if (option == JOptionPane.YES_OPTION) { - StructureSelectionManager.getStructureSelectionManager() - .setMapping(seq, chains, alreadyMapped, + jmb.ssm.setMapping(seq, chains, alreadyMapped, AppletFormatAdapter.FILE); if (ap.seqPanel.seqCanvas.fr != null) { @@ -309,7 +307,7 @@ public class AppJmol extends GStructureViewer implements Runnable, } // ///////////////////////////////// - jmb = new AppJmolBinding(this, new PDBEntry[] + jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }, null, null); addAlignmentPanel(ap); @@ -868,8 +866,7 @@ public class AppJmol extends GStructureViewer implements Runnable, { for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++) { - cap.appendText(StructureSelectionManager - .getStructureSelectionManager().printMapping( + cap.appendText(jmb.printMapping( jmb.pdbentry[pdbe].getFile())); cap.appendText("\n"); } diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 231d4e2..d15b9eb 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -31,6 +31,7 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.structure.StructureSelectionManager; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.api.JmolViewer; @@ -45,10 +46,10 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding */ private AppJmol appJmolWindow; - public AppJmolBinding(AppJmol appJmol, PDBEntry[] pdbentry, + public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, String protocol) { - super(pdbentry, sequenceIs, chains, protocol); + super(sSm, pdbentry, sequenceIs, chains, protocol); appJmolWindow = appJmol; } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java old mode 100755 new mode 100644 index dbb6955..db2dbf2 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -48,10 +48,10 @@ import javax.swing.event.MenuListener; * * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.155 $ */ public class Desktop extends jalview.jbgui.GDesktop implements - DropTargetListener, ClipboardOwner, IProgressIndicator + DropTargetListener, ClipboardOwner, IProgressIndicator, jalview.api.StructureSelectionManagerProvider { private JalviewChangeSupport changeSupport = new JalviewChangeSupport(); diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java old mode 100755 new mode 100644 index 5a13723..e639844 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -48,7 +48,7 @@ import jalview.util.jarInputStreamProvider; * will be :) * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.134 $ */ public class Jalview2XML { @@ -2831,8 +2831,7 @@ public class Jalview2XML String pdbFile = (String) filedat[0]; SequenceI[] seq = (SequenceI[]) ((Vector) filedat[2]) .toArray(new SequenceI[0]); - StructureSelectionManager.getStructureSelectionManager() - .setMapping(seq, null, pdbFile, + ((AppJmol) comp).jmb.ssm.setMapping(seq, null, pdbFile, jalview.io.AppletFormatAdapter.FILE); ((AppJmol) comp).jmb.addSequenceForStructFile(pdbFile, seq); } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java old mode 100755 new mode 100644 index 07fdeea..d44ecdf --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -37,7 +37,7 @@ import jalview.util.UrlLink; * DOCUMENT ME! * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.118 $ */ public class PopupMenu extends JPopupMenu { @@ -1826,8 +1826,7 @@ public class PopupMenu extends JPopupMenu public void colourByStructure(String pdbid) { - Annotation[] anots = jalview.structure.StructureSelectionManager - .getStructureSelectionManager().colourSequenceFromStructure( + Annotation[] anots = ap.av.getStructureSelectionManager().colourSequenceFromStructure( sequence, pdbid); AlignmentAnnotation an = new AlignmentAnnotation("Structure", diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java old mode 100755 new mode 100644 index a1913a8..50ece22 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -33,7 +33,7 @@ import jalview.structure.*; * DOCUMENT ME! * * @author $author$ - * @version $Revision$ + * @version $Revision: 1.130 $ */ public class SeqPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener, SequenceListener, @@ -123,7 +123,7 @@ public class SeqPanel extends JPanel implements MouseListener, addMouseMotionListener(this); addMouseListener(this); addMouseWheelListener(this); - ssm = StructureSelectionManager.getStructureSelectionManager(); + ssm = StructureSelectionManager.getStructureSelectionManager(Desktop.instance); ssm.addStructureViewerListener(this); ssm.addSelectionListener(this); } diff --git a/src/jalview/gui/VamsasApplication.java b/src/jalview/gui/VamsasApplication.java index cd9a529..1da1ae9 100644 --- a/src/jalview/gui/VamsasApplication.java +++ b/src/jalview/gui/VamsasApplication.java @@ -756,7 +756,7 @@ public class VamsasApplication implements SelectionSource,VamsasSource { final IPickManager pm = vclient.getPickManager(); final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(); + .getStructureSelectionManager(Desktop.instance); final VamsasApplication me = this; pm.registerMessageHandler(new IMessageHandler() { diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index 06154c8..1d0b463 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -1443,7 +1443,7 @@ public class VamsasAppDatastore if (mappings != null && mappings.length > 0) { jalview.structure.StructureSelectionManager - .getStructureSelectionManager().addMappings(mappings); + .getStructureSelectionManager(Desktop.instance).addMappings(mappings); } } } diff --git a/src/jalview/io/vamsas/Sequencemapping.java b/src/jalview/io/vamsas/Sequencemapping.java index 9263690..ee0c2b6 100644 --- a/src/jalview/io/vamsas/Sequencemapping.java +++ b/src/jalview/io/vamsas/Sequencemapping.java @@ -22,6 +22,7 @@ import java.util.Vector; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Mapping; import jalview.datamodel.SequenceI; +import jalview.gui.Desktop; import jalview.io.VamsasAppDatastore; import uk.ac.vamsas.client.Vobject; import uk.ac.vamsas.objects.core.AlignmentSequence; @@ -364,7 +365,7 @@ public class Sequencemapping extends Rangetype } bindjvvobj(mapping, sequenceMapping); jalview.structure.StructureSelectionManager - .getStructureSelectionManager().addMappings( + .getStructureSelectionManager(Desktop.instance).addMappings( new AlignedCodonFrame[] { afc }); // Try to link up any conjugate database references in the two sequences diff --git a/src/jalview/javascript/JSFunctionExec.java b/src/jalview/javascript/JSFunctionExec.java index 8eb0bd9..6f7fc43 100644 --- a/src/jalview/javascript/JSFunctionExec.java +++ b/src/jalview/javascript/JSFunctionExec.java @@ -9,7 +9,7 @@ import jalview.bin.JalviewLite; public class JSFunctionExec implements Runnable { - JalviewLite jvlite; + public JalviewLite jvlite; public JSFunctionExec(JalviewLite applet) { @@ -18,7 +18,15 @@ public class JSFunctionExec implements Runnable jsExecQueue = jvlite.getJsExecQueue(); jvlite.setExecutor(this); } - + public void finalize() { + jvlite=null; + executor=null; + if (jsExecQueue!=null) + { + jsExecQueue.clear(); + } + jsExecQueue=null; + } private Vector jsExecQueue; private Thread executor = null; @@ -27,18 +35,27 @@ public class JSFunctionExec implements Runnable { if (jsExecQueue != null) { + Vector q=null; synchronized (jsExecQueue) { - Vector q = jsExecQueue; - q.removeAllElements(); + q = jsExecQueue; jsExecQueue = null; + } + if (q!=null ) { + for (JSFunctionExec jx : q) + { + jx.jvlite=null; + + } + q.removeAllElements(); synchronized (q) { q.notifyAll(); } } - executor = null; } + jvlite=null; + executor = null; } public void run() diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 2f28820..c1d3a40 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -113,7 +113,7 @@ public class MouseOverStructureListener extends JSFunctionExec implements { final Object source = srce; StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(); + .getStructureSelectionManager(jvlite); // if (jvlite.debug) // { // ssm.reportMapping(); @@ -160,23 +160,28 @@ public class MouseOverStructureListener extends JSFunctionExec implements final String[] colcommands = JmolCommands.getColourBySequenceCommand( ssm, modelSet, sequence, sr, fr, ((AlignmentViewPanel) source).getAlignment()); + if (colcommands==null) + { + // + return; + } String mclass,mhandle; if (jvlite.isJsMessageSetChanged(mclass="colourstruct",mhandle=((jalview.appletgui.AlignmentPanel) source).av .getViewId(), colcommands)) { jvlite.setJsMessageSet(mclass, mhandle , colcommands); // and notify javascript handler - String st[] = new String[0]; + String st[] = new String[] + { + "colourstruct", + "" + + ((jalview.appletgui.AlignmentPanel) source).av + .getViewId(), ""+colcommands.length, ""+(colcommands[0]!=null ? colcommands[0].length() : 0)}; try { executeJavascriptFunction( true, - _listenerfn, - st = new String[] - { - "colourstruct", - "" - + ((jalview.appletgui.AlignmentPanel) source).av - .getViewId(), ""+colcommands.length, "" }); + _listenerfn,st +); } catch (Exception ex) { System.err.println("Couldn't execute callback with " @@ -243,9 +248,15 @@ public class MouseOverStructureListener extends JSFunctionExec implements return _listenerfn; } + public void finalise() + { + jvlite=null; + super.finalize(); + } @Override public void releaseReferences(Object svl) { + // TODO Auto-generated method stub } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 502c68e..d1bccd8 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -22,11 +22,13 @@ 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; @@ -47,13 +49,17 @@ public class StructureSelectionManager } Hashtable mappingData = new Hashtable(); - public static StructureSelectionManager getStructureSelectionManager() + public static StructureSelectionManager getStructureSelectionManager(StructureSelectionManagerProvider context) { - if (instance == null) + if (instances == null) { - instance = new StructureSelectionManager(); + instances = new java.util.IdentityHashMap(); + } + StructureSelectionManager instance=instances.get(context); + if (instance==null) + { + instances.put(context, instance=new StructureSelectionManager()); } - return instance; } @@ -374,7 +380,7 @@ public class StructureSelectionManager } } } - if (results.getSize() > 0) + if (results!=null) { for (int i = 0; i < listeners.size(); i++) { @@ -675,7 +681,7 @@ public class StructureSelectionManager modifySeqMappingList(true, codonFrames); } - Vector sel_listeners = new Vector(); + Vector sel_listeners = new Vector(); public void addSelectionListener(SelectionListener selecter) { @@ -712,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){}; + } + } + } -- 1.7.10.2