--- /dev/null
+package jalview.bin;
+
+import jalview.gui.AlignFrame;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
+import jalview.io.FileLoader;
+import jalview.io.IdentifyFile;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import javax.swing.JFrame;
+import javax.swing.JInternalFrame;
+
+/**
+ * Entry point for Jalview as Javascript. Expects parameter names as for the
+ * JalviewLite applet, formatted as for the Jalview application, for example
+ *
+ * <pre>
+ * JalviewJS file /examples/uniref50.fa features /examples/exampleFeatures.txt \
+ * PDBFile "/examples/pdb1.txt seq1"
+ * </pre>
+ *
+ * Note that (unlike the applet) parameter names are case sensitive
+ */
+// TODO or format as file=/examples/uniref50.fa (etc)?
+public class JalviewJS
+{
+ private static final String PARAM_FILE = "file";
+
+ private static final String PARAM_FILE2 = "file2";
+
+ private static final String PARAM_TREE = "tree";
+
+ private static final String PARAM_FEATURES = "features";
+
+ private static final String PARAM_ANNOTATIONS = "annotations";
+
+ private static final String PARAM_SHOW_ANNOTATION = "showAnnotation";
+
+ private static final String PARAM_PDBFILE = "PDBFile";
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ new JalviewJS().doMain(args);
+ } catch (FileFormatException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ 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
+ *
+ * @throws FileFormatException
+ */
+ void doMain(String[] args) throws FileFormatException
+ {
+ loadParameters(args);
+ if (paramFile == null)
+ {
+ usage();
+ }
+ else
+ {
+ showFrame();
+ }
+ }
+
+ /**
+ * Prints a chastising, yet helpful, error message on syserr
+ */
+ private void usage()
+ {
+ System.err.println("Usage: JalviewJS file <alignmentFileName>");
+ System.err.println("See documentation for full parameter list");
+ }
+
+ /**
+ * Parses any supplied parameters. Note that (unlike for the applet),
+ * parameter names are case sensitive.
+ *
+ * @param args
+ *
+ * @see http://www.jalview.org/examples/index.html#appletParameters
+ */
+ 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);
+ }
+
+ /**
+ * Reads parameter PDBFile, PDBFile1, PDFile2, ... and saves the value(s) (if
+ * any)
+ *
+ * @param parser
+ * @return
+ */
+ List<String> loadPdbParameters(ArgsParser parser)
+ {
+ List<String> values = new ArrayList<>();
+ String value = parser.getValue(PARAM_PDBFILE);
+ if (value != null)
+ {
+ values.add(value);
+ }
+ int i = 1;
+ while (true)
+ {
+ value = parser.getValue(PARAM_PDBFILE + String.valueOf(i));
+ if (value != null)
+ {
+ values.add(value);
+ }
+ else
+ {
+ break;
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Constructs and displays a JFrame containing an alignment panel (and any
+ * additional panels depending on parameters supplied)
+ *
+ * @throws FileFormatException
+ */
+ void showFrame() throws FileFormatException
+ {
+ JFrame frame = new JFrame(this.paramFile);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ JInternalFrame alignFrame = createAlignFrame();
+ frame.setContentPane(alignFrame.getContentPane());
+
+ frame.pack();
+ frame.setSize(AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+ frame.setVisible(true);
+ }
+
+ /**
+ * Constructs and returns the frame containing the alignment and its
+ * annotations
+ *
+ * @return
+ * @throws FileFormatException
+ */
+ JInternalFrame createAlignFrame() throws FileFormatException
+ {
+ Objects.requireNonNull(this.paramFile);
+
+ DataSourceType protocol = AppletFormatAdapter
+ .checkProtocol(this.paramFile);
+ FileFormatI format = new IdentifyFile().identify(this.paramFile,
+ protocol);
+ FileLoader fileLoader = new FileLoader(false);
+ AlignFrame af = fileLoader.LoadFileWaitTillLoaded(this.paramFile,
+ protocol, format);
+
+ return af;
+ }
+
+}