refactor to allow distinct StructureSelectionManager instances for
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 17 May 2011 12:49:57 +0000 (13:49 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 17 May 2011 12:49:57 +0000 (13:49 +0100)
each jalview context in a JVM (JAL-621, JAL-569, JAL-731, JAL-735,
JAL-832)

27 files changed:
src/MCview/AppletPDBCanvas.java [changed mode: 0755->0644]
src/MCview/PDBCanvas.java [changed mode: 0755->0644]
src/jalview/api/AlignmentViewPanel.java
src/jalview/appletgui/AlignFrame.java [changed mode: 0755->0644]
src/jalview/appletgui/AlignViewport.java [changed mode: 0755->0644]
src/jalview/appletgui/AlignmentPanel.java [changed mode: 0755->0644]
src/jalview/appletgui/AppletJmol.java
src/jalview/appletgui/AppletJmolBinding.java
src/jalview/appletgui/ExtJmol.java
src/jalview/appletgui/SeqPanel.java [changed mode: 0755->0644]
src/jalview/appletgui/TreePanel.java [changed mode: 0755->0644]
src/jalview/bin/JalviewLite.java [changed mode: 0755->0644]
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/gui/AlignViewport.java [changed mode: 0755->0644]
src/jalview/gui/AlignmentPanel.java [changed mode: 0755->0644]
src/jalview/gui/AppJmol.java
src/jalview/gui/AppJmolBinding.java
src/jalview/gui/Desktop.java [changed mode: 0755->0644]
src/jalview/gui/Jalview2XML.java [changed mode: 0755->0644]
src/jalview/gui/PopupMenu.java [changed mode: 0755->0644]
src/jalview/gui/SeqPanel.java [changed mode: 0755->0644]
src/jalview/gui/VamsasApplication.java
src/jalview/io/VamsasAppDatastore.java
src/jalview/io/vamsas/Sequencemapping.java
src/jalview/javascript/JSFunctionExec.java
src/jalview/javascript/MouseOverStructureListener.java
src/jalview/structure/StructureSelectionManager.java

old mode 100755 (executable)
new mode 100644 (file)
index 39d0926..756f2a5
@@ -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
     {
old mode 100755 (executable)
new mode 100644 (file)
index f9461e1..ed4cc1b
@@ -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
     {
index 7b3d3cd..fcda077 100644 (file)
@@ -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();
 }
old mode 100755 (executable)
new mode 100644 (file)
index 4634142..3654e0c
@@ -1174,8 +1174,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     if (PaintRefresher.components.size() == 0 && viewport.applet == null)\r
     {\r
       System.exit(0);\r
+    } else {\r
     }\r
-\r
+    viewport = null;\r
+    alignPanel = null;\r
     this.dispose();\r
   }\r
 \r
@@ -2280,7 +2282,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }\r
 \r
     jalview.structure.StructureSelectionManager\r
-            .getStructureSelectionManager().sequenceColoursChanged(\r
+            .getStructureSelectionManager(viewport.applet).sequenceColoursChanged(\r
                     alignPanel);\r
 \r
     alignPanel.paintAlignment(true);\r
@@ -3511,7 +3513,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     if (applet.useXtrnalSviewer)\r
     {\r
       // register the association(s) and quit, don't create any windows.\r
-      if (StructureSelectionManager.getStructureSelectionManager().setMapping(seqs, chains, pdb.getFile(), protocol)==null) {\r
+      if (StructureSelectionManager.getStructureSelectionManager(applet).setMapping(seqs, chains, pdb.getFile(), protocol)==null) {\r
         System.err.println("Failed to map "+pdb.getFile()+" ("+protocol+") to any sequences");\r
       }\r
       return;\r
@@ -3572,4 +3574,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {\r
     alignPanel.seqPanel.selection(sel, csel, null);\r
   }\r
+\r
+  public void scrollTo(int row, int column)\r
+  {\r
+    alignPanel.seqPanel.scrollTo(row, column);    \r
+  }\r
 }\r
old mode 100755 (executable)
new mode 100644 (file)
index 87566c6..264100e
@@ -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);
   }
old mode 100755 (executable)
new mode 100644 (file)
index e4b9b59..9bb3e4d
@@ -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);
+  }
 
 }
index 5b31db8..0ff2467 100644 (file)
@@ -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");
         }
index 152ebe9..ffe00b5 100644 (file)
@@ -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
-    
   }
 
 }
index 5714ce9..e1734d0 100644 (file)
@@ -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);
old mode 100755 (executable)
new mode 100644 (file)
index 29164bb..ade0afd
@@ -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);
+  }
+
 }
old mode 100755 (executable)
new mode 100644 (file)
index d424367..7595a50
@@ -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.
old mode 100755 (executable)
new mode 100644 (file)
index 8e22a1a..a4bebef
@@ -17,7 +17,9 @@
  */\r
 package jalview.bin;\r
 \r
+import jalview.api.StructureSelectionManagerProvider;\r
 import jalview.appletgui.AlignFrame;\r
+import jalview.appletgui.AlignViewport;\r
 import jalview.appletgui.EmbmenuFrame;\r
 import jalview.appletgui.FeatureSettings;\r
 import jalview.datamodel.Alignment;\r
@@ -60,9 +62,9 @@ import netscape.javascript.JSObject;
  * Jalview Applet. Runs in Java 1.18 runtime\r
  * \r
  * @author $author$\r
- * @version $Revision$\r
+ * @version $Revision: 1.92 $\r
  */\r
-public class JalviewLite extends Applet\r
+public class JalviewLite extends Applet implements StructureSelectionManagerProvider\r
 {\r
 \r
   // /////////////////////////////////////////\r
@@ -182,12 +184,12 @@ public class JalviewLite extends Applet
               && (alignedPosition.trim().length() == 0 || alignedPosition\r
                       .toLowerCase().indexOf("false") > -1))\r
       {\r
-        StructureSelectionManager.getStructureSelectionManager()\r
+        StructureSelectionManager.getStructureSelectionManager(this)\r
                 .mouseOverVamsasSequence(sq, sq.findIndex(apos), null);\r
       }\r
       else\r
       {\r
-        StructureSelectionManager.getStructureSelectionManager()\r
+        StructureSelectionManager.getStructureSelectionManager(this)\r
                 .mouseOverVamsasSequence(sq, apos, null);\r
       }\r
 \r
@@ -711,7 +713,7 @@ public class JalviewLite extends Applet
     setMouseoverListener(currentAlignFrame, listener);\r
   }\r
 \r
-  private Vector javascriptListeners = new Vector();\r
+  private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();\r
 \r
   public void setMouseoverListener(AlignFrame af, String listener)\r
   {\r
@@ -728,7 +730,7 @@ public class JalviewLite extends Applet
     jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener(\r
             this, af, listener);\r
     javascriptListeners.addElement(mol);\r
-    StructureSelectionManager.getStructureSelectionManager()\r
+    StructureSelectionManager.getStructureSelectionManager(this)\r
             .addStructureViewerListener(mol);\r
     if (debug)\r
     {\r
@@ -760,7 +762,7 @@ public class JalviewLite extends Applet
     jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender(\r
             this, af, listener);\r
     javascriptListeners.addElement(mol);\r
-    StructureSelectionManager.getStructureSelectionManager()\r
+    StructureSelectionManager.getStructureSelectionManager(this)\r
             .addSelectionListener(mol);\r
     if (debug)\r
     {\r
@@ -787,7 +789,7 @@ public class JalviewLite extends Applet
     jalview.javascript.MouseOverStructureListener mol = new jalview.javascript.MouseOverStructureListener(\r
             this, listener, separatorListToArray(modelSet));\r
     javascriptListeners.addElement(mol);\r
-    StructureSelectionManager.getStructureSelectionManager()\r
+    StructureSelectionManager.getStructureSelectionManager(this)\r
             .addStructureViewerListener(mol);\r
     if (debug)\r
     {\r
@@ -830,12 +832,12 @@ public class JalviewLite extends Applet
         msSize--;\r
         if (lstner instanceof SelectionListener)\r
         {\r
-          StructureSelectionManager.getStructureSelectionManager()\r
+          StructureSelectionManager.getStructureSelectionManager(this)\r
                   .removeSelectionListener((SelectionListener) lstner);\r
         }\r
         else\r
         {\r
-          StructureSelectionManager.getStructureSelectionManager()\r
+          StructureSelectionManager.getStructureSelectionManager(this)\r
                   .removeStructureViewerListener(lstner, null);\r
         }\r
         rprt = debug;\r
@@ -858,25 +860,52 @@ public class JalviewLite extends Applet
 \r
   public void stop()\r
   {\r
+    System.err.println("Applet "+getName()+" stop().");\r
+    tidyUp();\r
+  }\r
+  public void destroy()\r
+  {\r
+    System.err.println("Applet "+getName()+" destroy().");\r
+    tidyUp();\r
+  }\r
+  private void tidyUp()\r
+  {\r
+    removeAll();\r
+    if (currentAlignFrame!=null && currentAlignFrame.viewport!=null\r
+            && currentAlignFrame.viewport.applet!=null)\r
+    {\r
+      AlignViewport av = currentAlignFrame.viewport;\r
+      currentAlignFrame.closeMenuItem_actionPerformed();\r
+      av.applet=null;\r
+      currentAlignFrame=null;\r
+    }\r
     if (javascriptListeners != null)\r
     {\r
       while (javascriptListeners.size() > 0)\r
       {\r
-        Object mol = javascriptListeners.elementAt(0);\r
+        jalview.javascript.JSFunctionExec mol = javascriptListeners.elementAt(0);\r
         javascriptListeners.removeElement(mol);\r
         if (mol instanceof SelectionListener)\r
         {\r
-          StructureSelectionManager.getStructureSelectionManager()\r
+          StructureSelectionManager.getStructureSelectionManager(this)\r
                   .removeSelectionListener((SelectionListener) mol);\r
         }\r
         else\r
         {\r
-          StructureSelectionManager.getStructureSelectionManager()\r
+          StructureSelectionManager.getStructureSelectionManager(this)\r
                   .removeStructureViewerListener(mol, null);\r
         }\r
+        mol.jvlite=null;\r
       }\r
     }\r
-    jsFunctionExec.stopQueue();\r
+    if (jsFunctionExec!=null) {\r
+      jsFunctionExec.stopQueue();\r
+      jsFunctionExec.jvlite=null;\r
+    }\r
+    initialAlignFrame=null;\r
+    jsFunctionExec = null;\r
+    javascriptListeners=null;\r
+    StructureSelectionManager.release(this);\r
   }\r
   private jalview.javascript.JSFunctionExec jsFunctionExec;\r
   /**\r
@@ -892,7 +921,7 @@ public class JalviewLite extends Applet
   {\r
     try\r
     {\r
-      StructureSelectionManager.getStructureSelectionManager()\r
+      StructureSelectionManager.getStructureSelectionManager(this)\r
               .mouseOverStructure(new Integer(pdbResNum).intValue(), chain,\r
                       pdbfile);\r
       if (debug)\r
@@ -906,6 +935,24 @@ public class JalviewLite extends Applet
               + pdbResNum + "'");\r
     }\r
   }\r
+  /**\r
+   * adjust horizontal/vertical scroll to the make the given location the top left hand corner for given current view\r
+   * \r
+   * @param alf\r
+   * @param topRow\r
+   * @param leftHandColumn\r
+   */\r
+  public void scrollViewToIn(AlignFrame alf, String topRow, String leftHandColumn)\r
+  {\r
+    try {\r
+      alf.scrollTo(new Integer(topRow).intValue(), new Integer(leftHandColumn).intValue());\r
+      \r
+    } catch (Exception ex)\r
+    {\r
+      System.err.println("Couldn't parse integer arguments (topRow='"+topRow+"' and leftHandColumn='"+leftHandColumn+"'");\r
+      ex.printStackTrace();\r
+    }\r
+  }\r
 \r
   // //////////////////////////////////////////////\r
   // //////////////////////////////////////////////\r
@@ -1235,11 +1282,15 @@ public class JalviewLite extends Applet
       {\r
         if (frame instanceof AlignFrame)\r
         {\r
+          AlignViewport vp = ((AlignFrame) frame).viewport;\r
           ((AlignFrame) frame).closeMenuItem_actionPerformed();\r
-          if (((AlignFrame) frame).viewport.applet.currentAlignFrame == frame)\r
+          if (vp.applet.currentAlignFrame == frame)\r
           {\r
-            ((AlignFrame) frame).viewport.applet.currentAlignFrame = null;\r
+            vp.applet.currentAlignFrame = null;\r
           }\r
+          vp.applet=null;\r
+          vp=null;\r
+          \r
         }\r
         lastFrameX -= 40;\r
         lastFrameY -= 40;\r
@@ -1794,6 +1845,7 @@ public class JalviewLite extends Applet
         applet.remove(launcher);\r
         applet.repaint();\r
       }\r
+      callInitCallback();\r
     }\r
 \r
     /**\r
@@ -2173,7 +2225,7 @@ public class JalviewLite extends Applet
 \r
   public void start()\r
   {\r
-    callInitCallback();\r
+//    callInitCallback();\r
   }\r
   private Hashtable<String,long[]> jshashes=new Hashtable<String,long[]>();\r
   private Hashtable<String,Hashtable<String,String[]>> jsmessages=new Hashtable<String,Hashtable<String,String[]>>();\r
index 8e1ede4..6747349 100644 (file)
@@ -30,6 +30,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.api.FeatureRenderer;\r
 import jalview.api.SequenceRenderer;\r
 import jalview.api.SequenceStructureBinding;\r
+import jalview.api.StructureSelectionManagerProvider;\r
 import jalview.datamodel.*;\r
 import jalview.structure.*;\r
 import jalview.io.*;\r
@@ -45,7 +46,7 @@ import jalview.schemes.*;
 \r
 public abstract class JalviewJmolBinding implements StructureListener,\r
         JmolStatusListener, SequenceStructureBinding,\r
-        JmolSelectionListener, ComponentListener\r
+        JmolSelectionListener, ComponentListener, StructureSelectionManagerProvider\r
 \r
 {\r
   /**\r
@@ -128,13 +129,14 @@ public abstract class JalviewJmolBinding implements StructureListener,
    */\r
   public SequenceI[][] sequence;\r
 \r
-  StructureSelectionManager ssm;\r
+  public StructureSelectionManager ssm;\r
 \r
   public JmolViewer viewer;\r
 \r
-  public JalviewJmolBinding(PDBEntry[] pdbentry, SequenceI[][] sequenceIs,\r
+  public JalviewJmolBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs,\r
           String[][] chains, String protocol)\r
   {\r
+    this.ssm = ssm;\r
     this.sequence = sequenceIs;\r
     this.chains = chains;\r
     this.pdbentry = pdbentry;\r
@@ -152,8 +154,9 @@ public abstract class JalviewJmolBinding implements StructureListener,
      */\r
   }\r
 \r
-  public JalviewJmolBinding(JmolViewer viewer2)\r
+  public JalviewJmolBinding(StructureSelectionManager ssm, JmolViewer viewer2)\r
   {\r
+    this.ssm = ssm;\r
     viewer = viewer2;\r
     viewer.setJmolStatusListener(this);\r
     viewer.addSelectionListener(this);\r
@@ -227,8 +230,7 @@ public abstract class JalviewJmolBinding implements StructureListener,
   {\r
     viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);\r
     // remove listeners for all structures in viewer\r
-    StructureSelectionManager.getStructureSelectionManager()\r
-            .removeStructureViewerListener(this, this.getPdbFile());\r
+    ssm.removeStructureViewerListener(this, this.getPdbFile());\r
     // and shut down jmol\r
     viewer.evalStringQuiet("zap");\r
     viewer.setJmolStatusListener(null);\r
@@ -1044,7 +1046,6 @@ public abstract class JalviewJmolBinding implements StructureListener,
     chainFile = new Hashtable();\r
     boolean notifyLoaded = false;\r
     String[] modelfilenames = getPdbFile();\r
-    ssm = StructureSelectionManager.getStructureSelectionManager();\r
     // first check if we've lost any structures\r
     if (oldmodels != null && oldmodels.length > 0)\r
     {\r
@@ -1532,4 +1533,14 @@ public abstract class JalviewJmolBinding implements StructureListener,
       chains[pe] = null;\r
     }\r
   }\r
+  /**\r
+   * \r
+   * @param pdbfile\r
+   * @return text report of alignment between pdbfile and any associated alignment sequences\r
+   */\r
+  public String printMapping(String pdbfile)\r
+  {\r
+    return ssm.printMapping(pdbfile);\r
+  }\r
+\r
 }\r
old mode 100755 (executable)
new mode 100644 (file)
index 35743ab..af3ab95
@@ -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);
+  }
 }
old mode 100755 (executable)
new mode 100644 (file)
index 3ea6496..d2aa6d6
@@ -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();
+  }
 }
index 62f4d13..fdf00c0 100644 (file)
@@ -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");
       }
index 231d4e2..d15b9eb 100644 (file)
@@ -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;
   }
 
old mode 100755 (executable)
new mode 100644 (file)
index dbb6955..db2dbf2
@@ -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();
old mode 100755 (executable)
new mode 100644 (file)
index 5a13723..e639844
@@ -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<SequenceI>) 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);
             }
old mode 100755 (executable)
new mode 100644 (file)
index 07fdeea..d44ecdf
@@ -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",
old mode 100755 (executable)
new mode 100644 (file)
index a1913a8..50ece22
@@ -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);
     }
index cd9a529..1da1ae9 100644 (file)
@@ -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()
         {
index 06154c8..1d0b463 100644 (file)
@@ -1443,7 +1443,7 @@ public class VamsasAppDatastore
           if (mappings != null && mappings.length > 0)
           {
             jalview.structure.StructureSelectionManager
-                    .getStructureSelectionManager().addMappings(mappings);
+                    .getStructureSelectionManager(Desktop.instance).addMappings(mappings);
           }
         }
       }
index 9263690..ee0c2b6 100644 (file)
@@ -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
index 8eb0bd9..6f7fc43 100644 (file)
@@ -9,7 +9,7 @@ import jalview.bin.JalviewLite;
 \r
 public class JSFunctionExec implements Runnable\r
 {\r
-  JalviewLite jvlite;\r
+  public JalviewLite jvlite;\r
 \r
   public JSFunctionExec(JalviewLite applet)\r
   {\r
@@ -18,7 +18,15 @@ public class JSFunctionExec implements Runnable
     jsExecQueue = jvlite.getJsExecQueue();\r
     jvlite.setExecutor(this);\r
   }\r
-\r
+  public void finalize() {\r
+    jvlite=null;\r
+    executor=null;\r
+    if (jsExecQueue!=null)\r
+    {\r
+      jsExecQueue.clear();\r
+    }\r
+    jsExecQueue=null;\r
+  }\r
   private Vector jsExecQueue;\r
 \r
   private Thread executor = null;\r
@@ -27,18 +35,27 @@ public class JSFunctionExec implements Runnable
   {\r
     if (jsExecQueue != null)\r
     {\r
+      Vector<JSFunctionExec> q=null;\r
       synchronized (jsExecQueue)\r
       {\r
-        Vector q = jsExecQueue;\r
-        q.removeAllElements();\r
+        q = jsExecQueue;\r
         jsExecQueue = null;\r
+      }\r
+      if (q!=null ) {\r
+        for (JSFunctionExec jx : q)\r
+        {\r
+          jx.jvlite=null;\r
+          \r
+        }\r
+        q.removeAllElements();\r
         synchronized (q)\r
         {\r
           q.notifyAll();\r
         }\r
       }\r
-      executor = null;\r
     }\r
+    jvlite=null;\r
+    executor = null;\r
   }\r
 \r
   public void run()\r
index 2f28820..c1d3a40 100644 (file)
@@ -113,7 +113,7 @@ public class MouseOverStructureListener extends JSFunctionExec implements
   {\r
     final Object source = srce;\r
     StructureSelectionManager ssm = StructureSelectionManager\r
-            .getStructureSelectionManager();\r
+            .getStructureSelectionManager(jvlite);\r
     // if (jvlite.debug)\r
     // {\r
     // ssm.reportMapping();\r
@@ -160,23 +160,28 @@ public class MouseOverStructureListener extends JSFunctionExec implements
       final String[] colcommands = JmolCommands.getColourBySequenceCommand(\r
               ssm, modelSet, sequence, sr, fr,\r
               ((AlignmentViewPanel) source).getAlignment());\r
+      if (colcommands==null)\r
+      {\r
+        // \r
+        return;\r
+      }\r
       String mclass,mhandle;\r
       if (jvlite.isJsMessageSetChanged(mclass="colourstruct",mhandle=((jalview.appletgui.AlignmentPanel) source).av\r
               .getViewId(), colcommands)) {\r
       jvlite.setJsMessageSet(mclass, mhandle , colcommands);\r
       // and notify javascript handler\r
-      String st[] = new String[0];\r
+      String st[] = new String[]\r
+                                                  {\r
+              "colourstruct",\r
+              ""\r
+                      + ((jalview.appletgui.AlignmentPanel) source).av\r
+                              .getViewId(), ""+colcommands.length, ""+(colcommands[0]!=null ? colcommands[0].length() : 0)};\r
       try\r
       {\r
         executeJavascriptFunction(\r
                 true,\r
-                _listenerfn,\r
-                st = new String[]\r
-                {\r
-                    "colourstruct",\r
-                    ""\r
-                            + ((jalview.appletgui.AlignmentPanel) source).av\r
-                                    .getViewId(), ""+colcommands.length, "" });\r
+                _listenerfn,st\r
+);\r
       } catch (Exception ex)\r
       {\r
         System.err.println("Couldn't execute callback with "\r
@@ -243,9 +248,15 @@ public class MouseOverStructureListener extends JSFunctionExec implements
     return _listenerfn;\r
   }\r
 \r
+  public void finalise()\r
+  {\r
+    jvlite=null;\r
+    super.finalize();\r
+  }\r
   @Override\r
   public void releaseReferences(Object svl)\r
   {\r
+    \r
     // TODO Auto-generated method stub\r
 \r
   }\r
index 502c68e..d1bccd8 100644 (file)
@@ -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<StructureSelectionManagerProvider,StructureSelectionManager> instances;
 
   StructureMapping[] mappings;
 
@@ -47,13 +49,17 @@ public class StructureSelectionManager
   }\r
   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<StructureSelectionManagerProvider,StructureSelectionManager>();
+    }
+    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<SelectionListener> sel_listeners = new Vector<SelectionListener>();
 
   public void addSelectionListener(SelectionListener selecter)
   {
@@ -712,4 +718,67 @@ public class StructureSelectionManager
       }
     }
   }
+  
+  Vector<AlignmentViewPanelListener> view_listeners=new Vector<AlignmentViewPanelListener>();
+  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<AlignmentViewPanelListener> 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){};
+    }
+  }
+
 }