6 def String safename = null;
7 JvLoadTest(String sname) {
8 if (!new File(sname).exists() || new File(sname).canWrite())
12 System.err.println("Warning : "+sname+" isn't being used to store temporary files.");
15 def public boolean doTest (file) {
16 fl = new FileLoader(false);
18 AlignFrame af = fl.LoadFileWaitTillLoaded(file
22 def public boolean doSequentialReadTest (file) {
23 return doSequentialReadTest(file, 0);
25 // Return true if there is more data to read.
26 def public boolean peekFp(FileParse fp) {
27 try { fp.mark(); } catch (Exception ex) { System.err.println("FAILED mark."+ex); return false; };
32 if (nl==null) { return false; }
33 System.out.println(nl +"\\n");
35 } catch (Exception e) { // end of file.
37 try { fp.reset(); } catch (Exception ex) { System.err.println("FAILED rewind."+ex); return false; };
41 Halt after loading the mx'th entry in the filestream
43 def public boolean doSequentialReadTest (file, int mx) {
44 // first properly open the file
45 // if (!doTest(file)) { return };
46 def FileParse fp = null;
48 fp = new FileParse(file, AppletFormatAdapter.FILE);
49 } catch (Exception e) { System.err.println("Couldn't open "+file+"\\n"); e.printStackTrace(); return false;};
50 Desktop.instance.closeAll_actionPerformed(null)
52 while (fp!=null && fp.isValid() && (mx==0 || mx!=fp.index)) {
53 if (!peekFp(fp)) return false;
54 fl = new FileLoader(false);
55 AlignFrame af = fl.LoadFileWaitTillLoaded(fp, null);
56 System.out.println("FileParse index: "+fp.index);
57 if (af!=null && (mx==0 || mx!=fp.index))
58 { def boolean res = doTest(af);
69 def public void waitTillSettled(AlignFrame af)
71 if (af==null) { return; }
73 while (af.getViewport().updatingConsensus || af.getViewport().updatingConservation) {
74 Thread.sleep(150); // wait until things settle down
77 def public boolean doTest(AlignFrame af) {
78 Object pr = af.getViewport().getAlignment().getProperty("AC");
79 if (pr!=null) { System.out.println("Accession = "+(String) pr); }
80 af.selectAllSequenceMenuItem_actionPerformed(null)
81 def boolean done = false;
82 // Just try to save - don\'t mess around with clipboard
85 af.copy_actionPerformed(null)
87 } catch (Exception e) {
88 Thread.sleep(100); // wait until clipboard might be available again
91 if (af==null) { return false; }
93 // Try and save as a jalview project and reload
95 // af.saveAlignment(safename, "Jalview")
96 new Jalview2XML().SaveState(new java.io.File(safename));
98 } catch (Exception ex) {
99 System.out.println("Couldn\'t save.");
100 ex.printStackTrace(System.err);
105 Desktop.instance.closeAll_actionPerformed(null);
106 } catch (Exception ex) {}
109 af = new FileLoader(false).LoadFileWaitTillLoaded(safename, FormatAdapter.FILE);
111 catch (Exception ex) {
112 System.out.println("Couldn't reload saved file.");
118 Desktop.instance.closeAll_actionPerformed(null);
121 // af.newView_actionPerformed(null)
122 // af.newView_actionPerformed(null)
126 def public boolean TestForAll(String dir) {
127 println "For directory or file : "+dir;
128 File fd = new File(dir);
129 if (!fd.isDirectory()) { return doSequentialReadTest(dir); }
130 fd.eachFile() { file -> TestForAll(file.getAbsolutePath()) };
133 def JvLoadTest newJvLoadTest(String tempFile) {
134 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
136 jalview.gui.Desktop.instance.desktop.showMemoryUsage(true);
137 return new JvLoadTest(tempFile)