From c3ded07cf4a7708564e9878bf1763fe837e03ddc Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 3 Aug 2005 13:07:11 +0000 Subject: [PATCH] Can run headless=true --- src/jalview/bin/Cache.java | 13 ++- src/jalview/bin/Jalview.java | 223 ++++++++++++++++++++---------------- src/jalview/jbgui/GAlignFrame.java | 1 - 3 files changed, 131 insertions(+), 106 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index e2477d9..d8a6d3d 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -105,8 +105,14 @@ public class Cache jnlpVersion = "Test"; } + + System.out.println("Version: "+codeVersion); + // jnlpVersion will be null if we're using InstallAnywhere - if(jnlpVersion==null) + // Dont do this check if running in headless mode + if(jnlpVersion==null && ( + System.getProperty("java.awt.headless")==null + || System.getProperty("java.awt.headless").equals("false"))) { try{ java.net.URL url = new java.net.URL("http://www.jalview.org/webstart/jalview.jnlp"); @@ -124,10 +130,9 @@ public class Cache } }catch(Exception ex) { jnlpVersion = codeVersion; } - } - System.out.println("Version: "+codeVersion); - System.out.println("Latest : "+jnlpVersion); + System.out.println("Latest : "+jnlpVersion); + } setProperty("LATEST_VERSION", jnlpVersion); setProperty("VERSION", codeVersion); diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 395875c..3ab3bf4 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -25,6 +25,9 @@ import org.apache.log4j.*; import javax.swing.*; import java.util.Vector; +import jalview.datamodel.Alignment; +import jalview.io.FormatAdapter; +import jalview.datamodel.SequenceI; /** @@ -73,17 +76,42 @@ public class Jalview public static void main(String[] args) { ArgsParser aparser = new ArgsParser(args); + boolean headless = false; + + if( aparser.contains("help") || aparser.contains("h") ) + { + System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" + +"-nodisplay\tRun Jalview without User Interface.\n" + +"-props FILE\tUse the given Jalview properties file instead of users default.\n" + +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n" + +"TEXTSEQUENCE_IDSEQUENCE_INDEXSTART_RESIDUEEND_RESIDUECOLOUR\n" + +"SequenceID is used in preference to SequenceIndex if both are provided.\n" + +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n" + +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n" + +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n" + +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n" + +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n" + +"-msf FILE\tCreate alignment file FILE in MSF format.\n" + +"-pileup FILE\tCreate alignment file FILE in Pileup format\n" + +"-pir FILE\tCreate alignment file FILE in PIR format.\n" + +"-blc FILE\tCreate alignment file FILE in BLC format.\n" + +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n" + +"-png FILE\tCreate PNG image FILE from alignment.\n" + +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" + +"-eps FILE\tCreate EPS file FILE from alignment."); + System.exit(0); + } + + + if (aparser.contains("nodisplay")) + System.setProperty("java.awt.headless", "true"); + + if( System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) + { + headless = true; + } - try - { - UIManager.setLookAndFeel( - // "javax.swing.plaf.metal.MetalLookAndFeel" - // "javax.swing.plaf.multi.MultiLookAndFeel" - UIManager.getSystemLookAndFeelClassName()); - } - catch (Exception ex) - { - } Cache.loadProperties(aparser.getValue("props")); jalview.gui.Preferences.initPreferences(); @@ -97,125 +125,117 @@ public class Jalview } - String file = null, protocol = null, format = null, groups=null; - Desktop desktop = new Desktop(); - - - if(args==null || args.length==0) + Desktop desktop = null; + if( !headless ) { + try + { + UIManager.setLookAndFeel( + // "javax.swing.plaf.metal.MetalLookAndFeel" + // "javax.swing.plaf.multi.MultiLookAndFeel" + UIManager.getSystemLookAndFeelClassName()); + } + catch (Exception ex) + { + } + + desktop = new Desktop(); desktop.setVisible(true); } - else - { - if( aparser.contains("help") || aparser.contains("h") ) - { - System.out.println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" - +"-nodisplay\tRun Jalview without User Interface.\n" - +"-props FILE\tUse the given Jalview properties file instead of users default.\n" - +"-groups FILE\tUse the given file to mark groups on the alignment. \nGroups file is in the following tab delimited format\n" - +"TEXTSEQUENCE_IDSEQUENCE_INDEXSTART_RESIDUEEND_RESIDUECOLOUR\n" - +"SequenceID is used in preference to SequenceIndex if both are provided.\n" - +"Enter ID_NOT_SPECIFIED for SEQUENCE_ID or -1 for SEQUENCE_INDEX if unknown.\n" - +"COLOUR can be hexadecimal RGB or 'red', 'blue' etc.\n\n" - +"-fasta FILE\tCreate alignment file FILE in Fasta format.\n" - +"-clustal FILE\tCreate alignment file FILE in Clustal format.\n" - +"-pfam FILE\tCreate alignment file FILE in PFAM format.\n" - +"-msf FILE\tCreate alignment file FILE in MSF format.\n" - +"-pileup FILE\tCreate alignment file FILE in Pileup format\n" - +"-pir FILE\tCreate alignment file FILE in PIR format.\n" - +"-blc FILE\tCreate alignment file FILE in BLC format.\n" - +"-jalview FILE\tCreate alignment file FILE in Jalview format.\n" - +"-png FILE\tCreate PNG image FILE from alignment.\n" - +"-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n" - +"-eps FILE\tCreate EPS file FILE from alignment."); - System.exit(0); - } - if (!aparser.contains("nodisplay")) - desktop.setVisible(true); + String file = null, protocol = null, format = null, groups=null; + jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(); file = aparser.getValue("open"); - if (file == null && !desktop.isVisible()) + if (file == null && desktop==null) { System.out.println("No files to open!"); System.exit(1); } - else if(!file.startsWith("http://")) + + if(file!=null) { - if (!(new java.io.File(file)).exists()) + + if (!file.startsWith("http://")) { - System.out.println("Can't find " + file); - System.exit(1); + if (! (new java.io.File(file)).exists()) + { + System.out.println("Can't find " + file); + System.exit(1); + } } - } - - protocol = "File"; - if (file.indexOf("http:") > -1) - { - protocol = "URL"; - } + protocol = "File"; - if(file.endsWith(".jar")) - format = "Jalview"; - else - format = jalview.io.IdentifyFile.Identify(file, protocol); + if (file.indexOf("http:") > -1) + { + protocol = "URL"; + } - System.out.println("Opening: " + format + " file " + file); + if (file.endsWith(".jar")) + format = "Jalview"; + else + format = jalview.io.IdentifyFile.Identify(file, protocol); - AlignFrame af = desktop.LoadFileWaitTillLoaded(file, protocol, format); + System.out.println("Opening: " + format + " file " + file); - groups = aparser.getValue("groups"); - if(groups!=null) - { - af.parseGroupsFile(groups); - } + AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format); - String imageName = "unnamed.png"; - while (aparser.getSize() > 1) - { - format = aparser.nextValue(); - file = aparser.nextValue(); - - if (format.equalsIgnoreCase("png")) + groups = aparser.getValue("groups"); + if (groups != null) { - af.createPNG(new java.io.File(file)); - imageName = (new java.io.File(file)).getName(); - System.out.println("Creating PNG image: " + file); - continue; + af.parseGroupsFile(groups); } - else if (format.equalsIgnoreCase("imgMap")) + + String imageName = "unnamed.png"; + while (aparser.getSize() > 1) { - af.createImageMap(new java.io.File(file), imageName); - System.out.println("Creating image map: " + file); - continue; + format = aparser.nextValue(); + file = aparser.nextValue(); + + if (format.equalsIgnoreCase("png")) + { + af.createPNG(new java.io.File(file)); + imageName = (new java.io.File(file)).getName(); + System.out.println("Creating PNG image: " + file); + continue; + } + else if (format.equalsIgnoreCase("imgMap")) + { + af.createImageMap(new java.io.File(file), imageName); + System.out.println("Creating image map: " + file); + continue; + } + else if (format.equalsIgnoreCase("eps")) + { + System.out.println("Creating EPS file: " + file); + af.createEPS(new java.io.File(file)); + continue; + } + + if (af.saveAlignment(file, format)) + System.out.println("Written alignment in " + format + + " format to " + file); + else + System.out.println("Error writing file " + file + " in " + format + + " format!!"); + } - else if (format.equalsIgnoreCase("eps")) + + while (aparser.getSize() > 0) { - System.out.println("Creating EPS file: " + file); - af.createEPS(new java.io.File(file)); - continue; + System.out.println("Unknown arg: " + aparser.nextValue()); } - - if (af.saveAlignment(file, format)) - System.out.println("Written alignment in " + format + - " format to " + file); - else - System.out.println("Error writing file " + file + " in " + format + - " format!!"); - - } - - while (aparser.getSize() > 0) - { - System.out.println("Unknown arg: " + aparser.nextValue()); } - } - if (jalview.gui.Preferences.showStartupFile && - (jalview.gui.Preferences.startupFile != null)) + // We'll only open the default file if the desktop is visible. + ////////////////////// + if ( + !headless && + jalview.gui.Preferences.showStartupFile && + jalview.gui.Preferences.startupFile != null) { file = jalview.gui.Preferences.startupFile; @@ -237,7 +257,8 @@ public class Jalview } } - if (!desktop.isVisible()) + + if (desktop==null) System.exit(0); } } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 6c235a4..e4842ee 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -226,7 +226,6 @@ public class GAlignFrame } catch (Exception e) { - e.printStackTrace(); } } -- 1.7.10.2