JAL-1588 refactoring to StructureViewerBase and related
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 7 Jan 2015 12:13:32 +0000 (12:13 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 7 Jan 2015 12:13:32 +0000 (12:13 +0000)
18 files changed:
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AppJmol.java
src/jalview/gui/AppJmolBinding.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/gui/Desktop.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/JalviewChimeraBindingModel.java
src/jalview/gui/Preferences.java
src/jalview/gui/StructureViewer.java
src/jalview/gui/StructureViewerBase.java [new file with mode: 0644]
src/jalview/io/FileLoader.java
src/jalview/io/VamsasAppDatastore.java
src/jalview/jbgui/GPreferences.java
src/jalview/jbgui/GStructureViewer.java
test/jalview/ext/rbvi/chimera/JalviewChimeraView.java
test/jalview/ws/jabaws/JpredJabaStructExportImport.java
test/jalview/ws/jabaws/RNAStructExportImport.java

index cb2a9ca..34dd3f7 100644 (file)
@@ -38,7 +38,6 @@ import jalview.util.Comparison;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
-import java.awt.event.ComponentEvent;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -1279,7 +1278,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     {
       List<String> reply = viewer.sendChimeraCommand("save " + filepath,
               true);
-      System.out.println(reply);
+      return true; // todo: check for error in reply?
+      // System.out.println(reply);
     }
     return false;
   }
index 3273121..11cb909 100644 (file)
@@ -1076,7 +1076,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 .lastIndexOf(java.io.File.separatorChar) + 1);
       }
 
-      success = new Jalview2XML().SaveAlignment(this, file, shortName);
+      success = new Jalview2XML().saveAlignment(this, file, shortName);
 
       statusBar.setText(MessageManager.formatMessage(
               "label.successfully_saved_to_file_in_format", new String[]
index 90d3b15..55288d0 100644 (file)
@@ -26,11 +26,9 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
-import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
-import jalview.jbgui.GStructureViewer;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.HelixColourScheme;
@@ -46,7 +44,6 @@ import jalview.util.Platform;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
-import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Graphics;
@@ -76,9 +73,7 @@ import javax.swing.event.InternalFrameEvent;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
-public class AppJmol extends GStructureViewer implements Runnable,
-        ViewSetProvider
-
+public class AppJmol extends StructureViewerBase
 {
   AppJmolBinding jmb;
 
@@ -88,8 +83,6 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
   RenderPanel renderPanel;
 
-  AlignmentPanel ap;
-
   Vector atomsPicked = new Vector();
 
   private boolean addingStructures = false;
@@ -339,7 +332,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
                 topJmol.addAlignmentPanel(ap);
                 // add it to the set used for colouring
                 topJmol.useAlignmentPanelForColourbyseq(ap);
-                topJmol.buildJmolActionMenu();
+                topJmol.buildActionMenu();
                 ap.getStructureSelectionManager()
                         .sequenceColoursChanged(ap);
                 break;
@@ -436,7 +429,8 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
   public AlignmentPanel[] getAllAlignmentPanels()
   {
-    AlignmentPanel[] t, list = new AlignmentPanel[0];
+    AlignmentPanel[] t;
+    AlignmentPanel[] list = new AlignmentPanel[0];
     for (String setid : _aps)
     {
       AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
@@ -460,9 +454,9 @@ public class AppJmol extends GStructureViewer implements Runnable,
    */
   public void addAlignmentPanel(AlignmentPanel nap)
   {
-    if (ap == null)
+    if (getAlignmentPanel() == null)
     {
-      ap = nap;
+      setAlignmentPanel(nap);
     }
     if (!_aps.contains(nap.av.getSequenceSetId()))
     {
@@ -481,14 +475,14 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       _alignwith.remove(nap);
       _colourwith.remove(nap);
-      if (ap == nap)
+      if (getAlignmentPanel() == nap)
       {
-        ap = null;
+        setAlignmentPanel(null);
         for (AlignmentPanel aps : getAllAlignmentPanels())
         {
           if (aps != nap)
           {
-            ap = aps;
+            setAlignmentPanel(aps);
             break;
           }
         }
@@ -496,9 +490,9 @@ public class AppJmol extends GStructureViewer implements Runnable,
     } catch (Exception ex)
     {
     }
-    if (ap != null)
+    if (getAlignmentPanel() != null)
     {
-      buildJmolActionMenu();
+      buildActionMenu();
     }
   }
 
@@ -523,7 +517,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
           boolean enableColourBySeq)
   {
     useAlignmentPanelForColourbyseq(nap);
-    jmb.setColourBySequence(enableColourBySeq);
+    getBinding().setColourBySequence(enableColourBySeq);
     seqColour.setSelected(enableColourBySeq);
     viewerColour.setSelected(!enableColourBySeq);
   }
@@ -615,7 +609,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       if (frame instanceof AppJmol)
       {
-        if (((GStructureViewer) frame).isLinkedWith(apanel))
+        if (((StructureViewerBase) frame).isLinkedWith(apanel))
         {
           result.addElement(frame);
         }
@@ -725,7 +719,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
   public void closeViewer()
   {
     jmb.closeViewer();
-    ap = null;
+    setAlignmentPanel(null);
     _aps.clear();
     _alignwith.clear();
     _colourwith.clear();
@@ -1049,10 +1043,10 @@ public class AppJmol extends GStructureViewer implements Runnable,
     {
       if (!jmb.isLoadingFromArchive())
       {
-        if (_colourwith.size() == 0 && ap != null)
+        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
         {
           // Make the currently displayed alignment panel the associated view
-          _colourwith.add(ap.alignFrame.alignPanel);
+          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
         }
       }
       // Set the colour using the current view for the associated alignframe
@@ -1268,27 +1262,6 @@ public class AppJmol extends GStructureViewer implements Runnable,
     }
   }
 
-  protected void buildJmolActionMenu()
-  {
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith.size() == 0 && ap != null)
-    {
-      _alignwith.add(ap);
-    }
-    ;
-    for (Component c : viewerActionMenu.getMenuComponents())
-    {
-      if (c != alignStructs)
-      {
-        viewerActionMenu.remove((JMenuItem) c);
-      }
-    }
-    final ItemListener handler;
-  }
-
   /*
    * (non-Javadoc)
    * 
@@ -1304,14 +1277,14 @@ public class AppJmol extends GStructureViewer implements Runnable,
 
   private void alignStructs_withAllAlignPanels()
   {
-    if (ap == null)
+    if (getAlignmentPanel() == null)
     {
       return;
     }
     ;
     if (_alignwith.size() == 0)
     {
-      _alignwith.add(ap);
+      _alignwith.add(getAlignmentPanel());
     }
     ;
     try
@@ -1363,7 +1336,7 @@ public class AppJmol extends GStructureViewer implements Runnable,
         return ap;
       }
     }
-    return ap;
+    return getAlignmentPanel();
   }
 
   @Override
index a64072e..c70380c 100644 (file)
@@ -53,7 +53,7 @@ public class AppJmolBinding extends JalviewJmolBinding
   public FeatureRenderer getFeatureRenderer(
           AlignmentViewPanel alignment)
   {
-    AlignmentPanel ap = (alignment == null) ? appJmolWindow.ap
+    AlignmentPanel ap = (alignment == null) ? appJmolWindow.getAlignmentPanel()
             : (AlignmentPanel) alignment;
     if (ap.av.showSequenceFeatures)
     {
index 567a14c..bc985df 100644 (file)
@@ -27,11 +27,9 @@ import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
-import jalview.gui.ViewSelectionMenu.ViewSetProvider;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
-import jalview.jbgui.GStructureViewer;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.HelixColourScheme;
@@ -46,7 +44,6 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.dbsources.Pdb;
 
-import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
@@ -78,8 +75,7 @@ import javax.swing.event.MenuListener;
  * @author jprocter
  *
  */
-public class ChimeraViewFrame extends GStructureViewer implements Runnable,
-        ViewSetProvider
+public class ChimeraViewFrame extends StructureViewerBase
 {
   private JalviewChimeraBinding jmb;
 
@@ -87,8 +83,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
 
   private boolean alignAddedStructures = false;
 
-  AlignmentPanel ap;
-
   /*
    * state flag for PDB retrieval thread
    */
@@ -252,7 +246,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
                 topView.addAlignmentPanel(ap);
                 // add it to the set used for colouring
                 topView.useAlignmentPanelForColourbyseq(ap);
-                topView.buildChimeraActionMenu();
+                topView.buildActionMenu();
                 ap.getStructureSelectionManager()
                         .sequenceColoursChanged(ap);
                 break;
@@ -368,9 +362,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
    */
   public void addAlignmentPanel(AlignmentPanel nap)
   {
-    if (ap == null)
+    if (getAlignmentPanel() == null)
     {
-      ap = nap;
+      setAlignmentPanel(nap);
     }
     if (!_aps.contains(nap.av.getSequenceSetId()))
     {
@@ -389,14 +383,14 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       _alignwith.remove(nap);
       _colourwith.remove(nap);
-      if (ap == nap)
+      if (getAlignmentPanel() == nap)
       {
-        ap = null;
+        setAlignmentPanel(null);
         for (AlignmentPanel aps : getAllAlignmentPanels())
         {
           if (aps != nap)
           {
-            ap = aps;
+            setAlignmentPanel(aps);
             break;
           }
         }
@@ -404,9 +398,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     } catch (Exception ex)
     {
     }
-    if (ap != null)
+    if (getAlignmentPanel() != null)
     {
-      buildChimeraActionMenu();
+      buildActionMenu();
     }
   }
 
@@ -431,7 +425,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
           boolean enableColourBySeq)
   {
     useAlignmentPanelForColourbyseq(nap);
-    jmb.setColourBySequence(enableColourBySeq);
+    getBinding().setColourBySequence(enableColourBySeq);
     seqColour.setSelected(enableColourBySeq);
     viewerColour.setSelected(!enableColourBySeq);
   }
@@ -518,7 +512,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       if (frame instanceof ChimeraViewFrame)
       {
-        if (((ChimeraViewFrame) frame).isLinkedWith(apanel))
+        if (((StructureViewerBase) frame).isLinkedWith(apanel))
         {
           result.add((ChimeraViewFrame) frame);
         }
@@ -623,7 +617,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
               JOptionPane.YES_NO_OPTION);
       jmb.closeViewer(confirm == JOptionPane.YES_OPTION);
     }
-    ap = null;
+    setAlignmentPanel(null);
     _aps.clear();
     _alignwith.clear();
     _colourwith.clear();
@@ -959,10 +953,10 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     {
       if (!jmb.isLoadingFromArchive())
       {
-        if (_colourwith.size() == 0 && ap != null)
+        if (_colourwith.size() == 0 && getAlignmentPanel() != null)
         {
           // Make the currently displayed alignment panel the associated view
-          _colourwith.add(ap.alignFrame.alignPanel);
+          _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
         }
       }
       // Set the colour using the current view for the associated alignframe
@@ -1093,26 +1087,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
     }
   }
 
-  protected void buildChimeraActionMenu()
-  {
-    if (_alignwith == null)
-    {
-      _alignwith = new Vector<AlignmentPanel>();
-    }
-    if (_alignwith.size() == 0 && ap != null)
-    {
-      _alignwith.add(ap);
-    }
-    ;
-    for (Component c : viewerActionMenu.getMenuComponents())
-    {
-      if (c != alignStructs)
-      {
-        viewerActionMenu.remove((JMenuItem) c);
-      }
-    }
-  }
-
   /*
    * (non-Javadoc)
    * 
@@ -1128,14 +1102,14 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
 
   private void alignStructs_withAllAlignPanels()
   {
-    if (ap == null)
+    if (getAlignmentPanel() == null)
     {
       return;
     }
     ;
     if (_alignwith.size() == 0)
     {
-      _alignwith.add(ap);
+      _alignwith.add(getAlignmentPanel());
     }
     ;
     try
@@ -1187,7 +1161,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable,
         return ap;
       }
     }
-    return ap;
+    return getAlignmentPanel();
   }
 
   @Override
index 9871c27..06af0c1 100644 (file)
@@ -1480,7 +1480,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
           // TODO prevent user from messing with the Desktop whilst we're saving
           try
           {
-            new Jalview2XML().SaveState(choice);
+            new Jalview2XML().saveState(choice);
           } catch (OutOfMemoryError oom)
           {
             new OOMWarning("Whilst saving current state to "
@@ -1544,7 +1544,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
                   choice.hashCode());
           try
           {
-            new Jalview2XML().LoadJalviewAlign(choice);
+            new Jalview2XML().loadJalviewAlign(choice);
           } catch (OutOfMemoryError oom)
           {
             new OOMWarning("Whilst loading project from " + choice, oom);
index 830b791..c960287 100644 (file)
@@ -27,7 +27,6 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
-import jalview.jbgui.GStructureViewer;
 import jalview.schemabinding.version2.AlcodMap;
 import jalview.schemabinding.version2.Alcodon;
 import jalview.schemabinding.version2.AlcodonFrame;
@@ -96,11 +95,13 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.StringTokenizer;
@@ -127,6 +128,61 @@ import org.exolab.castor.xml.Unmarshaller;
  */
 public class Jalview2XML
 {
+
+  private class ViewerData
+  {
+
+    private int x;
+
+    private int y;
+
+    private int width;
+
+    private int height;
+
+    private boolean alignWithPanel;
+
+    private boolean colourWithAlignPanel;
+
+    private boolean colourByViewer;
+
+    private String stateData = "";
+
+    // todo: java bean in place of Object []
+    private Map<File, Object[]> fileData = new HashMap<File, Object[]>();
+
+    public ViewerData(int x, int y, int width, int height,
+            boolean alignWithPanel, boolean colourWithAlignPanel,
+            boolean colourByViewer)
+    {
+      this.x = x;
+      this.y = y;
+      this.width = width;
+      this.height = height;
+      this.alignWithPanel = alignWithPanel;
+      this.colourWithAlignPanel = colourWithAlignPanel;
+      this.colourByViewer = colourByViewer;
+    }
+
+  }
+
+  /*
+   * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
+   * of sequence objects are created.
+   */
+  IdentityHashMap<SequenceI, String> seqsToIds = null;
+
+  /**
+   * jalview XML Sequence ID to jalview sequence object reference (both dataset
+   * and alignment sequences. Populated as XML reps of sequence objects are
+   * created.)
+   */
+  Map<String, SequenceI> seqRefIds = null;
+
+  Vector frefedSequence = null;
+
+  boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
+
   /**
    * create/return unique hash string for sq
    * 
@@ -141,7 +197,7 @@ public class Jalview2XML
     }
     if (seqsToIds.containsKey(sq))
     {
-      return (String) seqsToIds.get(sq);
+      return seqsToIds.get(sq);
     }
     else
     {
@@ -182,31 +238,14 @@ public class Jalview2XML
   {
     if (seqsToIds == null)
     {
-      seqsToIds = new IdentityHashMap();
+      seqsToIds = new IdentityHashMap<SequenceI, String>();
     }
     if (seqRefIds == null)
     {
-      seqRefIds = new Hashtable();
+      seqRefIds = new HashMap<String, SequenceI>();
     }
   }
 
-  /**
-   * SequenceI reference -> XML ID string in jalview XML. Populated as XML reps
-   * of sequence objects are created.
-   */
-  java.util.IdentityHashMap seqsToIds = null;
-
-  /**
-   * jalview XML Sequence ID to jalview sequence object reference (both dataset
-   * and alignment sequences. Populated as XML reps of sequence objects are
-   * created.)
-   */
-  java.util.Hashtable seqRefIds = null; // key->SequenceI resolution
-
-  Vector frefedSequence = null;
-
-  boolean raiseGUI = true; // whether errors are raised in dialog boxes or not
-
   public Jalview2XML()
   {
   }
@@ -231,7 +270,7 @@ public class Jalview2XML
           {
             if (ref[1] instanceof jalview.datamodel.Mapping)
             {
-              SequenceI seq = (SequenceI) seqRefIds.get(sref);
+              SequenceI seq = seqRefIds.get(sref);
               while (seq.getDatasetSequence() != null)
               {
                 seq = seq.getDatasetSequence();
@@ -242,7 +281,7 @@ public class Jalview2XML
             {
               if (ref[1] instanceof jalview.datamodel.AlignedCodonFrame)
               {
-                SequenceI seq = (SequenceI) seqRefIds.get(sref);
+                SequenceI seq = seqRefIds.get(sref);
                 while (seq.getDatasetSequence() != null)
                 {
                   seq = seq.getDatasetSequence();
@@ -304,16 +343,17 @@ public class Jalview2XML
   /**
    * List of pdbfiles added to Jar
    */
-  Vector pdbfiles = null;
+  List<String> pdbfiles = null;
 
   // SAVES SEVERAL ALIGNMENT WINDOWS TO SAME JARFILE
-  public void SaveState(File statefile)
+  public void saveState(File statefile)
   {
+    FileOutputStream fos = null;
     try
     {
-      FileOutputStream fos = new FileOutputStream(statefile);
+      fos = new FileOutputStream(statefile);
       JarOutputStream jout = new JarOutputStream(fos);
-      SaveState(jout);
+      saveState(jout);
 
     } catch (Exception e)
     {
@@ -329,6 +369,18 @@ public class Jalview2XML
         errorMessage += "(output file was '" + statefile + "')";
       }
       e.printStackTrace();
+    } finally
+    {
+      if (fos != null)
+      {
+        try
+        {
+          fos.close();
+        } catch (IOException e)
+        {
+          // ignore
+        }
+      }
     }
     reportErrors();
   }
@@ -338,7 +390,7 @@ public class Jalview2XML
    * 
    * @param jout
    */
-  public void SaveState(JarOutputStream jout)
+  public void saveState(JarOutputStream jout)
   {
     JInternalFrame[] frames = Desktop.desktop.getAllFrames();
 
@@ -354,8 +406,6 @@ public class Jalview2XML
 
       // NOTE UTF-8 MUST BE USED FOR WRITING UNICODE CHARS
       // //////////////////////////////////////////////////
-      // NOTE ALSO new PrintWriter must be used for each new JarEntry
-      PrintWriter out = null;
 
       Vector shortNames = new Vector();
 
@@ -414,7 +464,7 @@ public class Jalview2XML
               fileName = fileName + ".xml";
             }
 
-            SaveState(apanel, fileName, jout);
+            saveState(apanel, fileName, jout);
 
             String dssid = getDatasetIdRef(af.getViewport().getAlignment()
                     .getDataset());
@@ -451,7 +501,7 @@ public class Jalview2XML
   }
 
   // USE THIS METHOD TO SAVE A SINGLE ALIGNMENT WINDOW
-  public boolean SaveAlignment(AlignFrame af, String jarFile,
+  public boolean saveAlignment(AlignFrame af, String jarFile,
           String fileName)
   {
     try
@@ -469,7 +519,7 @@ public class Jalview2XML
         {
           jfileName = jfileName + ".xml";
         }
-        SaveState(apanel, jfileName, jout);
+        saveState(apanel, jfileName, jout);
         String dssid = getDatasetIdRef(af.getViewport().getAlignment()
                 .getDataset());
         if (!dsses.containsKey(dssid))
@@ -507,12 +557,12 @@ public class Jalview2XML
       {
         jfileName = jfileName + ".xml";
       }
-      SaveState(_af.alignPanel, jfileName, true, jout);
+      saveState(_af.alignPanel, jfileName, true, jout);
     }
   }
 
   /**
-   * create a JalviewModel from an algnment view and marshall it to a
+   * create a JalviewModel from an alignment view and marshall it to a
    * JarOutputStream
    * 
    * @param ap
@@ -524,10 +574,10 @@ public class Jalview2XML
    * @param out
    *          jar entry name
    */
-  public JalviewModel SaveState(AlignmentPanel ap, String fileName,
+  public JalviewModel saveState(AlignmentPanel ap, String fileName,
           JarOutputStream jout)
   {
-    return SaveState(ap, fileName, false, jout);
+    return saveState(ap, fileName, false, jout);
   }
 
   /**
@@ -546,11 +596,10 @@ public class Jalview2XML
    * @param out
    *          jar entry name
    */
-  public JalviewModel SaveState(AlignmentPanel ap, String fileName,
+  public JalviewModel saveState(AlignmentPanel ap, String fileName,
           boolean storeDS, JarOutputStream jout)
   {
     initSeqRefs();
-    List<String> chimeraViewIds = new ArrayList<String>();
     List<UserColourScheme> userColours = new ArrayList<UserColourScheme>();
 
     AlignViewport av = ap.av;
@@ -720,21 +769,23 @@ public class Jalview2XML
 
           pdb.setId(entry.getId());
           pdb.setType(entry.getType());
-          //
-          // store any JMol views associated with this sequence
-          // this section copes with duplicate entries in the project, so a
-          // dataset only view *should* be coped with sensibly
-          List<String> jmolViewIds = new ArrayList<String>();
+
+          /*
+           * Store any JMol or Chimera views associated with this sequence. This
+           * section copes with duplicate entries in the project, so a dataset
+           * only view *should* be coped with sensibly.
+           */
+          List<String> viewIds = new ArrayList<String>();
           // This must have been loaded, is it still visible?
           JInternalFrame[] frames = Desktop.desktop.getAllFrames();
           String matchedFile = null;
           for (int f = frames.length - 1; f > -1; f--)
           {
-            if (frames[f] instanceof GStructureViewer)
+            if (frames[f] instanceof StructureViewerBase)
             {
-              GStructureViewer viewFrame = (GStructureViewer) frames[f];
+              StructureViewerBase viewFrame = (StructureViewerBase) frames[f];
               matchedFile = saveStructureState(ap, jds, pdb, entry,
-                      jmolViewIds, matchedFile, viewFrame);
+                      viewIds, matchedFile, viewFrame);
             }
           }
 
@@ -748,12 +799,13 @@ public class Jalview2XML
             pdb.setFile(matchedFile); // entry.getFile());
             if (pdbfiles == null)
             {
-              pdbfiles = new Vector();
+              pdbfiles = new ArrayList<String>();
             }
 
             if (!pdbfiles.contains(entry.getId()))
             {
-              pdbfiles.addElement(entry.getId());
+              pdbfiles.add(entry.getId());
+              DataInputStream dis = null;
               try
               {
                 File file = new File(matchedFile);
@@ -761,7 +813,7 @@ public class Jalview2XML
                 {
                   byte[] data = new byte[(int) file.length()];
                   jout.putNextEntry(new JarEntry(entry.getId()));
-                  DataInputStream dis = new DataInputStream(
+                  dis = new DataInputStream(
                           new FileInputStream(file));
                   dis.readFully(data);
 
@@ -773,6 +825,18 @@ public class Jalview2XML
               } catch (Exception ex)
               {
                 ex.printStackTrace();
+              } finally
+              {
+                if (dis != null)
+                {
+                  try
+                  {
+                    dis.close();
+                  } catch (IOException e)
+                  {
+                    // ignore
+                  }
+                }
               }
 
             }
@@ -941,7 +1005,7 @@ public class Jalview2XML
 
             if (sg.cs instanceof jalview.schemes.UserColourScheme)
             {
-              groups[i].setColour(SetUserColourScheme(sg.cs, userColours,
+              groups[i].setColour(setUserColourScheme(sg.cs, userColours,
                       jms));
             }
             else
@@ -960,7 +1024,7 @@ public class Jalview2XML
           else if (sg.cs instanceof jalview.schemes.UserColourScheme)
           {
             groups[i]
-                    .setColour(SetUserColourScheme(sg.cs, userColours, jms));
+                    .setColour(setUserColourScheme(sg.cs, userColours, jms));
           }
           else
           {
@@ -1023,7 +1087,7 @@ public class Jalview2XML
 
       if (av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)
       {
-        view.setBgColour(SetUserColourScheme(av.getGlobalColourScheme(),
+        view.setBgColour(setUserColourScheme(av.getGlobalColourScheme(),
                 userColours, jms));
       }
       else if (av.getGlobalColourScheme() instanceof jalview.schemes.AnnotationColourGradient)
@@ -1051,7 +1115,7 @@ public class Jalview2XML
           view.setConsThreshold(cs.getConservationInc());
           if (cs instanceof jalview.schemes.UserColourScheme)
           {
-            view.setBgColour(SetUserColourScheme(cs, userColours, jms));
+            view.setBgColour(setUserColourScheme(cs, userColours, jms));
           }
         }
 
@@ -1253,19 +1317,21 @@ public class Jalview2XML
   }
 
   /**
+   * Save the state of a structure viewer
+   * 
    * @param ap
    * @param jds
    * @param pdb
+   *          the archive XML element under which to save the state
    * @param entry
-   * @param jmolViewIds
+   * @param viewIds
    * @param matchedFile
    * @param viewFrame
    * @return
    */
-  protected String saveStructureState(AlignmentPanel ap,
-          jalview.datamodel.SequenceI jds, Pdbids pdb,
-          jalview.datamodel.PDBEntry entry, List<String> jmolViewIds,
-          String matchedFile, GStructureViewer viewFrame)
+  protected String saveStructureState(AlignmentPanel ap, SequenceI jds,
+          Pdbids pdb, PDBEntry entry, List<String> viewIds,
+          String matchedFile, StructureViewerBase viewFrame)
   {
     final AAStructureBindingModel bindingModel = viewFrame
             .getBinding();
@@ -1311,16 +1377,18 @@ public class Jalview2XML
           state.setYpos(viewFrame.getY());
           state.setWidth(viewFrame.getWidth());
           state.setHeight(viewFrame.getHeight());
-          state.setViewId(viewFrame.getViewId());
+          final String viewId = viewFrame.getViewId();
+          state.setViewId(viewId);
           state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap));
           state.setColourwithAlignPanel(viewFrame
                   .isUsedforcolourby(ap));
           state.setColourByJmol(viewFrame.isColouredByViewer());
-          if (!jmolViewIds.contains(state.getViewId()))
+          /*
+           * Only store each structure viewer's state once in each XML document.
+           */
+          if (!viewIds.contains(viewId))
           {
-            // Make sure we only store a Jmol state once in each XML
-            // document.
-            jmolViewIds.add(state.getViewId());
+            viewIds.add(viewId);
             state.setContent(statestring.replaceAll("\n", ""));
           }
           else
@@ -1329,7 +1397,6 @@ public class Jalview2XML
           }
           pdb.addStructureState(state);
         }
-
       }
     }
     return matchedFile;
@@ -1345,7 +1412,7 @@ public class Jalview2XML
     ac.setAnnotation(acg.getAnnotation());
     if (acg.getBaseColour() instanceof jalview.schemes.UserColourScheme)
     {
-      ac.setColourScheme(SetUserColourScheme(acg.getBaseColour(),
+      ac.setColourScheme(setUserColourScheme(acg.getBaseColour(),
               userColours, jms));
     }
     else
@@ -1789,7 +1856,7 @@ public class Jalview2XML
     return mp;
   }
 
-  String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,
+  String setUserColourScheme(jalview.schemes.ColourSchemeI cs,
           List<UserColourScheme> userColours, JalviewModelSequence jms)
   {
     String id = null;
@@ -1835,7 +1902,7 @@ public class Jalview2XML
     return id;
   }
 
-  jalview.schemes.UserColourScheme GetUserColourScheme(
+  jalview.schemes.UserColourScheme getUserColourScheme(
           JalviewModelSequence jms, String id)
   {
     UserColours[] uc = jms.getUserColours();
@@ -1893,7 +1960,7 @@ public class Jalview2XML
    * @param file
    *          - HTTP URL or filename
    */
-  public AlignFrame LoadJalviewAlign(final String file)
+  public AlignFrame loadJalviewAlign(final String file)
   {
 
     jalview.gui.AlignFrame af = null;
@@ -1908,7 +1975,7 @@ public class Jalview2XML
       // so we can re-open the jar input stream for each entry.
 
       jarInputStreamProvider jprovider = createjarInputStreamProvider(file);
-      af = LoadJalviewAlign(jprovider);
+      af = loadJalviewAlign(jprovider);
 
     } catch (MalformedURLException e)
     {
@@ -1981,7 +2048,7 @@ public class Jalview2XML
    * @param jprovider
    * @return
    */
-  public AlignFrame LoadJalviewAlign(final jarInputStreamProvider jprovider)
+  public AlignFrame loadJalviewAlign(final jarInputStreamProvider jprovider)
   {
     errorMessage = null;
     if (uniqueSetSuffix == null)
@@ -1990,7 +2057,7 @@ public class Jalview2XML
     }
     if (seqRefIds == null)
     {
-      seqRefIds = new Hashtable();
+      seqRefIds = new HashMap<String, SequenceI>();
     }
     if (viewportsAdded == null)
     {
@@ -2028,7 +2095,7 @@ public class Jalview2XML
           object = (JalviewModel) unmar.unmarshal(in);
           if (true) // !skipViewport(object))
           {
-            _af = LoadFromObject(object, file, true, jprovider);
+            _af = loadFromObject(object, file, true, jprovider);
             if (object.getJalviewModelSequence().getViewportCount() > 0)
             {
               af = _af;
@@ -2254,7 +2321,7 @@ public class Jalview2XML
    *          data source provider
    * @return alignment frame created from view stored in DOM
    */
-  AlignFrame LoadFromObject(JalviewModel object, String file,
+  AlignFrame loadFromObject(JalviewModel object, String file,
           boolean loadTreesAndStructures, jarInputStreamProvider jprovider)
   {
     SequenceSet vamsasSet = object.getVamsasModel().getSequenceSet(0);
@@ -2275,11 +2342,11 @@ public class Jalview2XML
 
     boolean multipleView = false;
 
-    JSeq[] JSEQ = object.getJalviewModelSequence().getJSeq();
+    JSeq[] jseqs = object.getJalviewModelSequence().getJSeq();
     int vi = 0; // counter in vamsasSeq array
-    for (int i = 0; i < JSEQ.length; i++)
+    for (int i = 0; i < jseqs.length; i++)
     {
-      String seqId = JSEQ[i].getId();
+      String seqId = jseqs[i].getId();
 
       if (seqRefIds.get(seqId) != null)
       {
@@ -2291,15 +2358,15 @@ public class Jalview2XML
         jseq = new jalview.datamodel.Sequence(vamsasSeq[vi].getName(),
                 vamsasSeq[vi].getSequence());
         jseq.setDescription(vamsasSeq[vi].getDescription());
-        jseq.setStart(JSEQ[i].getStart());
-        jseq.setEnd(JSEQ[i].getEnd());
+        jseq.setStart(jseqs[i].getStart());
+        jseq.setEnd(jseqs[i].getEnd());
         jseq.setVamsasId(uniqueSetSuffix + seqId);
         seqRefIds.put(vamsasSeq[vi].getId(), jseq);
         tmpseqs.add(jseq);
         vi++;
       }
 
-      if (JSEQ[i].getHidden())
+      if (jseqs[i].getHidden())
       {
         if (hiddenSeqs == null)
         {
@@ -2354,9 +2421,9 @@ public class Jalview2XML
       // structures for the alignment
       for (int i = 0; i < vamsasSeq.length; i++)
       {
-        if (JSEQ[i].getFeaturesCount() > 0)
+        if (jseqs[i].getFeaturesCount() > 0)
         {
-          Features[] features = JSEQ[i].getFeatures();
+          Features[] features = jseqs[i].getFeatures();
           for (int f = 0; f < features.length; f++)
           {
             jalview.datamodel.SequenceFeature sf = new jalview.datamodel.SequenceFeature(
@@ -2386,9 +2453,9 @@ public class Jalview2XML
         {
           addDBRefs(al.getSequenceAt(i).getDatasetSequence(), vamsasSeq[i]);
         }
-        if (JSEQ[i].getPdbidsCount() > 0)
+        if (jseqs[i].getPdbidsCount() > 0)
         {
-          Pdbids[] ids = JSEQ[i].getPdbids();
+          Pdbids[] ids = jseqs[i].getPdbids();
           for (int p = 0; p < ids.length; p++)
           {
             jalview.datamodel.PDBEntry entry = new jalview.datamodel.PDBEntry();
@@ -2451,7 +2518,7 @@ public class Jalview2XML
           AlcodMap[] maps = alc[i].getAlcodMap();
           for (int m = 0; m < maps.length; m++)
           {
-            SequenceI dnaseq = (SequenceI) seqRefIds
+            SequenceI dnaseq = seqRefIds
                     .get(maps[m].getDnasq());
             // Load Mapping
             jalview.datamodel.Mapping mapping = null;
@@ -2705,7 +2772,7 @@ public class Jalview2XML
         {
           if (groups[i].getColour().startsWith("ucs"))
           {
-            cs = GetUserColourScheme(jms, groups[i].getColour());
+            cs = getUserColourScheme(jms, groups[i].getColour());
           }
           else if (groups[i].getColour().equals("AnnotationColourGradient")
                   && groups[i].getAnnotationColours() != null)
@@ -2729,7 +2796,7 @@ public class Jalview2XML
         for (int s = 0; s < groups[i].getSeqCount(); s++)
         {
           String seqId = groups[i].getSeq(s) + "";
-          jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI) seqRefIds
+          jalview.datamodel.SequenceI ts = seqRefIds
                   .get(seqId);
 
           if (ts != null)
@@ -2901,7 +2968,7 @@ public class Jalview2XML
 
     if (isnewview)
     {
-      af = loadViewport(file, JSEQ, hiddenSeqs, al, jms, view,
+      af = loadViewport(file, jseqs, hiddenSeqs, al, jms, view,
               uniqueSeqSetId, viewId, autoAlan);
       av = af.viewport;
       ap = af.alignPanel;
@@ -2986,358 +3053,413 @@ public class Jalview2XML
     // //LOAD STRUCTURES
     if (loadTreesAndStructures)
     {
-      // run through all PDB ids on the alignment, and collect mappings between
-      // jmol view ids and all sequences referring to it
-      Hashtable<String, Object[]> jmolViewIds = new Hashtable();
+      loadStructures(jprovider, jseqs, af, ap);
+    }
+    // and finally return.
+    return af;
+  }
 
-      for (int i = 0; i < JSEQ.length; i++)
+  /**
+   * Load and link any saved structure viewers.
+   * 
+   * @param jprovider
+   * @param jseqs
+   * @param af
+   * @param ap
+   */
+  protected void loadStructures(jarInputStreamProvider jprovider,
+          JSeq[] jseqs, AlignFrame af, AlignmentPanel ap)
+  {
+    // run through all PDB ids on the alignment, and collect mappings between
+    // jmol view ids and all sequences referring to it
+    Map<String, ViewerData> jmolViewIds = new HashMap<String, ViewerData>();
+
+    for (int i = 0; i < jseqs.length; i++)
+    {
+      if (jseqs[i].getPdbidsCount() > 0)
       {
-        if (JSEQ[i].getPdbidsCount() > 0)
+        Pdbids[] ids = jseqs[i].getPdbids();
+        for (int p = 0; p < ids.length; p++)
         {
-          Pdbids[] ids = JSEQ[i].getPdbids();
-          for (int p = 0; p < ids.length; p++)
+          final int structureStateCount = ids[p].getStructureStateCount();
+          for (int s = 0; s < structureStateCount; s++)
           {
-            for (int s = 0; s < ids[p].getStructureStateCount(); s++)
+            // check to see if we haven't already created this structure view
+            final StructureState structureState = ids[p].getStructureState(s);
+            String sviewid = (structureState.getViewId() == null) ? null
+                    : structureState.getViewId()
+                            + uniqueSetSuffix;
+            jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
+            // Originally : ids[p].getFile()
+            // : TODO: verify external PDB file recovery still works in normal
+            // jalview project load
+            jpdb.setFile(loadPDBFile(jprovider, ids[p].getId()));
+            jpdb.setId(ids[p].getId());
+
+            int x = structureState.getXpos();
+            int y = structureState.getYpos();
+            int width = structureState.getWidth();
+            int height = structureState.getHeight();
+
+            // Probably don't need to do this anymore...
+            // Desktop.desktop.getComponentAt(x, y);
+            // TODO: NOW: check that this recovers the PDB file correctly.
+            String pdbFile = loadPDBFile(jprovider, ids[p].getId());
+            jalview.datamodel.SequenceI seq = seqRefIds
+                    .get(jseqs[i].getId() + "");
+            if (sviewid == null)
             {
-              // check to see if we haven't already created this structure view
-              String sviewid = (ids[p].getStructureState(s).getViewId() == null) ? null
-                      : ids[p].getStructureState(s).getViewId()
-                              + uniqueSetSuffix;
-              jalview.datamodel.PDBEntry jpdb = new jalview.datamodel.PDBEntry();
-              // Originally : ids[p].getFile()
-              // : TODO: verify external PDB file recovery still works in normal
-              // jalview project load
-              jpdb.setFile(loadPDBFile(jprovider, ids[p].getId()));
-              jpdb.setId(ids[p].getId());
-
-              int x = ids[p].getStructureState(s).getXpos();
-              int y = ids[p].getStructureState(s).getYpos();
-              int width = ids[p].getStructureState(s).getWidth();
-              int height = ids[p].getStructureState(s).getHeight();
-
-              // Probably don't need to do this anymore...
-              // Desktop.desktop.getComponentAt(x, y);
-              // TODO: NOW: check that this recovers the PDB file correctly.
-              String pdbFile = loadPDBFile(jprovider, ids[p].getId());
-              jalview.datamodel.SequenceI seq = (jalview.datamodel.SequenceI) seqRefIds
-                      .get(JSEQ[i].getId() + "");
-              if (sviewid == null)
-              {
-                sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width
-                        + "," + height;
-              }
-              if (!jmolViewIds.containsKey(sviewid))
-              {
-                jmolViewIds.put(sviewid, new Object[]
-                { new int[]
-                { x, y, width, height }, "",
-                    new Hashtable<String, Object[]>(), new boolean[]
-                    { false, false, true } });
-                // Legacy pre-2.7 conversion JAL-823 :
-                // do not assume any view has to be linked for colour by
-                // sequence
-              }
+              sviewid = "_jalview_pre2_4_" + x + "," + y + "," + width
+                      + "," + height;
+            }
+            if (!jmolViewIds.containsKey(sviewid))
+            {
+              jmolViewIds.put(sviewid, new ViewerData(x, y, width, height,
+                      false, false, true));
+              // Legacy pre-2.7 conversion JAL-823 :
+              // do not assume any view has to be linked for colour by
+              // sequence
+            }
 
-              // assemble String[] { pdb files }, String[] { id for each
-              // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
-              // seqs_file 2}, boolean[] {
-              // linkAlignPanel,superposeWithAlignpanel}} from hash
-              Object[] jmoldat = jmolViewIds.get(sviewid);
-              ((boolean[]) jmoldat[3])[0] |= ids[p].getStructureState(s)
-                      .hasAlignwithAlignPanel() ? ids[p].getStructureState(
-                      s).getAlignwithAlignPanel() : false;
-              // never colour by linked panel if not specified
-              ((boolean[]) jmoldat[3])[1] |= ids[p].getStructureState(s)
-                      .hasColourwithAlignPanel() ? ids[p]
-                      .getStructureState(s).getColourwithAlignPanel()
-                      : false;
-              // default for pre-2.7 projects is that Jmol colouring is enabled
-              ((boolean[]) jmoldat[3])[2] &= ids[p].getStructureState(s)
-                      .hasColourByJmol() ? ids[p].getStructureState(s)
-                      .getColourByJmol() : true;
-
-              if (((String) jmoldat[1]).length() < ids[p]
-                      .getStructureState(s).getContent().length())
+            // assemble String[] { pdb files }, String[] { id for each
+            // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+            // seqs_file 2}, boolean[] {
+            // linkAlignPanel,superposeWithAlignpanel}} from hash
+            ViewerData jmoldat = jmolViewIds.get(sviewid);
+            jmoldat.alignWithPanel |= structureState
+                    .hasAlignwithAlignPanel() ? structureState.getAlignwithAlignPanel() : false;
+            // never colour by linked panel if not specified
+            jmoldat.colourWithAlignPanel |= structureState
+                    .hasColourwithAlignPanel() ? structureState.getColourwithAlignPanel()
+                    : false;
+            // default for pre-2.7 projects is that Jmol colouring is enabled
+            jmoldat.colourByViewer &= structureState
+                    .hasColourByJmol() ? structureState
+                    .getColourByJmol() : true;
+
+            if (jmoldat.stateData.length() < structureState.getContent()
+                    .length())
+            {
               {
-                {
-                  jmoldat[1] = ids[p].getStructureState(s).getContent();
-                }
+                jmoldat.stateData = structureState.getContent();
               }
-              if (ids[p].getFile() != null)
+            }
+            if (ids[p].getFile() != null)
+            {
+              File mapkey = new File(ids[p].getFile());
+              Object[] seqstrmaps = jmoldat.fileData.get(mapkey);
+              if (seqstrmaps == null)
               {
-                File mapkey = new File(ids[p].getFile());
-                Object[] seqstrmaps = (Object[]) ((Hashtable) jmoldat[2])
-                        .get(mapkey);
-                if (seqstrmaps == null)
-                {
-                  ((Hashtable) jmoldat[2]).put(mapkey,
-                          seqstrmaps = new Object[]
-                          { pdbFile, ids[p].getId(), new Vector(),
-                              new Vector() });
-                }
-                if (!((Vector) seqstrmaps[2]).contains(seq))
-                {
-                  ((Vector) seqstrmaps[2]).addElement(seq);
-                  // ((Vector)seqstrmaps[3]).addElement(n) :
-                  // in principle, chains
-                  // should be stored here : do we need to
-                  // TODO: store and recover seq/pdb_id :
-                  // chain mappings
-                }
+                jmoldat.fileData.put(mapkey,
+                        seqstrmaps = new Object[]
+                        { pdbFile, ids[p].getId(), new Vector(),
+                            new Vector() });
               }
-              else
+              if (!((Vector) seqstrmaps[2]).contains(seq))
               {
-                errorMessage = ("The Jmol views in this project were imported\nfrom an older version of Jalview.\nPlease review the sequence colour associations\nin the Colour by section of the Jmol View menu.\n\nIn the case of problems, see note at\nhttp://issues.jalview.org/browse/JAL-747");
-                warn(errorMessage);
+                ((Vector) seqstrmaps[2]).addElement(seq);
+                // ((Vector)seqstrmaps[3]).addElement(n) :
+                // in principle, chains
+                // should be stored here : do we need to
+                // TODO: store and recover seq/pdb_id :
+                // chain mappings
               }
             }
+            else
+            {
+              errorMessage = ("The Jmol views in this project were imported\nfrom an older version of Jalview.\nPlease review the sequence colour associations\nin the Colour by section of the Jmol View menu.\n\nIn the case of problems, see note at\nhttp://issues.jalview.org/browse/JAL-747");
+              warn(errorMessage);
+            }
           }
         }
       }
+    }
+    {
+
+      // Instantiate the associated Jmol views
+      for (Entry<String, ViewerData> entry : jmolViewIds.entrySet())
       {
+        String sviewid = entry.getKey();
+        ViewerData svattrib = entry.getValue();
+        String state = svattrib.stateData;
+        Map<File, Object[]> oldFiles = svattrib.fileData;
+        final boolean useinJmolsuperpos = svattrib.alignWithPanel;
+        final boolean usetoColourbyseq = svattrib.colourWithAlignPanel;
+        final boolean jmolColouring = svattrib.colourByViewer;
+        int x = svattrib.x;
+        int y = svattrib.y;
+        int width = svattrib.width;
+        int height = svattrib.height;
+        // collate the pdbfile -> sequence mappings from this view
+        Vector<String> pdbfilenames = new Vector<String>();
+        Vector<SequenceI[]> seqmaps = new Vector<SequenceI[]>();
+        Vector<String> pdbids = new Vector<String>();
 
-        // Instantiate the associated Jmol views
-        for (Entry<String, Object[]> entry : jmolViewIds.entrySet())
+        /*
+         * Search for any Jmol windows already open from other alignment views
+         * that exactly match the stored structure state
+         */
+        AppJmol comp = null;
+        JInternalFrame[] frames = getAllFrames();
+        for (JInternalFrame frame : frames)
         {
-          String sviewid = entry.getKey();
-          Object[] svattrib = entry.getValue();
-          int[] geom = (int[]) svattrib[0];
-          String state = (String) svattrib[1];
-          Hashtable<File, Object[]> oldFiles = (Hashtable<File, Object[]>) svattrib[2];
-          final boolean useinJmolsuperpos = ((boolean[]) svattrib[3])[0], usetoColourbyseq = ((boolean[]) svattrib[3])[1], jmolColouring = ((boolean[]) svattrib[3])[2];
-          int x = geom[0], y = geom[1], width = geom[2], height = geom[3];
-          // collate the pdbfile -> sequence mappings from this view
-          Vector<String> pdbfilenames = new Vector<String>();
-          Vector<SequenceI[]> seqmaps = new Vector<SequenceI[]>();
-          Vector<String> pdbids = new Vector<String>();
-
-          // Search to see if we've already created this Jmol view
-          AppJmol comp = null;
-          JInternalFrame[] frames = null;
-          do
+          if (frame instanceof AppJmol)
           {
-            try
+            /*
+             * Post jalview 2.4 schema includes structure view id
+             */
+            if (sviewid != null
+                    && ((StructureViewerBase) frame).getViewId().equals(
+                            sviewid))
             {
-              frames = Desktop.desktop.getAllFrames();
-            } catch (ArrayIndexOutOfBoundsException e)
-            {
-              // occasional No such child exceptions are thrown here...
-              frames = null;
-              try
-              {
-                Thread.sleep(10);
-              } catch (Exception f)
-              {
-              }
-              ;
+              comp = (AppJmol) frame;
             }
-          } while (frames == null);
-          // search for any Jmol windows already open from other
-          // alignment views that exactly match the stored structure state
-          for (int f = 0; comp == null && f < frames.length; f++)
-          {
-            if (frames[f] instanceof AppJmol)
+            /*
+             * Otherwise test for matching position and size of viewer frame
+             */
+            else if (frame.getX() == x && frame.getY() == y
+                    && frame.getHeight() == height
+                    && frame.getWidth() == width)
             {
-              if (sviewid != null
-                      && ((GStructureViewer) frames[f]).getViewId().equals(sviewid))
-              {
-                // post jalview 2.4 schema includes structure view id
-                comp = (AppJmol) frames[f];
-              }
-              else if (frames[f].getX() == x && frames[f].getY() == y
-                      && frames[f].getHeight() == height
-                      && frames[f].getWidth() == width)
-              {
-                comp = (AppJmol) frames[f];
-              }
+              comp = (AppJmol) frame;
             }
           }
+        }
 
-          if (comp == null)
+        if (comp == null)
+        {
+          /*
+           * Create a new Jmol window. First parse the Jmol state to translate
+           * filenames loaded into the view, and record the order in which files
+           * are shown in the Jmol view, so we can add the sequence mappings in
+           * same order.
+           */
+          StringBuffer newFileLoc = null;
+          int cp = 0, ncp, ecp;
+          while ((ncp = state.indexOf("load ", cp)) > -1)
           {
-            // create a new Jmol window.
-            // First parse the Jmol state to translate filenames loaded into the
-            // view, and record the order in which files are shown in the Jmol
-            // view, so we can add the sequence mappings in same order.
-            StringBuffer newFileLoc = null;
-            int cp = 0, ncp, ecp;
-            while ((ncp = state.indexOf("load ", cp)) > -1)
+            if (newFileLoc == null)
             {
-              if (newFileLoc == null)
-              {
-                newFileLoc = new StringBuffer();
-              }
-              do
-              {
-                // look for next filename in load statement
-                newFileLoc.append(state.substring(cp,
-                        ncp = (state.indexOf("\"", ncp + 1) + 1)));
-                String oldfilenam = state.substring(ncp,
-                        ecp = state.indexOf("\"", ncp));
-                // recover the new mapping data for this old filename
-                // have to normalize filename - since Jmol and jalview do
-                // filename
-                // translation differently.
-                Object[] filedat = oldFiles.get(new File(oldfilenam));
-                newFileLoc.append(Platform
-                        .escapeString((String) filedat[0]));
-                pdbfilenames.addElement((String) filedat[0]);
-                pdbids.addElement((String) filedat[1]);
-                seqmaps.addElement(((Vector<SequenceI>) filedat[2])
-                        .toArray(new SequenceI[0]));
-                newFileLoc.append("\"");
-                cp = ecp + 1; // advance beyond last \" and set cursor so we can
-                              // look for next file statement.
-              } while ((ncp = state.indexOf("/*file*/", cp)) > -1);
+              newFileLoc = new StringBuffer();
             }
-            if (cp > 0)
+            do
             {
-              // just append rest of state
-              newFileLoc.append(state.substring(cp));
-            }
-            else
+              // look for next filename in load statement
+              newFileLoc.append(state.substring(cp,
+                      ncp = (state.indexOf("\"", ncp + 1) + 1)));
+              String oldfilenam = state.substring(ncp,
+                      ecp = state.indexOf("\"", ncp));
+              // recover the new mapping data for this old filename
+              // have to normalize filename - since Jmol and jalview do
+              // filename
+              // translation differently.
+              Object[] filedat = oldFiles.get(new File(oldfilenam));
+              newFileLoc.append(Platform
+                      .escapeString((String) filedat[0]));
+              pdbfilenames.addElement((String) filedat[0]);
+              pdbids.addElement((String) filedat[1]);
+              seqmaps.addElement(((Vector<SequenceI>) filedat[2])
+                      .toArray(new SequenceI[0]));
+              newFileLoc.append("\"");
+              cp = ecp + 1; // advance beyond last \" and set cursor so we can
+                            // look for next file statement.
+            } while ((ncp = state.indexOf("/*file*/", cp)) > -1);
+          }
+          if (cp > 0)
+          {
+            // just append rest of state
+            newFileLoc.append(state.substring(cp));
+          }
+          else
+          {
+            System.err
+                    .print("Ignoring incomplete Jmol state for PDB ids: ");
+            newFileLoc = new StringBuffer(state);
+            newFileLoc.append("; load append ");
+            for (File id : oldFiles.keySet())
             {
-              System.err
-                      .print("Ignoring incomplete Jmol state for PDB ids: ");
-              newFileLoc = new StringBuffer(state);
-              newFileLoc.append("; load append ");
-              for (File id : oldFiles.keySet())
-              {
-                // add this and any other pdb files that should be present in
-                // the viewer
-                Object[] filedat = oldFiles.get(id);
-                String nfilename;
-                newFileLoc.append(((String) filedat[0]));
-                pdbfilenames.addElement((String) filedat[0]);
-                pdbids.addElement((String) filedat[1]);
-                seqmaps.addElement(((Vector<SequenceI>) filedat[2])
-                        .toArray(new SequenceI[0]));
-                newFileLoc.append(" \"");
-                newFileLoc.append((String) filedat[0]);
-                newFileLoc.append("\"");
+              // add this and any other pdb files that should be present in
+              // the viewer
+              Object[] filedat = oldFiles.get(id);
+              String nfilename;
+              newFileLoc.append(((String) filedat[0]));
+              pdbfilenames.addElement((String) filedat[0]);
+              pdbids.addElement((String) filedat[1]);
+              seqmaps.addElement(((Vector<SequenceI>) filedat[2])
+                      .toArray(new SequenceI[0]));
+              newFileLoc.append(" \"");
+              newFileLoc.append((String) filedat[0]);
+              newFileLoc.append("\"");
 
-              }
-              newFileLoc.append(";");
             }
+            newFileLoc.append(";");
+          }
 
-            if (newFileLoc != null)
+          if (newFileLoc != null)
+          {
+            int histbug = newFileLoc.indexOf("history = ");
+            histbug += 10;
+            int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";",
+                    histbug);
+            String val = (diff == -1) ? null : newFileLoc.substring(
+                    histbug, diff);
+            if (val != null && val.length() >= 4)
             {
-              int histbug = newFileLoc.indexOf("history = ");
-              histbug += 10;
-              int diff = histbug == -1 ? -1 : newFileLoc.indexOf(";",
-                      histbug);
-              String val = (diff == -1) ? null : newFileLoc.substring(
-                      histbug, diff);
-              if (val != null && val.length() >= 4)
+              if (val.contains("e"))
               {
-                if (val.contains("e"))
+                if (val.trim().equals("true"))
                 {
-                  if (val.trim().equals("true"))
-                  {
-                    val = "1";
-                  }
-                  else
-                  {
-                    val = "0";
-                  }
-                  newFileLoc.replace(histbug, diff, val);
+                  val = "1";
                 }
+                else
+                {
+                  val = "0";
+                }
+                newFileLoc.replace(histbug, diff, val);
               }
-              // TODO: assemble String[] { pdb files }, String[] { id for each
-              // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
-              // seqs_file 2}} from hash
-              final String[] pdbf = pdbfilenames
-                      .toArray(new String[pdbfilenames.size()]), id = pdbids
-                      .toArray(new String[pdbids.size()]);
-              final SequenceI[][] sq = seqmaps
-                      .toArray(new SequenceI[seqmaps.size()][]);
-              final String fileloc = newFileLoc.toString(), vid = sviewid;
-              final AlignFrame alf = af;
-              final java.awt.Rectangle rect = new java.awt.Rectangle(x, y,
-                      width, height);
-              try
+            }
+            // TODO: assemble String[] { pdb files }, String[] { id for each
+            // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+            // seqs_file 2}} from hash
+            final String[] pdbf = pdbfilenames
+                    .toArray(new String[pdbfilenames.size()]), id = pdbids
+                    .toArray(new String[pdbids.size()]);
+            final SequenceI[][] sq = seqmaps
+                    .toArray(new SequenceI[seqmaps.size()][]);
+            final String fileloc = newFileLoc.toString(), vid = sviewid;
+            final AlignFrame alf = af;
+            final java.awt.Rectangle rect = new java.awt.Rectangle(x, y,
+                    width, height);
+            try
+            {
+              javax.swing.SwingUtilities.invokeAndWait(new Runnable()
               {
-                javax.swing.SwingUtilities.invokeAndWait(new Runnable()
+                @Override
+                public void run()
                 {
-                  @Override
-                  public void run()
+                  JalviewStructureDisplayI sview = null;
+                  try
                   {
-                    JalviewStructureDisplayI sview = null;
-                    try
-                    {
-                      // JAL-1333 note - we probably can't migrate Jmol views to UCSF Chimera!
-                      sview = new StructureViewer(alf.alignPanel.getStructureSelectionManager()).createView(StructureViewer.Viewer.JMOL, pdbf, id, sq, alf.alignPanel,
-                              useinJmolsuperpos, usetoColourbyseq,
-                              jmolColouring, fileloc, rect, vid);
-                      addNewStructureViewer(sview);
-                    } catch (OutOfMemoryError ex)
+                    // JAL-1333 note - we probably can't migrate Jmol views to UCSF Chimera!
+                    sview = new StructureViewer(alf.alignPanel
+                            .getStructureSelectionManager()).createView(
+                            StructureViewer.ViewerType.JMOL, pdbf, id, sq,
+                            alf.alignPanel,
+                            useinJmolsuperpos, usetoColourbyseq,
+                            jmolColouring, fileloc, rect, vid);
+                    addNewStructureViewer(sview);
+                  } catch (OutOfMemoryError ex)
+                  {
+                    new OOMWarning("restoring structure view for PDB id "
+                            + id, (OutOfMemoryError) ex.getCause());
+                    if (sview != null && sview.isVisible())
                     {
-                      new OOMWarning("restoring structure view for PDB id "
-                              + id, (OutOfMemoryError) ex.getCause());
-                      if (sview != null && sview.isVisible())
-                      {
-                        sview.closeViewer();
-                        sview.setVisible(false);
-                        sview.dispose();
-                      }
+                      sview.closeViewer();
+                      sview.setVisible(false);
+                      sview.dispose();
                     }
                   }
-                });
-              } catch (InvocationTargetException ex)
-              {
-                warn("Unexpected error when opening Jmol view.", ex);
-
-              } catch (InterruptedException e)
-              {
-                // e.printStackTrace();
-              }
-            }
-
-          }
-          else
-          // if (comp != null)
-          {
-            // NOTE: if the jalview project is part of a shared session then
-            // view synchronization should/could be done here.
-
-            // add mapping for sequences in this view to an already open Jmol
-            // instance
-            for (File id : oldFiles.keySet())
-            {
-              // add this and any other pdb files that should be present in the
-              // viewer
-              Object[] filedat = oldFiles.get(id);
-              String pdbFile = (String) filedat[0];
-              SequenceI[] seq = ((Vector<SequenceI>) filedat[2])
-                      .toArray(new SequenceI[0]);
-              comp.jmb.getSsm().setMapping(seq, null, pdbFile,
-                      jalview.io.AppletFormatAdapter.FILE);
-              comp.jmb.addSequenceForStructFile(pdbFile, seq);
-            }
-            // and add the AlignmentPanel's reference to the Jmol view
-            comp.addAlignmentPanel(ap);
-            if (useinJmolsuperpos)
-            {
-              comp.useAlignmentPanelForSuperposition(ap);
-            }
-            else
-            {
-              comp.excludeAlignmentPanelForSuperposition(ap);
-            }
-            if (usetoColourbyseq)
+                }
+              });
+            } catch (InvocationTargetException ex)
             {
-              comp.useAlignmentPanelForColourbyseq(ap, !jmolColouring);
-            }
-            else
+              warn("Unexpected error when opening Jmol view.", ex);
+
+            } catch (InterruptedException e)
             {
-              comp.excludeAlignmentPanelForColourbyseq(ap);
+              // e.printStackTrace();
             }
           }
+
+        }
+        else
+        // if (comp != null)
+        {
+          linkStructureViewer(ap, comp, oldFiles, useinJmolsuperpos,
+                  usetoColourbyseq, jmolColouring);
         }
       }
     }
-    // and finally return.
-    return af;
+  }
+
+  /**
+   * Link an AlignmentPanel to an existing JMol viewer.
+   * 
+   * @param ap
+   * @param viewer
+   * @param oldFiles
+   * @param useinJmolsuperpos
+   * @param usetoColourbyseq
+   * @param jmolColouring
+   */
+  protected void linkStructureViewer(AlignmentPanel ap, AppJmol viewer,
+          Map<File, Object[]> oldFiles,
+          final boolean useinJmolsuperpos, final boolean usetoColourbyseq,
+          final boolean jmolColouring)
+  {
+    // NOTE: if the jalview project is part of a shared session then
+    // view synchronization should/could be done here.
+
+    // add mapping for sequences in this view to an already open Jmol
+    // instance
+    for (File id : oldFiles.keySet())
+    {
+      // add this and any other pdb files that should be present in the
+      // viewer
+      Object[] filedat = oldFiles.get(id);
+      String pdbFile = (String) filedat[0];
+      SequenceI[] seq = ((Vector<SequenceI>) filedat[2])
+              .toArray(new SequenceI[0]);
+      viewer.jmb.getSsm().setMapping(seq, null, pdbFile,
+              jalview.io.AppletFormatAdapter.FILE);
+      viewer.jmb.addSequenceForStructFile(pdbFile, seq);
+    }
+    // and add the AlignmentPanel's reference to the Jmol view
+    viewer.addAlignmentPanel(ap);
+    if (useinJmolsuperpos)
+    {
+      viewer.useAlignmentPanelForSuperposition(ap);
+    }
+    else
+    {
+      viewer.excludeAlignmentPanelForSuperposition(ap);
+    }
+    if (usetoColourbyseq)
+    {
+      viewer.useAlignmentPanelForColourbyseq(ap, !jmolColouring);
+    }
+    else
+    {
+      viewer.excludeAlignmentPanelForColourbyseq(ap);
+    }
+  }
+
+  /**
+   * Get all frames within the Desktop.
+   * 
+   * @return
+   */
+  protected JInternalFrame[] getAllFrames()
+  {
+    JInternalFrame[] frames = null;
+    // TODO is this necessary - is it safe - risk of hanging?
+    do
+    {
+      try
+      {
+        frames = Desktop.desktop.getAllFrames();
+      } catch (ArrayIndexOutOfBoundsException e)
+      {
+        // occasional No such child exceptions are thrown here...
+        try
+        {
+          Thread.sleep(10);
+        } catch (InterruptedException f)
+        {
+        }
+      }
+    } while (frames == null);
+    return frames;
   }
 
   /**
@@ -3529,7 +3651,7 @@ public class Jalview2XML
     {
       if (view.getBgColour().startsWith("ucs"))
       {
-        cs = GetUserColourScheme(jms, view.getBgColour());
+        cs = getUserColourScheme(jms, view.getBgColour());
       }
       else if (view.getBgColour().startsWith("Annotation"))
       {
@@ -3786,7 +3908,7 @@ public class Jalview2XML
           {
             cs = new AnnotationColourGradient(
                     annAlignment.getAlignmentAnnotation()[i],
-                    GetUserColourScheme(jms,
+                    getUserColourScheme(jms,
                             viewAnnColour.getColourScheme()),
                     viewAnnColour.getAboveThreshold());
           }
@@ -3997,7 +4119,7 @@ public class Jalview2XML
     return false;
   }
 
-  public void AddToSkipList(AlignFrame af)
+  public void addToSkipList(AlignFrame af)
   {
     if (skipList == null)
     {
@@ -4078,7 +4200,7 @@ public class Jalview2XML
       // need to create or add a new dataset sequence reference to this sequence
       if (sqid != null)
       {
-        dsq = (jalview.datamodel.SequenceI) seqRefIds.get(sqid);
+        dsq = seqRefIds.get(sqid);
       }
       // check again
       if (dsq == null)
@@ -4274,7 +4396,7 @@ public class Jalview2XML
           /**
            * recover from hash
            */
-          jmap.setTo((SequenceI) seqRefIds.get(dsfor));
+          jmap.setTo(seqRefIds.get(dsfor));
         }
         else
         {
@@ -4333,7 +4455,7 @@ public class Jalview2XML
           boolean keepSeqRefs)
   {
     initSeqRefs();
-    jalview.schemabinding.version2.JalviewModel jm = SaveState(ap, null,
+    jalview.schemabinding.version2.JalviewModel jm = saveState(ap, null,
             null);
 
     if (!keepSeqRefs)
@@ -4356,7 +4478,7 @@ public class Jalview2XML
 
     viewportsAdded = new Hashtable();
 
-    AlignFrame af = LoadFromObject(jm, null, false, null);
+    AlignFrame af = loadFromObject(jm, null, false, null);
     af.alignPanels.clear();
     af.closeMenuItem_actionPerformed(true);
 
@@ -4490,14 +4612,14 @@ public class Jalview2XML
         // register sequence object so the XML parser can recover it.
         if (seqRefIds == null)
         {
-          seqRefIds = new Hashtable();
+          seqRefIds = new HashMap<String, SequenceI>();
         }
         if (seqsToIds == null)
         {
-          seqsToIds = new IdentityHashMap();
+          seqsToIds = new IdentityHashMap<SequenceI, String>();
         }
-        seqRefIds.put(jv2vobj.get(jvobj).toString(), jvobj);
-        seqsToIds.put(jvobj, id);
+        seqRefIds.put(jv2vobj.get(jvobj).toString(), (SequenceI) jvobj);
+        seqsToIds.put((SequenceI) jvobj, id);
       }
       else if (jvobj instanceof jalview.datamodel.AlignmentAnnotation)
       {
index 9d1f18f..a2a3184 100644 (file)
@@ -24,7 +24,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding
   public FeatureRenderer getFeatureRenderer(
           AlignmentViewPanel alignment)
   {
-    AlignmentPanel ap = (alignment == null) ? cvf.ap
+    AlignmentPanel ap = (alignment == null) ? cvf.getAlignmentPanel()
             : (AlignmentPanel) alignment;
     if (ap.av.showSequenceFeatures)
     {
index bdc83e5..c024b1c 100755 (executable)
@@ -23,7 +23,7 @@ package jalview.gui;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
 import jalview.gui.Help.HelpId;
-import jalview.gui.StructureViewer.Viewer;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
 import jalview.jbgui.GPreferences;
@@ -289,7 +289,7 @@ public class Preferences extends GPreferences
     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
     addTempFactor.setEnabled(structSelected);
     structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
-            Viewer.JMOL.name()));
+            ViewerType.JMOL.name()));
     chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
     chimeraPath.addActionListener(new ActionListener()
     {
@@ -892,7 +892,7 @@ public class Preferences extends GPreferences
   @Override
   protected void structureViewer_actionPerformed(String selectedItem)
   {
-    if (!selectedItem.equals(Viewer.CHIMERA.name()))
+    if (!selectedItem.equals(ViewerType.CHIMERA.name()))
     {
       return;
     }
index 22f12ea..c204fec 100644 (file)
@@ -41,19 +41,19 @@ public class StructureViewer
 {
   StructureSelectionManager ssm;
 
-  public enum Viewer
+  public enum ViewerType
   {
     JMOL, CHIMERA
   };
 
-  public Viewer getViewerType()
+  public ViewerType getViewerType()
   {
     String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY,
-            Viewer.JMOL.name());
-    return Viewer.valueOf(viewType);
+            ViewerType.JMOL.name());
+    return ViewerType.valueOf(viewType);
   }
 
-  public void setViewerType(Viewer type)
+  public void setViewerType(ViewerType type)
   {
     Cache.setProperty(Preferences.STRUCTURE_DISPLAY, type.name());
   }
@@ -69,15 +69,15 @@ public class StructureViewer
     return viewStructures(getViewerType(), ap, pr, collateForPDB);
   }
 
-  public JalviewStructureDisplayI viewStructures(Viewer viewerType,
+  public JalviewStructureDisplayI viewStructures(ViewerType viewerType,
           AlignmentPanel ap, PDBEntry[] pr, SequenceI[][] collateForPDB)
   {
     JalviewStructureDisplayI sview = null;
-    if (viewerType.equals(Viewer.JMOL))
+    if (viewerType.equals(ViewerType.JMOL))
     {
       sview = new AppJmol(ap, pr, ap.av.collateForPDB(pr));
     }
-    else if (viewerType.equals(Viewer.CHIMERA))
+    else if (viewerType.equals(ViewerType.CHIMERA))
     {
       sview = new ChimeraViewFrame(ap, pr, ap.av.collateForPDB(pr));
     }
@@ -89,15 +89,15 @@ public class StructureViewer
     return sview;
   }
 
-  public JalviewStructureDisplayI viewStructures(Viewer viewerType,
+  public JalviewStructureDisplayI viewStructures(ViewerType viewerType,
           AlignmentPanel ap, PDBEntry pr, SequenceI[] collateForPDB)
   {
     JalviewStructureDisplayI sview = null;
-    if (viewerType.equals(Viewer.JMOL))
+    if (viewerType.equals(ViewerType.JMOL))
     {
       sview = new AppJmol(pr, collateForPDB, null, ap);
     }
-    else if (viewerType.equals(Viewer.CHIMERA))
+    else if (viewerType.equals(ViewerType.CHIMERA))
     {
       sview = new ChimeraViewFrame(pr, collateForPDB, null, ap);
     }
@@ -115,13 +115,14 @@ public class StructureViewer
     return viewStructures(getViewerType(), ap, pdb, sequenceIs);
   }
 
-  public JalviewStructureDisplayI createView(Viewer viewer, String[] pdbf,
+  public JalviewStructureDisplayI createView(ViewerType type,
+          String[] pdbf,
           String[] id, SequenceI[][] sq, AlignmentPanel alignPanel,
           boolean useinJmolsuperpos, boolean usetoColourbyseq,
           boolean jmolColouring, String fileloc, Rectangle rect, String vid)
   {
     JalviewStructureDisplayI sview = null;
-    switch (viewer)
+    switch (type)
     {
     case JMOL:
       sview = new AppJmol(pdbf, id, sq, alignPanel, useinJmolsuperpos,
@@ -129,10 +130,10 @@ public class StructureViewer
       break;
     case CHIMERA:
       Cache.log.error("Unsupported structure viewer type "
-              + viewer.toString());
+              + type.toString());
       break;
     default:
-      Cache.log.error("Unknown structure viewer type " + viewer.toString());
+      Cache.log.error("Unknown structure viewer type " + type.toString());
     }
     return sview;
   }
diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java
new file mode 100644 (file)
index 0000000..34398fe
--- /dev/null
@@ -0,0 +1,118 @@
+package jalview.gui;
+
+import java.awt.Component;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.JMenuItem;
+
+import jalview.gui.ViewSelectionMenu.ViewSetProvider;
+import jalview.jbgui.GStructureViewer;
+
+/**
+ * Base class with common functionality for JMol, Chimera or other structure
+ * viewers.
+ * 
+ * @author gmcarstairs
+ *
+ */
+public abstract class StructureViewerBase extends GStructureViewer
+        implements Runnable, ViewSetProvider
+{
+
+  /**
+   * list of sequenceSet ids associated with the view
+   */
+  protected List<String> _aps = new ArrayList<String>();
+  /**
+   * list of alignment panels to use for superposition
+   */
+  protected Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
+  /**
+   * list of alignment panels that are used for colouring structures by aligned
+   * sequences
+   */
+  protected Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
+  private String viewId = null;
+  private AlignmentPanel ap;
+
+  /**
+   * 
+   * @param ap2
+   * @return true if this Jmol instance is linked with the given alignPanel
+   */
+  public boolean isLinkedWith(AlignmentPanel ap2)
+  {
+    return _aps.contains(ap2.av.getSequenceSetId());
+  }
+
+  public boolean isUsedforaligment(AlignmentPanel ap2)
+  {
+  
+    return (_alignwith != null) && _alignwith.contains(ap2);
+  }
+
+  public boolean isUsedforcolourby(AlignmentPanel ap2)
+  {
+    return (_colourwith != null) && _colourwith.contains(ap2);
+  }
+
+  /**
+   * 
+   * @return TRUE if the view is NOT being coloured by the alignment colours.
+   */
+  public boolean isColouredByViewer()
+  {
+    return !getBinding().isColourBySequence();
+  }
+
+  public String getViewId()
+  {
+    if (viewId == null)
+    {
+      viewId = System.currentTimeMillis() + "." + this.hashCode();
+    }
+    return viewId;
+  }
+
+  protected void setViewId(String viewId)
+  {
+    this.viewId = viewId;
+  }
+
+  public String getStateInfo()
+  {
+    return "";
+  }
+
+  protected void buildActionMenu()
+  {
+    if (_alignwith == null)
+    {
+      _alignwith = new Vector<AlignmentPanel>();
+    }
+    if (_alignwith.size() == 0 && ap != null)
+    {
+      _alignwith.add(ap);
+    }
+    ;
+    for (Component c : viewerActionMenu.getMenuComponents())
+    {
+      if (c != alignStructs)
+      {
+        viewerActionMenu.remove((JMenuItem) c);
+      }
+    }
+  }
+
+  public AlignmentPanel getAlignmentPanel()
+  {
+    return ap;
+  }
+
+  protected void setAlignmentPanel(AlignmentPanel alp)
+  {
+    this.ap = alp;
+  }
+}
index 833f590..0285bf0 100755 (executable)
@@ -277,7 +277,7 @@ public class FileLoader implements Runnable
                   .println("IMPLEMENTATION ERROR: Cannot read consecutive Jalview XML projects from a stream.");
           // We read the data anyway - it might make sense.
         }
-        alignFrame = new Jalview2XML(raiseGUI).LoadJalviewAlign(file);
+        alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(file);
       }
       else
       {
index 6293a1b..90447db 100644 (file)
@@ -1304,7 +1304,7 @@ public class VamsasAppDatastore
             };
             if (dojvsync)
             {
-              fromxml.LoadJalviewAlign(jprovider);
+              fromxml.loadJalviewAlign(jprovider);
             }
           } catch (Exception e)
           {
@@ -1352,7 +1352,7 @@ public class VamsasAppDatastore
           };
           if (dojvsync)
           {
-            fromxml.LoadJalviewAlign(jarstream);
+            fromxml.loadJalviewAlign(jarstream);
           }
         } catch (Exception e)
         {
@@ -1498,7 +1498,7 @@ public class VamsasAppDatastore
         jxml.setSkipList(skipList);
         if (dojvsync)
         {
-          jxml.SaveState(new JarOutputStream(cappdata
+          jxml.saveState(new JarOutputStream(cappdata
                   .getClientOutputStream()));
         }
 
index 610f32e..3596619 100755 (executable)
@@ -21,7 +21,7 @@
 package jalview.jbgui;
 
 import jalview.gui.JvSwingUtils;
-import jalview.gui.StructureViewer.Viewer;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -780,8 +780,8 @@ public class GPreferences extends JPanel
 
     structViewer.setFont(verdana11);
     structViewer.setBounds(new Rectangle(160, ypos, 120, height));
-    structViewer.addItem(Viewer.JMOL.name());
-    structViewer.addItem(Viewer.CHIMERA.name());
+    structViewer.addItem(ViewerType.JMOL.name());
+    structViewer.addItem(ViewerType.CHIMERA.name());
     structViewer.addActionListener(new ActionListener()
     {
       @Override
index 4471bbb..24e7ee3 100644 (file)
 package jalview.jbgui;
 
 import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.gui.AlignmentPanel;
 import jalview.util.MessageManager;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.Vector;
 
 import javax.swing.ButtonGroup;
 import javax.swing.JInternalFrame;
@@ -80,24 +77,6 @@ public abstract class GStructureViewer extends JInternalFrame implements
   protected JMenuItem helpItem = new JMenuItem();
 
   /**
-   * list of sequenceSet ids associated with the view
-   */
-  protected ArrayList<String> _aps = new ArrayList<String>();
-
-  /**
-   * list of alignment panels to use for superposition
-   */
-  protected Vector<AlignmentPanel> _alignwith = new Vector<AlignmentPanel>();
-
-  /**
-   * list of alignment panels that are used for colouring structures by aligned
-   * sequences
-   */
-  protected Vector<AlignmentPanel> _colourwith = new Vector<AlignmentPanel>();
-
-  private String viewId = null;
-
-  /**
    * Constructor
    */
   public GStructureViewer()
@@ -464,52 +443,4 @@ public abstract class GStructureViewer extends JInternalFrame implements
   // this.bindingModel = bindingModel;
   // }
 
-  /**
-   * 
-   * @param ap2
-   * @return true if this Jmol instance is linked with the given alignPanel
-   */
-  public boolean isLinkedWith(AlignmentPanel ap2)
-  {
-    return _aps.contains(ap2.av.getSequenceSetId());
-  }
-
-  public boolean isUsedforaligment(AlignmentPanel ap2)
-  {
-  
-    return (_alignwith != null) && _alignwith.contains(ap2);
-  }
-
-  public boolean isUsedforcolourby(AlignmentPanel ap2)
-  {
-    return (_colourwith != null) && _colourwith.contains(ap2);
-  }
-
-  /**
-   * 
-   * @return TRUE if the view is NOT being coloured by the alignment colours.
-   */
-  public boolean isColouredByViewer()
-  {
-    return !getBinding().isColourBySequence();
-  }
-
-  public String getViewId()
-  {
-    if (viewId == null)
-    {
-      viewId = System.currentTimeMillis() + "." + this.hashCode();
-    }
-    return viewId;
-  }
-
-  protected void setViewId(String viewId)
-  {
-    this.viewId = viewId;
-  }
-
-  public String getStateInfo()
-  {
-    return null;
-  }
 }
index 1736af5..858806b 100644 (file)
@@ -1,19 +1,14 @@
 package jalview.ext.rbvi.chimera;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.StructureViewer;
-import jalview.gui.StructureViewer.Viewer;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.FormatAdapter;
 
-import java.awt.Desktop;
-import java.io.File;
-
-import org.junit.After;
 import org.junit.AfterClass;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -58,25 +53,30 @@ public class JalviewChimeraView
       if (dsq.getPDBId()!=null && dsq.getPDBId().size()>0) {
         for (int q=0;q<dsq.getPDBId().size();q++) 
         {
-          new StructureViewer(af.getViewport().getStructureSelectionManager()).viewStructures(Viewer.JMOL,
+          new StructureViewer(af.getViewport()
+                  .getStructureSelectionManager()).viewStructures(
+                  ViewerType.JMOL,
                   af.getCurrentView().getAlignPanel(),
                   new PDBEntry[] { (PDBEntry)dsq.getPDBId().elementAt(q) },
                   new SequenceI[][] { new SequenceI[] { sq } });
 
-          new StructureViewer(af.getViewport().getStructureSelectionManager()).viewStructures(Viewer.CHIMERA,
+          new StructureViewer(af.getViewport()
+                  .getStructureSelectionManager()).viewStructures(
+                  ViewerType.CHIMERA,
                   af.getCurrentView().getAlignPanel(),
                   new PDBEntry[] { (PDBEntry)dsq.getPDBId().elementAt(q) },
                   new SequenceI[][] { new SequenceI[] { sq } });
+          // todo: break here means only once through this loop?
           break;
         }
         break;
       }
    }
-    try {
-      Thread.sleep(200000);
-    } catch (InterruptedException q)
-    {
-      
-    }
+    // try {
+      // why?
+//      Thread.sleep(200000);
+//    } catch (InterruptedException q)
+//    {
+    // }
   }
 }
index f0b8f99..f47e542 100644 (file)
@@ -270,10 +270,10 @@ public class JpredJabaStructExportImport
     // write out parameters
     jalview.gui.AlignFrame nalf = null;
     assertTrue("Couldn't write out the Jar file",
-            new Jalview2XML(false).SaveAlignment(af,
+            new Jalview2XML(false).saveAlignment(af,
                     "testJPredWS_param.jar", "trial parameter writeout"));
     assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
-            false).LoadJalviewAlign("testJpredWS_param.jar")) != null);
+            false).loadJalviewAlign("testJpredWS_param.jar")) != null);
     if (nalf != null)
     {
       AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(
index 9a723ca..e74ebe7 100644 (file)
@@ -220,10 +220,10 @@ public class RNAStructExportImport
     // write out parameters
     jalview.gui.AlignFrame nalf = null;
     assertTrue("Couldn't write out the Jar file",
-            new Jalview2XML(false).SaveAlignment(af,
+            new Jalview2XML(false).saveAlignment(af,
                     "testRnalifold_param.jar", "trial parameter writeout"));
     assertTrue("Couldn't read back the Jar file", (nalf = new Jalview2XML(
-            false).LoadJalviewAlign("testRnalifold_param.jar")) != null);
+            false).loadJalviewAlign("testRnalifold_param.jar")) != null);
     if (nalf != null)
     {
       AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(