X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructures%2Fmodels%2FAAStructureBindingModel.java;h=6e926df87a475774acbbf2ff05bea75c8b3766fd;hb=d85a2741994c169e1b81db8f9166f5214ff1f561;hp=8d8957c244530a0ab25ef979f2429035eb12aeb7;hpb=42f4227ed213d422a87d3b22fc9e85d14ffaf53f;p=jalview.git diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 8d8957c..6e926df 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -20,12 +20,26 @@ */ package jalview.structures.models; +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.BitSet; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.SwingUtilities; + import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.api.StructureSelectionManagerProvider; import jalview.api.structures.JalviewStructureDisplayI; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; @@ -46,17 +60,6 @@ import jalview.structure.StructureSelectionManager; import jalview.util.Comparison; import jalview.util.MessageManager; -import java.awt.Color; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.BitSet; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.SwingUtilities; - /** * * A base class to hold common function for protein structure model binding. @@ -913,8 +916,7 @@ public abstract class AAStructureBindingModel { AtomSpecModel atomSpec = getAtomSpec(structures[i], matched); List commands = commandGenerator - .superposeStructures(refAtoms, - atomSpec); + .superposeStructures(refAtoms, atomSpec); List replies = executeCommands(commands, true, null); for (String reply : replies) { @@ -1372,7 +1374,6 @@ public abstract class AAStructureBindingModel for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { - // todo indirect this resolution / allow override final String modelId = getModelIdForFile(files[pdbfnum]); StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); @@ -1514,4 +1515,83 @@ public abstract class AAStructureBindingModel atomSpec.addRange(model, startPos, endPos, chain); } + + /** + * Returns the file extension (including '.' separator) to use for a saved + * viewer session file. Default is to return null (not supported), override as + * required. + * + * @return + */ + public String getSessionFileExtension() + { + return null; + } + + /** + * If supported, saves the state of the structure viewer to a temporary file + * and returns the file. Returns null and logs an error on any failure. + * + * @return + */ + public File saveSession() + { + String prefix = getViewerType().toString(); + String suffix = getSessionFileExtension(); + File f = null; + try + { + f = File.createTempFile(prefix, suffix); + saveSession(f); + } catch (IOException e) + { + Cache.log.error(String.format("Error saving %s session: %s", + prefix, e.toString())); + } + + return f; + } + + /** + * Saves the structure viewer session to the given file + * + * @param f + */ + protected void saveSession(File f) + { + StructureCommandI cmd = commandGenerator + .saveSession(f.getPath()); + if (cmd != null) + { + executeCommand(cmd, false); + } + } + + /** + * Returns true if the viewer is an external structure viewer for which the + * process is still alive, else false (for Jmol, or an external viewer which + * the user has independently closed) + * + * @return + */ + public boolean isViewerRunning() + { + return false; + } + + /** + * Closes Jalview's structure viewer panel and releases associated resources. + * If it is managing an external viewer program, and {@code forceClose} is + * true, also shuts down that program. + * + * @param forceClose + */ + public void closeViewer(boolean forceClose) + { + getSsm().removeStructureViewerListener(this, this.getStructureFiles()); + releaseUIResources(); + + // add external viewer shutdown in overrides + // todo - or can maybe pull up to here + } }