package jalview.bin;
import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
import jalview.io.AppletFormatAdapter;
import jalview.io.DataSourceType;
import jalview.io.FileFormatException;
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
private static final String PARAM_PDBFILE = "PDBFile";
+ private static final String PARAM_PROPS = "props";
+
+ private Map<String, String> params;
+
+ private List<String> pdbFileParams;
+
public static void main(String[] args)
{
try
}
}
- private String paramFile;
-
- private String paramFile2;
-
- private String paramTree;
-
- private String paramFeatures;
-
- private String paramAnnotations;
-
- private String paramShowAnnotation;
-
- private List<String> paramPdbFile;
-
/**
* Parses parameters and shows the frame and any loaded panels
*
void doMain(String[] args) throws FileFormatException
{
loadParameters(args);
- if (paramFile == null)
+ if (getParameter(PARAM_FILE) == null)
{
usage();
}
}
/**
+ * 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 <alignmentFileName>");
+ System.err.println("Usage: JalviewJS file <alignmentFile>");
System.err.println("See documentation for full parameter list");
}
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));
}
/**
*/
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;
}