2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 def class JvLoadTest {
26 def String safename = null;
27 JvLoadTest(String sname) {
28 if (!new File(sname).exists() || new File(sname).canWrite())
32 System.err.println("Warning : "+sname+" isn't being used to store temporary files.");
35 def public boolean doTest (file) {
36 fl = new FileLoader(false);
38 AlignFrame af = fl.LoadFileWaitTillLoaded(file
42 def public boolean doSequentialReadTest (file) {
43 return doSequentialReadTest(file, 0);
45 // Return true if there is more data to read.
46 def public boolean peekFp(FileParse fp) {
47 try { fp.mark(); } catch (Exception ex) { System.err.println("FAILED mark."+ex); return false; };
52 if (nl==null) { return false; }
53 System.out.println(nl +"\\n");
55 } catch (Exception e) { // end of file.
57 try { fp.reset(); } catch (Exception ex) { System.err.println("FAILED rewind."+ex); return false; };
61 Halt after loading the mx'th entry in the filestream
63 def public boolean doSequentialReadTest (file, int mx) {
64 // first properly open the file
65 // if (!doTest(file)) { return };
66 def FileParse fp = null;
68 fp = new FileParse(file, AppletFormatAdapter.FILE);
69 } catch (Exception e) { System.err.println("Couldn't open "+file+"\\n"); e.printStackTrace(); return false;};
70 Desktop.instance.closeAll_actionPerformed(null)
72 while (fp!=null && fp.isValid() && (mx==0 || mx!=fp.index)) {
73 if (!peekFp(fp)) return false;
74 fl = new FileLoader(false);
75 AlignFrame af = fl.LoadFileWaitTillLoaded(fp, null);
76 System.out.println("FileParse index: "+fp.index);
77 if (af!=null && (mx==0 || mx!=fp.index))
78 { def boolean res = doTest(af);
89 def public void waitTillSettled(AlignFrame af)
91 if (af==null) { return; }
93 while (af.getViewport().updatingConsensus || af.getViewport().updatingConservation) {
94 Thread.sleep(150); // wait until things settle down
97 def public boolean doTest(AlignFrame af) {
98 Object pr = af.getViewport().getAlignment().getProperty("AC");
99 if (pr!=null) { System.out.println("Accession = "+(String) pr); }
100 af.selectAllSequenceMenuItem_actionPerformed(null)
101 def boolean done = false;
102 // Just try to save - don\'t mess around with clipboard
105 af.copy_actionPerformed(null)
107 } catch (Exception e) {
108 Thread.sleep(100); // wait until clipboard might be available again
111 if (af==null) { return false; }
113 // Try and save as a jalview project and reload
115 // af.saveAlignment(safename, "Jalview")
116 new Jalview2XML().SaveState(new java.io.File(safename));
118 } catch (Exception ex) {
119 System.out.println("Couldn\'t save.");
120 ex.printStackTrace(System.err);
125 Desktop.instance.closeAll_actionPerformed(null);
126 } catch (Exception ex) {}
129 af = new FileLoader(false).LoadFileWaitTillLoaded(safename, FormatAdapter.FILE);
131 catch (Exception ex) {
132 System.out.println("Couldn't reload saved file.");
138 Desktop.instance.closeAll_actionPerformed(null);
141 // af.newView_actionPerformed(null)
142 // af.newView_actionPerformed(null)
146 def public boolean TestForAll(String dir) {
147 println "For directory or file : "+dir;
148 File fd = new File(dir);
149 if (!fd.isDirectory()) { return doSequentialReadTest(dir); }
150 fd.eachFile() { file -> TestForAll(file.getAbsolutePath()) };
153 def JvLoadTest newJvLoadTest(String tempFile) {
154 jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
156 jalview.gui.Desktop.instance.desktop.showMemoryUsage(true);
157 return new JvLoadTest(tempFile)