From: gmungoc Date: Thu, 17 Oct 2019 13:02:21 +0000 (+0100) Subject: JAL-3436 move/rename/private fields refactoring only X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e7921fdc9d6ab87ef91bb7781dd7d9316e671e3f;p=jalview.git JAL-3436 move/rename/private fields refactoring only --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 0c25262..2ef31a2 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -194,9 +194,9 @@ public class AlignFrame extends GAlignFrame /** * Current filename for this alignment */ - String fileName = null; + private String fileName = null; - File fileObject; + private File fileObject; /** * Creates a new AlignFrame object with specific width and height. diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index ccfe460..9507a87 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -161,6 +161,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -266,6 +267,25 @@ public class Jalview2XML private Map rnaSessions = new HashMap<>(); /** + * contains last error message (if any) encountered by XML loader. + */ + String errorMessage = null; + + /** + * flag to control whether the Jalview2XML_V1 parser should be deferred to if + * exceptions are raised during project XML parsing + */ + public boolean attemptversion1parse = false; + + /* + * JalviewJS only -- to allow read file bytes to be saved in the + * created AlignFrame, allowing File | Reload of a project file to work + * + * BH 2019 JAL-3436 + */ + private File jarFile; + + /** * A helper method for safely using the value of an optional attribute that * may be null if not present in the XML. Answers the boolean value, or false * if null. @@ -2731,24 +2751,6 @@ public class Jalview2XML } /** - * contains last error message (if any) encountered by XML loader. - */ - String errorMessage = null; - - /** - * flag to control whether the Jalview2XML_V1 parser should be deferred to if - * exceptions are raised during project XML parsing - */ - public boolean attemptversion1parse = false; - - /** - * JalviewJS only -- to preserve bytes in AlignFrame - * - * BH 2019 JAL-3436 - */ - private File file; - - /** * Load a jalview project archive from a jar file * * @param file @@ -2800,55 +2802,50 @@ public class Jalview2XML } @SuppressWarnings("unused") - private jarInputStreamProvider createjarInputStreamProvider(final Object ofile) throws MalformedURLException { - - // BH 2018 allow for bytes already attached to File object - try { - String file = (ofile instanceof File ? ((File) ofile).getCanonicalPath() : ofile.toString()); + private jarInputStreamProvider createjarInputStreamProvider( + final Object ofile) throws MalformedURLException + { + try + { + String file = (ofile instanceof File + ? ((File) ofile).getCanonicalPath() + : ofile.toString()); byte[] bytes = Platform.isJS() ? Platform.getFileBytes((File) ofile) : null; if (bytes != null) { - this.file = (File) ofile; - } - URL url = null; - errorMessage = null; - uniqueSetSuffix = null; - seqRefIds = null; - viewportsAdded.clear(); - frefedSequence = null; - - if (file.startsWith("http://")) { - url = new URL(file); - } - final URL _url = url; - return new jarInputStreamProvider() { - - @Override - public JarInputStream getJarInputStream() throws IOException { - if (bytes != null) { -// System.out.println("Jalview2XML: opening byte jarInputStream for bytes.length=" + bytes.length); - return new JarInputStream(new ByteArrayInputStream(bytes)); - } - if (_url != null) { -// System.out.println("Jalview2XML: opening url jarInputStream for " + _url); - return new JarInputStream(_url.openStream()); - } else { -// System.out.println("Jalview2XML: opening file jarInputStream for " + file); - return new JarInputStream(new FileInputStream(file)); - } - } - - @Override - public String getFilename() { - return file; - } - }; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } + this.jarFile = (File) ofile; + } + errorMessage = null; + uniqueSetSuffix = null; + seqRefIds = null; + viewportsAdded.clear(); + frefedSequence = null; + + URL url = file.startsWith("http://") ? new URL(file) : null; + return new jarInputStreamProvider() + { + @Override + public JarInputStream getJarInputStream() throws IOException + { + InputStream is = bytes != null ? new ByteArrayInputStream(bytes) + : (url != null ? url.openStream() + : new FileInputStream(file)); + return new JarInputStream(is); + } + + @Override + public String getFilename() + { + return file; + } + }; + } catch (IOException e) + { + e.printStackTrace(); + return null; + } + } /** * Recover jalview session from a jalview project archive. Caller may @@ -5029,7 +5026,7 @@ public class Jalview2XML ; af.alignPanel.setHoldRepaint(true); af.setFileName(fileName, FileFormat.Jalview); - af.setFileObject(file); // BH 2019 JAL-3436 + af.setFileObject(jarFile); // BH 2019 JAL-3436 final AlignViewport viewport = af.getViewport(); for (int i = 0; i < JSEQ.size(); i++)