Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / examples / groovy / JvLoadTester.groovy
index d944ece..cc92e40 100644 (file)
-import jalview.gui.*;\r
-import jalview.io.*;\r
-\r
-def class JvLoadTest {\r
-    FileLoader fl = null;\r
-    def String safename = null;\r
-    JvLoadTest(String sname) { \r
-       if (!new File(sname).exists() || new File(sname).canWrite())\r
-           {\r
-               safename = sname;\r
-           } else {\r
-               System.err.println("Warning : "+sname+" isn't being used to store temporary files.");\r
-           }   \r
-    }\r
-    def public boolean doTest (file) {\r
-       fl = new FileLoader(false);\r
-       System.gc();\r
-       AlignFrame af = fl.LoadFileWaitTillLoaded(file\r
-                                                 ,FormatAdapter.FILE);\r
-       return doTest(af);\r
-    }\r
-    def public boolean doSequentialReadTest (file) {\r
-       return doSequentialReadTest(file, 0);\r
-    }\r
-    // Return true if there is more data to read.\r
-    def public boolean peekFp(FileParse fp) {\r
-       try { fp.mark(); }  catch (Exception ex) { System.err.println("FAILED mark."+ex); return false; };\r
-       try {\r
-         def String nl;\r
-         for (i in 1..3) { \r
-          nl = fp.nextLine();\r
-          if (nl==null) { return false; }\r
-          System.out.println(nl +"\\n");\r
-          }\r
-       } catch (Exception e) { // end of file.\r
-               return false; };\r
-       try { fp.reset(); } catch (Exception ex) { System.err.println("FAILED rewind."+ex); return false; };\r
-       return true;\r
-    }\r
-    /*\r
-      Halt after loading the mx'th entry in the filestream\r
-    */\r
-    def public boolean doSequentialReadTest (file, int mx) {\r
-       // first properly open the file\r
-       //      if (!doTest(file)) { return };\r
-       def FileParse fp = null;\r
-       try {\r
-               fp = new FileParse(file, AppletFormatAdapter.FILE);\r
-       } catch (Exception e) { System.err.println("Couldn't open "+file+"\\n"); e.printStackTrace(); return false;};\r
-       Desktop.instance.closeAll_actionPerformed(null)\r
-           System.gc();\r
-       while (fp!=null && fp.isValid() && (mx==0 || mx!=fp.index)) {\r
-           if (!peekFp(fp)) return false;\r
-           fl = new FileLoader(false);\r
-           AlignFrame af = fl.LoadFileWaitTillLoaded(fp, null);\r
-           System.out.println("FileParse index: "+fp.index);   \r
-           if (af!=null && (mx==0 || mx!=fp.index))\r
-               {       def boolean res = doTest(af);\r
-               if (!res)\r
-                   {\r
-                       // return false;\r
-                   }\r
-               } else {\r
-                   // return false;\r
-               }\r
-       }\r
-       return true;\r
-    }\r
-    def public void waitTillSettled(AlignFrame af)\r
-    {\r
-       if (af==null) { return; }\r
-       Thread.sleep(10);\r
-       while (af.getViewport().updatingConsensus || af.getViewport().updatingConservation) {\r
-           Thread.sleep(150); // wait until things settle down\r
-       }\r
-    }\r
-    def public boolean doTest(AlignFrame af) {\r
-       Object pr = af.getViewport().getAlignment().getProperty("AC");\r
-       if (pr!=null) { System.out.println("Accession = "+(String) pr); }\r
-       af.selectAllSequenceMenuItem_actionPerformed(null)\r
-           def boolean done = false;\r
-       // Just try to save - don\'t mess around with clipboard\r
-       /*while (!done) {\r
-         try {\r
-         af.copy_actionPerformed(null)\r
-         done = true;\r
-         } catch (Exception e) {\r
-         Thread.sleep(100); // wait until clipboard might be available again\r
-         }\r
-         }*/\r
-       if (af==null) { return false; }\r
-       waitTillSettled(af);\r
-       // Try and save as a jalview project and reload\r
-       try {\r
-           //      af.saveAlignment(safename, "Jalview")\r
-           new Jalview2XML().SaveState(new java.io.File(safename));\r
-           Thread.sleep(100);\r
-               } catch (Exception ex) { \r
-                   System.out.println("Couldn\'t save.");\r
-                   ex.printStackTrace(System.err);\r
-                   return false;\r
-               }\r
-       waitTillSettled(af);\r
-       try {\r
-           Desktop.instance.closeAll_actionPerformed(null);\r
-       } catch (Exception ex) {}\r
-       System.gc();\r
-       try {\r
-           af = new FileLoader(false).LoadFileWaitTillLoaded(safename, FormatAdapter.FILE);    \r
-       } \r
-       catch (Exception ex) {\r
-           System.out.println("Couldn't reload saved file.");\r
-            System.gc();\r
-           return false;\r
-       }\r
-       waitTillSettled(af);\r
-\r
-       Desktop.instance.closeAll_actionPerformed(null);\r
-\r
-       // af.paste(true)\r
-       // af.newView_actionPerformed(null)\r
-       // af.newView_actionPerformed(null)\r
-\r
-       return true;\r
-    }\r
-    def public boolean TestForAll(String dir) {\r
-       println "For directory or file : "+dir;\r
-       File fd = new File(dir);\r
-       if (!fd.isDirectory()) { return doSequentialReadTest(dir); }\r
-       fd.eachFile() { file -> TestForAll(file.getAbsolutePath()) };\r
-    }\r
-}\r
-def JvLoadTest newJvLoadTest(String tempFile) {\r
-       jalview.gui.Desktop.instance.closeAll_actionPerformed(null);\r
-       System.gc();\r
-       jalview.gui.Desktop.instance.desktop.showMemoryUsage(true);\r
-       return new JvLoadTest(tempFile)\r
-}
\ No newline at end of file
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+import jalview.gui.*;
+import jalview.io.*;
+
+class JvLoadTest {
+    FileLoader fl = null;
+    def String safename = null;
+    JvLoadTest(String sname) { 
+       if (!new File(sname).exists() || new File(sname).canWrite())
+           {
+               safename = sname;
+           } else {
+               System.err.println("Warning : "+sname+" isn't being used to store temporary files.");
+           }   
+    }
+    def public boolean doTest (file) {
+       fl = new FileLoader(false);
+       System.gc();
+       AlignFrame af = fl.LoadFileWaitTillLoaded(file
+                                                 ,FormatAdapter.FILE);
+       return doTest(af);
+    }
+    def public boolean doSequentialReadTest (file) {
+       return doSequentialReadTest(file, 0);
+    }
+    // Return true if there is more data to read.
+    def public boolean peekFp(FileParse fp) {
+       try { fp.mark(); }  catch (Exception ex) { System.err.println("FAILED mark."+ex); return false; };
+       try {
+         def String nl;
+         for (i in 1..3) { 
+          nl = fp.nextLine();
+          if (nl==null) { return false; }
+          System.out.println(nl +"\\n");
+          }
+       } catch (Exception e) { // end of file.
+               return false; };
+       try { fp.reset(); } catch (Exception ex) { System.err.println("FAILED rewind."+ex); return false; };
+       return true;
+    }
+    /*
+      Halt after loading the mx'th entry in the filestream
+    */
+    def public boolean doSequentialReadTest (file, int mx) {
+       // first properly open the file
+       //      if (!doTest(file)) { return };
+       def FileParse fp = null;
+       try {
+               fp = new FileParse(file, AppletFormatAdapter.FILE);
+       } catch (Exception e) { System.err.println("Couldn't open "+file+"\\n"); e.printStackTrace(); return false;};
+       Desktop.instance.closeAll_actionPerformed(null)
+           System.gc();
+       while (fp!=null && fp.isValid() && (mx==0 || mx!=fp.index)) {
+           if (!peekFp(fp)) return false;
+           fl = new FileLoader(false);
+           AlignFrame af = fl.LoadFileWaitTillLoaded(fp, null);
+           System.out.println("FileParse index: "+fp.index);   
+           if (af!=null && (mx==0 || mx!=fp.index))
+               {       def boolean res = doTest(af);
+               if (!res)
+                   {
+                       // return false;
+                   }
+               } else {
+                   // return false;
+               }
+       }
+       return true;
+    }
+    def public void waitTillSettled(AlignFrame af)
+    {
+       if (af==null) { return; }
+       Thread.sleep(10);
+       while (af.getViewport().updatingConsensus || af.getViewport().updatingConservation) {
+           Thread.sleep(150); // wait until things settle down
+       }
+    }
+    def public boolean doTest(AlignFrame af) {
+       Object pr = af.getViewport().getAlignment().getProperty("AC");
+       if (pr!=null) { System.out.println("Accession = "+(String) pr); }
+       af.selectAllSequenceMenuItem_actionPerformed(null)
+           def boolean done = false;
+       // Just try to save - don\'t mess around with clipboard
+       /*while (!done) {
+         try {
+         af.copy_actionPerformed(null)
+         done = true;
+         } catch (Exception e) {
+         Thread.sleep(100); // wait until clipboard might be available again
+         }
+         }*/
+       if (af==null) { return false; }
+       waitTillSettled(af);
+       // Try and save as a jalview project and reload
+       try {
+           //      af.saveAlignment(safename, "Jalview")
+           new Jalview2XML().SaveState(new java.io.File(safename));
+           Thread.sleep(100);
+               } catch (Exception ex) { 
+                   System.out.println("Couldn\'t save.");
+                   ex.printStackTrace(System.err);
+                   return false;
+               }
+       waitTillSettled(af);
+       try {
+           Desktop.instance.closeAll_actionPerformed(null);
+       } catch (Exception ex) {}
+       System.gc();
+       try {
+           af = new FileLoader(false).LoadFileWaitTillLoaded(safename, FormatAdapter.FILE);    
+       } 
+       catch (Exception ex) {
+           System.out.println("Couldn't reload saved file.");
+            System.gc();
+           return false;
+       }
+       waitTillSettled(af);
+
+       Desktop.instance.closeAll_actionPerformed(null);
+
+       // af.paste(true)
+       // af.newView_actionPerformed(null)
+       // af.newView_actionPerformed(null)
+
+       return true;
+    }
+    def public boolean TestForAll(String dir) {
+       println "For directory or file : "+dir;
+       File fd = new File(dir);
+       if (!fd.isDirectory()) { return doSequentialReadTest(dir); }
+       fd.eachFile() { file -> TestForAll(file.getAbsolutePath()) };
+    }
+}
+def JvLoadTest newJvLoadTest(String tempFile) {
+       jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
+       System.gc();
+       jalview.gui.Desktop.instance.desktop.showMemoryUsage(true);
+       return new JvLoadTest(tempFile)
+}