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