From: gmungoc Date: Wed, 20 Jun 2018 08:26:51 +0000 (+0100) Subject: JAL-3030 reads features file, properties file X-Git-Tag: Release_2_11_4_0~45^2~18^2~687 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8790f91b06eee23852c2c9ee99dd7daa0c0e9e90;p=jalview.git JAL-3030 reads features file, properties file --- diff --git a/src/jalview/bin/JalviewJS.java b/src/jalview/bin/JalviewJS.java index d161d1d..4e24354 100644 --- a/src/jalview/bin/JalviewJS.java +++ b/src/jalview/bin/JalviewJS.java @@ -1,6 +1,7 @@ package jalview.bin; import jalview.gui.AlignFrame; +import jalview.gui.Desktop; import jalview.io.AppletFormatAdapter; import jalview.io.DataSourceType; import jalview.io.FileFormatException; @@ -9,11 +10,12 @@ import jalview.io.FileLoader; import jalview.io.IdentifyFile; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import javax.swing.JFrame; -import javax.swing.JInternalFrame; /** * Entry point for Jalview as Javascript. Expects parameter names as for the @@ -43,6 +45,12 @@ public class JalviewJS private static final String PARAM_PDBFILE = "PDBFile"; + private static final String PARAM_PROPS = "props"; + + private Map params; + + private List pdbFileParams; + public static void main(String[] args) { try @@ -54,20 +62,6 @@ public class JalviewJS } } - private String paramFile; - - private String paramFile2; - - private String paramTree; - - private String paramFeatures; - - private String paramAnnotations; - - private String paramShowAnnotation; - - private List paramPdbFile; - /** * Parses parameters and shows the frame and any loaded panels * @@ -76,7 +70,7 @@ public class JalviewJS void doMain(String[] args) throws FileFormatException { loadParameters(args); - if (paramFile == null) + if (getParameter(PARAM_FILE) == null) { usage(); } @@ -87,11 +81,22 @@ public class JalviewJS } /** + * Answers the value of the given runtime parameter, or null if not provided + * + * @param paramName + * @return + */ + private String getParameter(String paramName) + { + return params.get(paramName); + } + + /** * Prints a chastising, yet helpful, error message on syserr */ private void usage() { - System.err.println("Usage: JalviewJS file "); + System.err.println("Usage: JalviewJS file "); System.err.println("See documentation for full parameter list"); } @@ -106,13 +111,29 @@ public class JalviewJS void loadParameters(String[] args) { ArgsParser parser = new ArgsParser(args); - paramFile = parser.getValue(PARAM_FILE); - paramFile2 = parser.getValue(PARAM_FILE2); - paramTree = parser.getValue(PARAM_TREE); - paramFeatures = parser.getValue(PARAM_FEATURES); - paramAnnotations = parser.getValue(PARAM_ANNOTATIONS); - paramShowAnnotation = parser.getValue(PARAM_SHOW_ANNOTATION); - paramPdbFile = loadPdbParameters(parser); + params = new HashMap<>(); + + // TODO javascript-friendly source of properties + Cache.loadProperties(parser.getValue(PARAM_PROPS)); + loadParameter(parser, PARAM_FILE); + loadParameter(parser, PARAM_FILE2); + loadParameter(parser, PARAM_TREE); + loadParameter(parser, PARAM_FEATURES); + loadParameter(parser, PARAM_ANNOTATIONS); + loadParameter(parser, PARAM_SHOW_ANNOTATION); + pdbFileParams = loadPdbParameters(parser); + } + + /** + * Reads one command line parameter value and saves it against the parameter + * name. Note the saved value is null if the parameter is not present. + * + * @param parser + * @param param + */ + protected void loadParameter(ArgsParser parser, String param) + { + params.put(param, parser.getValue(param)); } /** @@ -154,36 +175,63 @@ public class JalviewJS */ void showFrame() throws FileFormatException { - JFrame frame = new JFrame(this.paramFile); + JFrame frame = new JFrame(getParameter(PARAM_FILE)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JInternalFrame alignFrame = createAlignFrame(); + /* + * construct an AlignFrame and extract its contents and menu bar + * TODO there may be a less obscure way to do this + */ + AlignFrame alignFrame = createAlignFrame(); frame.setContentPane(alignFrame.getContentPane()); frame.setJMenuBar(alignFrame.getJMenuBar()); + // fudge so that dialogs can be opened with this frame as parent + Desktop.parent = frame.getContentPane(); + + loadFeatures(alignFrame, getParameter(PARAM_FEATURES)); + frame.pack(); frame.setSize(AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); frame.setVisible(true); } /** + * Load on a features file if one was specified as a parameter + * + * @param alignFrame + * + * @param featureFile + */ + protected void loadFeatures(AlignFrame alignFrame, String featureFile) + { + if (featureFile != null) + { + // todo extract helper for protocol resolution from JalviewLite + DataSourceType sourceType = featureFile.startsWith("http") + ? DataSourceType.URL + : DataSourceType.FILE; + alignFrame.parseFeaturesFile(featureFile, sourceType); + } + } + + /** * Constructs and returns the frame containing the alignment and its * annotations * * @return * @throws FileFormatException */ - JInternalFrame createAlignFrame() throws FileFormatException + AlignFrame createAlignFrame() throws FileFormatException { - Objects.requireNonNull(this.paramFile); + String file = getParameter(PARAM_FILE); + Objects.requireNonNull(file); - DataSourceType protocol = AppletFormatAdapter - .checkProtocol(this.paramFile); - FileFormatI format = new IdentifyFile().identify(this.paramFile, - protocol); + DataSourceType protocol = AppletFormatAdapter.checkProtocol(file); + FileFormatI format = new IdentifyFile().identify(file, protocol); FileLoader fileLoader = new FileLoader(false); - AlignFrame af = fileLoader.LoadFileWaitTillLoaded(this.paramFile, - protocol, format); + AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, + format); return af; }