From: Ben Soares Date: Fri, 1 Sep 2023 23:03:21 +0000 (+0100) Subject: JAL-629 Save structure frames in project files when opened and saved in headless... X-Git-Tag: Release_2_11_4_0~197^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9ffbc78ef4639f680f304758c88d4e1d98c13859;p=jalview.git JAL-629 Save structure frames in project files when opened and saved in headless mode --- diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index b8d2cce..6ebbf89 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -87,6 +87,21 @@ public abstract class StructureViewerBase extends GStructureViewer BySequence, ByChain, ChargeCysteine, ByViewer } + private static List svbs = new ArrayList<>(); + + public static List getAllStructureViewerBases() + { + List goodSvbs = new ArrayList<>(); + for (StructureViewerBase s : svbs) + { + if (s != null && !goodSvbs.contains(s)) + { + goodSvbs.add(s); + } + } + return goodSvbs; + } + /** * list of sequenceSet ids associated with the view */ @@ -137,6 +152,7 @@ public abstract class StructureViewerBase extends GStructureViewer { super(); setFrameIcon(null); + svbs.add(this); } /** diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 400465d..9499acd 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -1140,51 +1140,52 @@ public class Jalview2XML * only view *should* be coped with sensibly. */ // This must have been loaded, is it still visible? - JInternalFrame[] frames = null; + List viewFrames = new ArrayList<>(); if (Desktop.desktop != null) { - frames = Desktop.desktop.getAllFrames(); + JInternalFrame[] jifs = Desktop.desktop.getAllFrames(); + if (jifs != null) + { + for (JInternalFrame jif : jifs) + { + if (jif instanceof StructureViewerBase) + { + viewFrames.add((StructureViewerBase) jif); + } + } + } } else if (Jalview.isHeadlessMode() && Jalview.getInstance().getCommands() != null) { - // TODO - } - else - { - frames = null; + viewFrames.addAll( + StructureViewerBase.getAllStructureViewerBases()); } + String matchedFile = null; - if (frames != null) + for (StructureViewerBase viewFrame : viewFrames) { - for (int f = frames.length - 1; f > -1; f--) + matchedFile = saveStructureViewer(ap, jds, pdb, entry, viewIds, + matchedFile, viewFrame); + /* + * Only store each structure viewer's state once in the project + * jar. First time through only (storeDS==false) + */ + String viewId = viewFrame.getViewId(); + String viewerType = viewFrame.getViewerType().toString(); + if (!storeDS && !viewIds.contains(viewId)) { - if (frames[f] instanceof StructureViewerBase) + viewIds.add(viewId); + File viewerState = viewFrame.saveSession(); + if (viewerState != null) { - StructureViewerBase viewFrame = (StructureViewerBase) frames[f]; - matchedFile = saveStructureViewer(ap, jds, pdb, entry, - viewIds, matchedFile, viewFrame); - /* - * Only store each structure viewer's state once in the project - * jar. First time through only (storeDS==false) - */ - String viewId = viewFrame.getViewId(); - String viewerType = viewFrame.getViewerType().toString(); - if (!storeDS && !viewIds.contains(viewId)) - { - viewIds.add(viewId); - File viewerState = viewFrame.saveSession(); - if (viewerState != null) - { - copyFileToJar(jout, viewerState.getPath(), - getViewerJarEntryName(viewId), viewerType); - } - else - { - Console.error("Failed to save viewer state for " - + viewerType); - } - } + copyFileToJar(jout, viewerState.getPath(), + getViewerJarEntryName(viewId), viewerType); + } + else + { + Console.error( + "Failed to save viewer state for " + viewerType); } } }