import javax.swing.*;\r
\r
import java.util.Vector;\r
+import jalview.datamodel.Alignment;\r
+import jalview.io.FormatAdapter;\r
+import jalview.datamodel.SequenceI;\r
\r
\r
/**\r
public static void main(String[] args)\r
{\r
ArgsParser aparser = new ArgsParser(args);\r
+ boolean headless = false;\r
+\r
+ if( aparser.contains("help") || aparser.contains("h") )\r
+ {\r
+ System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"\r
+ +"-nodisplay\tRun Jalview without User Interface.\n"\r
+ +"-props FILE\tUse the given Jalview properties file instead of users default.\n"\r
+ +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n"\r
+ +"TEXT<tab>SEQUENCE_ID<tab>SEQUENCE_INDEX<tab>START_RESIDUE<tab>END_RESIDUE<tab>COLOUR\n"\r
+ +"SequenceID is used in preference to SequenceIndex if both are provided.\n"\r
+ +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n"\r
+ +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n"\r
+ +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"\r
+ +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"\r
+ +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"\r
+ +"-msf FILE\tCreate alignment file FILE in MSF format.\n"\r
+ +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"\r
+ +"-pir FILE\tCreate alignment file FILE in PIR format.\n"\r
+ +"-blc FILE\tCreate alignment file FILE in BLC format.\n"\r
+ +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"\r
+ +"-png FILE\tCreate PNG image FILE from alignment.\n"\r
+ +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"\r
+ +"-eps FILE\tCreate EPS file FILE from alignment.");\r
+ System.exit(0);\r
+ }\r
+\r
+\r
+ if (aparser.contains("nodisplay"))\r
+ System.setProperty("java.awt.headless", "true");\r
+\r
+ if( System.getProperty("java.awt.headless") != null\r
+ && System.getProperty("java.awt.headless").equals("true"))\r
+ {\r
+ headless = true;\r
+ }\r
\r
- try\r
- {\r
- UIManager.setLookAndFeel(\r
- // "javax.swing.plaf.metal.MetalLookAndFeel"\r
- // "javax.swing.plaf.multi.MultiLookAndFeel"\r
- UIManager.getSystemLookAndFeelClassName());\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
\r
Cache.loadProperties(aparser.getValue("props"));\r
jalview.gui.Preferences.initPreferences();\r
}\r
\r
\r
- String file = null, protocol = null, format = null, groups=null;\r
- Desktop desktop = new Desktop();\r
-\r
-\r
- if(args==null || args.length==0)\r
+ Desktop desktop = null;\r
+ if( !headless )\r
{\r
+ try\r
+ {\r
+ UIManager.setLookAndFeel(\r
+ // "javax.swing.plaf.metal.MetalLookAndFeel"\r
+ // "javax.swing.plaf.multi.MultiLookAndFeel"\r
+ UIManager.getSystemLookAndFeelClassName());\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
+\r
+ desktop = new Desktop();\r
desktop.setVisible(true);\r
}\r
- else\r
- {\r
- if( aparser.contains("help") || aparser.contains("h") )\r
- {\r
- System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"\r
- +"-nodisplay\tRun Jalview without User Interface.\n"\r
- +"-props FILE\tUse the given Jalview properties file instead of users default.\n"\r
- +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n"\r
- +"TEXT<tab>SEQUENCE_ID<tab>SEQUENCE_INDEX<tab>START_RESIDUE<tab>END_RESIDUE<tab>COLOUR\n"\r
- +"SequenceID is used in preference to SequenceIndex if both are provided.\n"\r
- +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n"\r
- +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n"\r
- +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n"\r
- +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n"\r
- +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n"\r
- +"-msf FILE\tCreate alignment file FILE in MSF format.\n"\r
- +"-pileup FILE\tCreate alignment file FILE in Pileup format\n"\r
- +"-pir FILE\tCreate alignment file FILE in PIR format.\n"\r
- +"-blc FILE\tCreate alignment file FILE in BLC format.\n"\r
- +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n"\r
- +"-png FILE\tCreate PNG image FILE from alignment.\n"\r
- +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"\r
- +"-eps FILE\tCreate EPS file FILE from alignment.");\r
- System.exit(0);\r
\r
- }\r
\r
- if (!aparser.contains("nodisplay"))\r
- desktop.setVisible(true);\r
+ String file = null, protocol = null, format = null, groups=null;\r
+ jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();\r
\r
file = aparser.getValue("open");\r
\r
- if (file == null && !desktop.isVisible())\r
+ if (file == null && desktop==null)\r
{\r
System.out.println("No files to open!");\r
System.exit(1);\r
}\r
- else if(!file.startsWith("http://"))\r
+\r
+ if(file!=null)\r
{\r
- if (!(new java.io.File(file)).exists())\r
+\r
+ if (!file.startsWith("http://"))\r
{\r
- System.out.println("Can't find " + file);\r
- System.exit(1);\r
+ if (! (new java.io.File(file)).exists())\r
+ {\r
+ System.out.println("Can't find " + file);\r
+ System.exit(1);\r
+ }\r
}\r
- }\r
-\r
- protocol = "File";\r
\r
- if (file.indexOf("http:") > -1)\r
- {\r
- protocol = "URL";\r
- }\r
+ protocol = "File";\r
\r
- if(file.endsWith(".jar"))\r
- format = "Jalview";\r
- else\r
- format = jalview.io.IdentifyFile.Identify(file, protocol);\r
+ if (file.indexOf("http:") > -1)\r
+ {\r
+ protocol = "URL";\r
+ }\r
\r
- System.out.println("Opening: " + format + " file " + file);\r
+ if (file.endsWith(".jar"))\r
+ format = "Jalview";\r
+ else\r
+ format = jalview.io.IdentifyFile.Identify(file, protocol);\r
\r
- AlignFrame af = desktop.LoadFileWaitTillLoaded(file, protocol, format);\r
+ System.out.println("Opening: " + format + " file " + file);\r
\r
- groups = aparser.getValue("groups");\r
- if(groups!=null)\r
- {\r
- af.parseGroupsFile(groups);\r
- }\r
+ AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);\r
\r
- String imageName = "unnamed.png";\r
- while (aparser.getSize() > 1)\r
- {\r
- format = aparser.nextValue();\r
- file = aparser.nextValue();\r
-\r
- if (format.equalsIgnoreCase("png"))\r
+ groups = aparser.getValue("groups");\r
+ if (groups != null)\r
{\r
- af.createPNG(new java.io.File(file));\r
- imageName = (new java.io.File(file)).getName();\r
- System.out.println("Creating PNG image: " + file);\r
- continue;\r
+ af.parseGroupsFile(groups);\r
}\r
- else if (format.equalsIgnoreCase("imgMap"))\r
+\r
+ String imageName = "unnamed.png";\r
+ while (aparser.getSize() > 1)\r
{\r
- af.createImageMap(new java.io.File(file), imageName);\r
- System.out.println("Creating image map: " + file);\r
- continue;\r
+ format = aparser.nextValue();\r
+ file = aparser.nextValue();\r
+\r
+ if (format.equalsIgnoreCase("png"))\r
+ {\r
+ af.createPNG(new java.io.File(file));\r
+ imageName = (new java.io.File(file)).getName();\r
+ System.out.println("Creating PNG image: " + file);\r
+ continue;\r
+ }\r
+ else if (format.equalsIgnoreCase("imgMap"))\r
+ {\r
+ af.createImageMap(new java.io.File(file), imageName);\r
+ System.out.println("Creating image map: " + file);\r
+ continue;\r
+ }\r
+ else if (format.equalsIgnoreCase("eps"))\r
+ {\r
+ System.out.println("Creating EPS file: " + file);\r
+ af.createEPS(new java.io.File(file));\r
+ continue;\r
+ }\r
+\r
+ if (af.saveAlignment(file, format))\r
+ System.out.println("Written alignment in " + format +\r
+ " format to " + file);\r
+ else\r
+ System.out.println("Error writing file " + file + " in " + format +\r
+ " format!!");\r
+\r
}\r
- else if (format.equalsIgnoreCase("eps"))\r
+\r
+ while (aparser.getSize() > 0)\r
{\r
- System.out.println("Creating EPS file: " + file);\r
- af.createEPS(new java.io.File(file));\r
- continue;\r
+ System.out.println("Unknown arg: " + aparser.nextValue());\r
}\r
-\r
- if (af.saveAlignment(file, format))\r
- System.out.println("Written alignment in " + format +\r
- " format to " + file);\r
- else\r
- System.out.println("Error writing file " + file + " in " + format +\r
- " format!!");\r
-\r
- }\r
-\r
- while (aparser.getSize() > 0)\r
- {\r
- System.out.println("Unknown arg: " + aparser.nextValue());\r
}\r
- }\r
\r
- if (jalview.gui.Preferences.showStartupFile &&\r
- (jalview.gui.Preferences.startupFile != null))\r
+ // We'll only open the default file if the desktop is visible.\r
+ //////////////////////\r
+ if (\r
+ !headless &&\r
+ jalview.gui.Preferences.showStartupFile &&\r
+ jalview.gui.Preferences.startupFile != null)\r
{\r
\r
file = jalview.gui.Preferences.startupFile;\r
}\r
}\r
\r
- if (!desktop.isVisible())\r
+\r
+ if (desktop==null)\r
System.exit(0);\r
}\r
}\r