JAL-845 preparation for awareness of AlignFrame in SplitFrame for save
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 3 Feb 2015 16:49:47 +0000 (16:49 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 3 Feb 2015 16:49:47 +0000 (16:49 +0000)
src/jalview/gui/Jalview2XML.java

index d3a7e2c..f08306a 100644 (file)
@@ -336,7 +336,7 @@ public class Jalview2XML
    */
   public void SaveState(JarOutputStream jout)
   {
-    JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+    AlignFrame[] frames = Desktop.getAlignFrames(); // Desktop.desktop.getAllFrames();
 
     if (frames == null)
     {
@@ -353,71 +353,66 @@ public class Jalview2XML
       // NOTE ALSO new PrintWriter must be used for each new JarEntry
       PrintWriter out = null;
 
-      Vector shortNames = new Vector();
+      List<String> shortNames = new ArrayList<String>();
 
       // REVERSE ORDER
       for (int i = frames.length - 1; i > -1; i--)
       {
-        if (frames[i] instanceof AlignFrame)
+        AlignFrame af = frames[i];
+        // skip ?
+        if (skipList != null
+                && skipList
+                        .containsKey(af.getViewport().getSequenceSetId()))
         {
-          AlignFrame af = (AlignFrame) frames[i];
-          // skip ?
-          if (skipList != null
-                  && skipList.containsKey(af.getViewport()
-                          .getSequenceSetId()))
-          {
-            continue;
-          }
+          continue;
+        }
 
-          String shortName = af.getTitle();
+        String shortName = af.getTitle();
 
-          if (shortName.indexOf(File.separatorChar) > -1)
+        if (shortName.indexOf(File.separatorChar) > -1)
+        {
+          shortName = shortName.substring(shortName
+                  .lastIndexOf(File.separatorChar) + 1);
+        }
+
+        int count = 1;
+
+        while (shortNames.contains(shortName))
+        {
+          if (shortName.endsWith("_" + (count - 1)))
           {
-            shortName = shortName.substring(shortName
-                    .lastIndexOf(File.separatorChar) + 1);
+            shortName = shortName.substring(0, shortName.lastIndexOf("_"));
           }
 
-          int count = 1;
+          shortName = shortName.concat("_" + count);
+          count++;
+        }
 
-          while (shortNames.contains(shortName))
-          {
-            if (shortName.endsWith("_" + (count - 1)))
-            {
-              shortName = shortName
-                      .substring(0, shortName.lastIndexOf("_"));
-            }
+        shortNames.add(shortName);
 
-            shortName = shortName.concat("_" + count);
-            count++;
-          }
+        if (!shortName.endsWith(".xml"))
+        {
+          shortName = shortName + ".xml";
+        }
 
-          shortNames.addElement(shortName);
+        int apSize = af.alignPanels.size();
 
-          if (!shortName.endsWith(".xml"))
+        for (int ap = 0; ap < apSize; ap++)
+        {
+          AlignmentPanel apanel = af.alignPanels.get(ap);
+          String fileName = apSize == 1 ? shortName : ap + shortName;
+          if (!fileName.endsWith(".xml"))
           {
-            shortName = shortName + ".xml";
+            fileName = fileName + ".xml";
           }
 
-          int ap, apSize = af.alignPanels.size();
+          SaveState(apanel, fileName, jout);
 
-          for (ap = 0; ap < apSize; ap++)
+          String dssid = getDatasetIdRef(af.getViewport().getAlignment()
+                  .getDataset());
+          if (!dsses.containsKey(dssid))
           {
-            AlignmentPanel apanel = af.alignPanels.get(ap);
-            String fileName = apSize == 1 ? shortName : ap + shortName;
-            if (!fileName.endsWith(".xml"))
-            {
-              fileName = fileName + ".xml";
-            }
-
-            SaveState(apanel, fileName, jout);
-
-            String dssid = getDatasetIdRef(af.getViewport().getAlignment()
-                    .getDataset());
-            if (!dsses.containsKey(dssid))
-            {
-              dsses.put(dssid, af);
-            }
-
+            dsses.put(dssid, af);
           }
         }
       }