2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Color;
24 import java.io.BufferedReader;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.io.OutputStreamWriter;
30 import java.io.PrintWriter;
31 import java.net.MalformedURLException;
33 import java.net.URISyntaxException;
35 import java.security.AllPermission;
36 import java.security.CodeSource;
37 import java.security.PermissionCollection;
38 import java.security.Permissions;
39 import java.security.Policy;
40 import java.util.HashMap;
41 import java.util.Locale;
43 import java.util.Vector;
44 import java.util.logging.ConsoleHandler;
45 import java.util.logging.Level;
46 import java.util.logging.Logger;
48 import javax.swing.JDialog;
49 import javax.swing.JFrame;
50 import javax.swing.JOptionPane;
51 import javax.swing.SwingUtilities;
52 import javax.swing.UIManager;
53 import javax.swing.UIManager.LookAndFeelInfo;
54 import javax.swing.UnsupportedLookAndFeelException;
56 import com.formdev.flatlaf.FlatLightLaf;
57 import com.formdev.flatlaf.themes.FlatMacLightLaf;
58 import com.formdev.flatlaf.util.SystemInfo;
59 import com.threerings.getdown.util.LaunchUtil;
61 //import edu.stanford.ejalbert.launching.IBrowserLaunching;
62 import groovy.lang.Binding;
63 import groovy.util.GroovyScriptEngine;
64 import jalview.ext.so.SequenceOntology;
65 import jalview.gui.AlignFrame;
66 import jalview.gui.Desktop;
67 import jalview.gui.PromptUserConfig;
68 import jalview.gui.QuitHandler;
69 import jalview.gui.QuitHandler.QResponse;
70 import jalview.io.AppletFormatAdapter;
71 import jalview.io.BioJsHTMLOutput;
72 import jalview.io.DataSourceType;
73 import jalview.io.FileFormat;
74 import jalview.io.FileFormatException;
75 import jalview.io.FileFormatI;
76 import jalview.io.FileFormats;
77 import jalview.io.FileLoader;
78 import jalview.io.HtmlSvgOutput;
79 import jalview.io.IdentifyFile;
80 import jalview.io.NewickFile;
81 import jalview.io.gff.SequenceOntologyFactory;
82 import jalview.schemes.ColourSchemeI;
83 import jalview.schemes.ColourSchemeProperty;
84 import jalview.util.ChannelProperties;
85 import jalview.util.HttpUtils;
86 import jalview.util.LaunchUtils;
87 import jalview.util.MessageManager;
88 import jalview.util.Platform;
89 import jalview.ws.jws2.Jws2Discoverer;
92 * Main class for Jalview Application <br>
94 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
97 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
98 * jalview.bin.Jalview jalview.bin.Jalview
100 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
101 * embellish '*' to e.g. '*.jar')
104 * @version $Revision$
110 Platform.getURLCommandArguments();
111 Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
112 Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
113 Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
114 Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
118 * singleton instance of this class
120 private static Jalview instance;
122 private Desktop desktop;
124 public static AlignFrame currentAlignFrame;
128 if (!Platform.isJS())
135 // grab all the rights we can for the JVM
136 Policy.setPolicy(new Policy()
139 public PermissionCollection getPermissions(CodeSource codesource)
141 Permissions perms = new Permissions();
142 perms.add(new AllPermission());
147 public void refresh()
155 * keep track of feature fetching tasks.
163 * TODO: generalise to track all jalview events to orchestrate batch processing
167 private int queued = 0;
169 private int running = 0;
171 public FeatureFetcher()
176 public void addFetcher(final AlignFrame af,
177 final Vector<String> dasSources)
179 final long id = System.currentTimeMillis();
181 final FeatureFetcher us = this;
182 new Thread(new Runnable()
194 af.setProgressBar(MessageManager
195 .getString("status.das_features_being_retrived"), id);
196 af.featureSettings_actionPerformed(null);
197 af.setProgressBar(null, id);
206 public synchronized boolean allFinished()
208 return queued == 0 && running == 0;
213 public static Jalview getInstance()
219 * main class for Jalview application
222 * open <em>filename</em>
224 public static void main(String[] args)
226 // setLogging(); // BH - for event debugging in JavaScript
227 instance = new Jalview();
228 instance.doMain(args);
231 private static void logClass(String name)
233 // BH - for event debugging in JavaScript
234 ConsoleHandler consoleHandler = new ConsoleHandler();
235 consoleHandler.setLevel(Level.ALL);
236 Logger logger = Logger.getLogger(name);
237 logger.setLevel(Level.ALL);
238 logger.addHandler(consoleHandler);
241 @SuppressWarnings("unused")
242 private static void setLogging()
250 System.out.println("not in js");
253 // BH - for event debugging in JavaScript (Java mode only)
254 if (!Platform.isJS())
261 Logger.getLogger("").setLevel(Level.ALL);
262 logClass("java.awt.EventDispatchThread");
263 logClass("java.awt.EventQueue");
264 logClass("java.awt.Component");
265 logClass("java.awt.focus.Component");
266 logClass("java.awt.focus.DefaultKeyboardFocusManager");
274 void doMain(String[] args)
277 if (!Platform.isJS())
279 System.setSecurityManager(null);
281 Runtime.getRuntime().addShutdownHook(new Thread()
285 Console.debug("Running shutdown hook");
286 if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
288 // Got to here by a SIGTERM signal.
289 // Note we will not actually cancel the quit from here -- it's too
290 // late -- but we can wait for saving files.
291 Console.debug("Checking for saving files");
292 QuitHandler.getQuitResponse(false);
296 Console.debug("Nothing more to do");
298 Console.debug("Exiting, bye!");
299 // shutdownHook cannot be cancelled, JVM will now halt
305 .println("Java version: " + System.getProperty("java.version"));
306 System.out.println("Java Home: " + System.getProperty("java.home"));
307 System.out.println(System.getProperty("os.arch") + " "
308 + System.getProperty("os.name") + " "
309 + System.getProperty("os.version"));
311 String val = System.getProperty("sys.install4jVersion");
314 System.out.println("Install4j version: " + val);
316 val = System.getProperty("installer_template_version");
319 System.out.println("Install4j template version: " + val);
321 val = System.getProperty("launcher_version");
324 System.out.println("Launcher version: " + val);
327 if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11)
329 System.setProperty("flatlaf.uiScale", "1");
332 // report Jalview version
333 Cache.loadBuildProperties(true);
335 ArgsParser aparser = new ArgsParser(args);
337 boolean headless = false;
339 String usrPropsFile = aparser.getValue("props");
340 Cache.loadProperties(usrPropsFile); // must do this
342 if (usrPropsFile != null)
345 "CMD [-props " + usrPropsFile + "] executed successfully!");
348 if (!Platform.isJS())
355 if (aparser.contains("help") || aparser.contains("h"))
360 if (aparser.contains("nodisplay") || aparser.contains("nogui")
361 || aparser.contains("headless"))
363 System.setProperty("java.awt.headless", "true");
368 // allow https handshakes to download intermediate certs if necessary
369 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
371 final String jabawsUrl = aparser.getValue("jabaws");
372 if (jabawsUrl != null)
376 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
378 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
379 } catch (MalformedURLException e)
382 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
387 String defs = aparser.getValue("setprop");
390 int p = defs.indexOf('=');
393 System.err.println("Ignoring invalid setprop argument : " + defs);
397 System.out.println("Executing setprop argument: " + defs);
400 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
402 // DISABLED FOR SECURITY REASONS
403 // TODO: add a property to allow properties to be overriden by cli args
404 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
406 defs = aparser.getValue("setprop");
408 if (System.getProperty("java.awt.headless") != null
409 && System.getProperty("java.awt.headless").equals("true"))
413 System.setProperty("http.agent",
414 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
418 Console.initLogger();
421 NoClassDefFoundError error)
423 error.printStackTrace();
424 System.out.println("\nEssential logging libraries not found."
425 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
434 * configure 'full' SO model if preferences say to, else use the default (full SO)
435 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
437 boolean soDefault = !Platform.isJS();
438 if (Cache.getDefault("USE_FULL_SO", soDefault))
440 SequenceOntologyFactory.setInstance(new SequenceOntology());
445 Desktop.nosplash = aparser.contains("nosplash");
446 desktop = new Desktop();
447 desktop.setInBatchMode(true); // indicate we are starting up
451 JalviewTaskbar.setTaskbar(this);
452 } catch (Exception e)
454 Console.info("Cannot set Taskbar");
455 Console.error(e.getMessage());
456 // e.printStackTrace();
457 } catch (Throwable t)
459 Console.info("Cannot set Taskbar");
460 Console.error(t.getMessage());
461 // t.printStackTrace();
464 // set Proxy settings before all the internet calls
465 Cache.setProxyPropertiesFromPreferences();
467 desktop.setVisible(true);
469 if (!Platform.isJS())
478 * Check to see that the JVM version being run is suitable for the Java
479 * version this Jalview was compiled for. Popup a warning if not.
481 if (!LaunchUtils.checkJavaVersion())
483 Console.warn("The Java version being used (Java "
484 + LaunchUtils.getJavaVersion()
485 + ") may lead to problems. This installation of Jalview should be used with Java "
486 + LaunchUtils.getJavaCompileVersion() + ".");
489 .getBooleanUserPreference("IGNORE_JVM_WARNING_POPUP"))
492 MessageManager.getString("label.continue") };
493 JOptionPane.showOptionDialog(null,
494 MessageManager.formatMessage(
495 "warning.wrong_jvm_version_message",
496 LaunchUtils.getJavaVersion(),
497 LaunchUtils.getJavaCompileVersion()),
499 .getString("warning.wrong_jvm_version_title"),
500 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
501 null, options, options[0]);
505 if (!aparser.contains("nowebservicediscovery"))
507 desktop.startServiceDiscovery();
509 if (!aparser.contains("nousagestats"))
511 startUsageStats(desktop);
515 System.err.println("CMD [-nousagestats] executed successfully!");
518 if (!aparser.contains("noquestionnaire"))
520 String url = aparser.getValue("questionnaire");
523 // Start the desktop questionnaire prompter with the specified
525 Console.debug("Starting questionnaire url at " + url);
526 desktop.checkForQuestionnaire(url);
527 System.out.println("CMD questionnaire[-" + url
528 + "] executed successfully!");
532 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
534 // Start the desktop questionnaire prompter with the specified
537 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
539 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
541 "Starting questionnaire with default url: " + defurl);
542 desktop.checkForQuestionnaire(defurl);
549 .println("CMD [-noquestionnaire] executed successfully!");
552 if (!aparser.contains("nonews")
553 || Cache.getProperty("NONEWS") == null)
555 desktop.checkForNews();
558 if (!aparser.contains("nohtmltemplates")
559 || Cache.getProperty("NOHTMLTEMPLATES") == null)
561 BioJsHTMLOutput.updateBioJS();
566 // Check if JVM and compile version might cause problems and log if it
568 if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
570 Console.warn("The Java version being used (Java "
571 + LaunchUtils.getJavaVersion()
572 + ") may lead to problems. This installation of Jalview should be used with Java "
573 + LaunchUtils.getJavaCompileVersion() + ".");
576 // Move any new getdown-launcher-new.jar into place over old
577 // getdown-launcher.jar
578 String appdirString = System.getProperty("getdownappdir");
579 if (appdirString != null && appdirString.length() > 0)
581 final File appdir = new File(appdirString);
587 LaunchUtil.upgradeGetdown(
588 new File(appdir, "getdown-launcher-old.jar"),
589 new File(appdir, "getdown-launcher.jar"),
590 new File(appdir, "getdown-launcher-new.jar"));
595 String file = null, data = null;
597 FileFormatI format = null;
599 DataSourceType protocol = null;
601 FileLoader fileLoader = new FileLoader(!headless);
603 String groovyscript = null; // script to execute after all loading is
604 // completed one way or another
605 // extract groovy argument and execute if necessary
606 groovyscript = aparser.getValue("groovy", true);
607 file = aparser.getValue("open", true);
609 if (file == null && desktop == null)
611 System.out.println("No files to open!");
616 // Finally, deal with the remaining input data.
621 desktop.setProgressBar(
623 .getString("status.processing_commandline_args"),
624 progress = System.currentTimeMillis());
626 System.out.println("CMD [-open " + file + "] executed successfully!");
628 if (!Platform.isJS())
630 * ignore in JavaScript -- can't just file existence - could load it?
635 if (!HttpUtils.startsWithHttpOrHttps(file))
637 if (!(new File(file)).exists())
639 System.out.println("Can't find " + file);
648 protocol = AppletFormatAdapter.checkProtocol(file);
652 format = new IdentifyFile().identify(file, protocol);
653 } catch (FileFormatException e1)
658 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
662 System.out.println("error");
666 setCurrentAlignFrame(af);
667 data = aparser.getValue("colour", true);
670 data.replaceAll("%20", " ");
672 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
673 af.getViewport(), af.getViewport().getAlignment(), data);
678 "CMD [-color " + data + "] executed successfully!");
683 // Must maintain ability to use the groups flag
684 data = aparser.getValue("groups", true);
687 af.parseFeaturesFile(data,
688 AppletFormatAdapter.checkProtocol(data));
689 // System.out.println("Added " + data);
691 "CMD groups[-" + data + "] executed successfully!");
693 data = aparser.getValue("features", true);
696 af.parseFeaturesFile(data,
697 AppletFormatAdapter.checkProtocol(data));
698 // System.out.println("Added " + data);
700 "CMD [-features " + data + "] executed successfully!");
703 data = aparser.getValue("annotations", true);
706 af.loadJalviewDataFile(data, null, null, null);
707 // System.out.println("Added " + data);
709 "CMD [-annotations " + data + "] executed successfully!");
711 // set or clear the sortbytree flag.
712 if (aparser.contains("sortbytree"))
714 af.getViewport().setSortByTree(true);
715 if (af.getViewport().getSortByTree())
717 System.out.println("CMD [-sortbytree] executed successfully!");
720 if (aparser.contains("no-annotation"))
722 af.getViewport().setShowAnnotation(false);
723 if (!af.getViewport().isShowAnnotation())
725 System.out.println("CMD no-annotation executed successfully!");
728 if (aparser.contains("nosortbytree"))
730 af.getViewport().setSortByTree(false);
731 if (!af.getViewport().getSortByTree())
734 .println("CMD [-nosortbytree] executed successfully!");
737 data = aparser.getValue("tree", true);
743 "CMD [-tree " + data + "] executed successfully!");
744 NewickFile nf = new NewickFile(data,
745 AppletFormatAdapter.checkProtocol(data));
747 .setCurrentTree(af.showNewickTree(nf, data).getTree());
748 } catch (IOException ex)
750 System.err.println("Couldn't add tree " + data);
751 ex.printStackTrace(System.err);
754 // TODO - load PDB structure(s) to alignment JAL-629
755 // (associate with identical sequence in alignment, or a specified
757 if (groovyscript != null)
759 // Execute the groovy script after we've done all the rendering stuff
760 // and before any images or figures are generated.
761 System.out.println("Executing script " + groovyscript);
762 executeGroovyScript(groovyscript, af);
763 System.out.println("CMD groovy[" + groovyscript
764 + "] executed successfully!");
767 String imageName = "unnamed.png";
768 while (aparser.getSize() > 1)
770 String outputFormat = aparser.nextValue();
771 file = aparser.nextValue();
773 if (outputFormat.equalsIgnoreCase("png"))
775 af.createPNG(new File(file));
776 imageName = (new File(file)).getName();
777 System.out.println("Creating PNG image: " + file);
780 else if (outputFormat.equalsIgnoreCase("svg"))
782 File imageFile = new File(file);
783 imageName = imageFile.getName();
784 af.createSVG(imageFile);
785 System.out.println("Creating SVG image: " + file);
788 else if (outputFormat.equalsIgnoreCase("html"))
790 File imageFile = new File(file);
791 imageName = imageFile.getName();
792 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
793 htmlSVG.exportHTML(file);
795 System.out.println("Creating HTML image: " + file);
798 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
802 System.err.println("The output html file must not be null");
807 BioJsHTMLOutput.refreshVersionInfo(
808 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
809 } catch (URISyntaxException e)
813 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
814 bjs.exportHTML(file);
816 .println("Creating BioJS MSA Viwer HTML file: " + file);
819 else if (outputFormat.equalsIgnoreCase("imgMap"))
821 af.createImageMap(new File(file), imageName);
822 System.out.println("Creating image map: " + file);
825 else if (outputFormat.equalsIgnoreCase("eps"))
827 File outputFile = new File(file);
829 "Creating EPS file: " + outputFile.getAbsolutePath());
830 af.createEPS(outputFile);
833 FileFormatI outFormat = null;
836 outFormat = FileFormats.getInstance().forName(outputFormat);
837 } catch (Exception formatP)
839 System.out.println("Couldn't parse " + outFormat
840 + " as a valid Jalview format string.");
842 if (outFormat != null)
844 if (!outFormat.isWritable())
847 "This version of Jalview does not support alignment export as "
852 af.saveAlignment(file, outFormat);
853 if (af.isSaveAlignmentSuccessful())
855 System.out.println("Written alignment in "
856 + outFormat.getName() + " format to " + file);
860 System.out.println("Error writing file " + file + " in "
861 + outFormat.getName() + " format!!");
868 while (aparser.getSize() > 0)
870 System.out.println("Unknown arg: " + aparser.nextValue());
875 AlignFrame startUpAlframe = null;
876 // We'll only open the default file if the desktop is visible.
878 // ////////////////////
880 if (!Platform.isJS() && !headless && file == null
881 && Cache.getDefault("SHOW_STARTUP_FILE", true))
888 file = Cache.getDefault("STARTUP_FILE",
889 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
890 + "/examples/exampleFile_2_7.jvp");
891 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
893 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
895 file.replace("http:", "https:");
896 // hardwire upgrade of the startup file
897 file.replace("_2_3", "_2_7");
898 file.replace("2_7.jar", "2_7.jvp");
899 // and remove the stale setting
900 Cache.removeProperty("STARTUP_FILE");
903 protocol = AppletFormatAdapter.checkProtocol(file);
905 if (file.endsWith(".jar"))
907 format = FileFormat.Jalview;
913 format = new IdentifyFile().identify(file, protocol);
914 } catch (FileFormatException e)
920 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
922 // don't ask to save when quitting if only the startup file has been
924 Console.debug("Resetting up-to-date flag for startup file");
925 startUpAlframe.getViewport().setSavedUpToDate(true);
926 // extract groovy arguments before anything else.
929 // Once all other stuff is done, execute any groovy scripts (in order)
930 if (groovyscript != null)
932 if (Cache.groovyJarsPresent())
934 System.out.println("Executing script " + groovyscript);
935 executeGroovyScript(groovyscript, startUpAlframe);
940 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
944 // and finally, turn off batch mode indicator - if the desktop still exists
949 desktop.setProgressBar(null, progress);
951 desktop.setInBatchMode(false);
955 private static void setLookAndFeel()
957 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
959 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
961 String lafProp = System.getProperty("laf");
962 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
968 else if (lafSetting != null)
972 boolean lafSet = false;
975 case "crossplatform":
976 lafSet = setCrossPlatformLookAndFeel();
979 Console.error("Could not set requested laf=" + laf);
983 lafSet = setSystemLookAndFeel();
986 Console.error("Could not set requested laf=" + laf);
990 lafSet = setGtkLookAndFeel();
993 Console.error("Could not set requested laf=" + laf);
997 lafSet = setMetalLookAndFeel();
1000 Console.error("Could not set requested laf=" + laf);
1004 lafSet = setNimbusLookAndFeel();
1007 Console.error("Could not set requested laf=" + laf);
1011 lafSet = setFlatLookAndFeel();
1014 Console.error("Could not set requested laf=" + laf);
1018 lafSet = setMacLookAndFeel();
1021 Console.error("Could not set requested laf=" + laf);
1027 Console.error("Requested laf=" + laf + " not implemented");
1031 setSystemLookAndFeel();
1032 if (Platform.isLinux())
1034 setLinuxLookAndFeel();
1036 if (Platform.isMac())
1038 setMacLookAndFeel();
1043 private static boolean setCrossPlatformLookAndFeel()
1045 boolean set = false;
1048 UIManager.setLookAndFeel(
1049 UIManager.getCrossPlatformLookAndFeelClassName());
1051 } catch (Exception ex)
1053 Console.error("Unexpected Look and Feel Exception");
1054 Console.error(ex.getMessage());
1055 Console.debug(Cache.getStackTraceString(ex));
1060 private static boolean setSystemLookAndFeel()
1062 boolean set = false;
1065 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1067 } catch (Exception ex)
1069 Console.error("Unexpected Look and Feel Exception");
1070 Console.error(ex.getMessage());
1071 Console.debug(Cache.getStackTraceString(ex));
1076 private static boolean setSpecificLookAndFeel(String name,
1077 String className, boolean nameStartsWith)
1079 boolean set = false;
1082 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1084 if (info.getName() != null && nameStartsWith
1085 ? info.getName().toLowerCase(Locale.ROOT)
1086 .startsWith(name.toLowerCase(Locale.ROOT))
1087 : info.getName().toLowerCase(Locale.ROOT)
1088 .equals(name.toLowerCase(Locale.ROOT)))
1090 className = info.getClassName();
1094 UIManager.setLookAndFeel(className);
1096 } catch (Exception ex)
1098 Console.error("Unexpected Look and Feel Exception");
1099 Console.error(ex.getMessage());
1100 Console.debug(Cache.getStackTraceString(ex));
1105 private static boolean setGtkLookAndFeel()
1107 return setSpecificLookAndFeel("gtk",
1108 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1111 private static boolean setMetalLookAndFeel()
1113 return setSpecificLookAndFeel("metal",
1114 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1117 private static boolean setNimbusLookAndFeel()
1119 return setSpecificLookAndFeel("nimbus",
1120 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1123 private static boolean setFlatLookAndFeel()
1125 boolean set = false;
1126 if (SystemInfo.isMacOS)
1130 UIManager.setLookAndFeel(
1131 "com.formdev.flatlaf.themes.FlatMacLightLaf");
1133 Console.debug("Using FlatMacLightLaf");
1134 } catch (ClassNotFoundException | InstantiationException
1135 | IllegalAccessException | UnsupportedLookAndFeelException e)
1137 Console.debug("Exception loading FlatLightLaf", e);
1139 System.setProperty("apple.laf.useScreenMenuBar", "true");
1140 System.setProperty("apple.awt.application.name",
1141 ChannelProperties.getProperty("app_name"));
1142 System.setProperty("apple.awt.application.appearance", "system");
1143 if (SystemInfo.isMacFullWindowContentSupported
1144 && Desktop.desktop != null)
1146 Console.debug("Setting transparent title bar");
1147 Desktop.desktop.getRootPane()
1148 .putClientProperty("apple.awt.fullWindowContent", true);
1149 Desktop.desktop.getRootPane()
1150 .putClientProperty("apple.awt.transparentTitleBar", true);
1151 Desktop.desktop.getRootPane()
1152 .putClientProperty("apple.awt.fullscreenable", true);
1154 SwingUtilities.invokeLater(() -> {
1155 FlatMacLightLaf.setup();
1157 Console.debug("Using FlatMacLightLaf");
1164 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1166 Console.debug("Using FlatLightLaf");
1167 } catch (ClassNotFoundException | InstantiationException
1168 | IllegalAccessException | UnsupportedLookAndFeelException e)
1170 Console.debug("Exception loading FlatLightLaf", e);
1172 // Windows specific properties here
1173 SwingUtilities.invokeLater(() -> {
1174 FlatLightLaf.setup();
1176 Console.debug("Using FlatLightLaf");
1179 else if (SystemInfo.isLinux)
1183 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1185 Console.debug("Using FlatLightLaf");
1186 } catch (ClassNotFoundException | InstantiationException
1187 | IllegalAccessException | UnsupportedLookAndFeelException e)
1189 Console.debug("Exception loading FlatLightLaf", e);
1191 // enable custom window decorations
1192 JFrame.setDefaultLookAndFeelDecorated(true);
1193 JDialog.setDefaultLookAndFeelDecorated(true);
1194 SwingUtilities.invokeLater(() -> {
1195 FlatLightLaf.setup();
1197 Console.debug("Using FlatLightLaf");
1205 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1207 Console.debug("Using FlatLightLaf");
1208 } catch (ClassNotFoundException | InstantiationException
1209 | IllegalAccessException | UnsupportedLookAndFeelException e)
1211 Console.debug("Exception loading FlatLightLaf", e);
1217 UIManager.put("TabbedPane.tabType", "card");
1218 UIManager.put("TabbedPane.showTabSeparators", true);
1219 UIManager.put("TabbedPane.showContentSeparator", true);
1220 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1221 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1222 UIManager.put("TabbedPane.hasFullBorder", true);
1223 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1224 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1225 UIManager.put("TabbedPane.smoothScrolling", true);
1226 UIManager.put("TabbedPane.tabWidthMode", "compact");
1227 UIManager.put("TabbedPane.selectedBackground", Color.white);
1230 Desktop.setLiveDragMode(Cache.getDefault("FLAT_LIVE_DRAG_MODE", true));
1234 private static boolean setMacLookAndFeel()
1236 boolean set = false;
1237 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1238 ChannelProperties.getProperty("app_name"));
1239 System.setProperty("apple.laf.useScreenMenuBar", "true");
1241 * broken native LAFs on (ARM?) macbooks
1242 set = setQuaquaLookAndFeel();
1243 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1244 .toLowerCase(Locale.ROOT).contains("quaqua"))
1246 set = setVaquaLookAndFeel();
1249 set = setFlatLookAndFeel();
1253 private static boolean setLinuxLookAndFeel()
1255 boolean set = false;
1256 set = setFlatLookAndFeel();
1258 set = setMetalLookAndFeel();
1259 // avoid GtkLookAndFeel -- not good results especially on HiDPI
1261 set = setNimbusLookAndFeel();
1265 private static void showUsage()
1268 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1269 + "-nodisplay\tRun Jalview without User Interface.\n"
1270 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1271 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1272 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1273 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1274 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1275 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1276 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1277 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1278 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1279 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1280 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1281 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1282 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1283 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1284 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1285 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1286 + "-html FILE\tCreate HTML file from alignment.\n"
1287 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1288 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1289 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1290 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1291 + "-noquestionnaire\tTurn off questionnaire check.\n"
1292 + "-nonews\tTurn off check for Jalview news.\n"
1293 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1294 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1296 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1297 // after all other properties files have been read\n\t
1298 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1299 // passed in correctly)"
1300 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1301 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1302 + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
1303 + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1304 + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1305 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1308 private static void startUsageStats(final Desktop desktop)
1311 * start a User Config prompt asking if we can log usage statistics.
1313 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1314 "USAGESTATS", "Jalview Usage Statistics",
1315 "Do you want to help make Jalview better by enabling "
1316 + "the collection of usage statistics with Google Analytics ?"
1317 + "\n\n(you can enable or disable usage tracking in the preferences)",
1324 "Initialising googletracker for usage stats.");
1325 Cache.initGoogleTracker();
1326 Console.debug("Tracking enabled.");
1333 Console.debug("Not enabling Google Tracking.");
1336 desktop.addDialogThread(prompter);
1340 * Locate the given string as a file and pass it to the groovy interpreter.
1342 * @param groovyscript
1343 * the script to execute
1344 * @param jalviewContext
1345 * the Jalview Desktop object passed in to the groovy binding as the
1348 private void executeGroovyScript(String groovyscript, AlignFrame af)
1351 * for scripts contained in files
1358 if (groovyscript.trim().equals("STDIN"))
1360 // read from stdin into a tempfile and execute it
1363 tfile = File.createTempFile("jalview", "groovy");
1364 PrintWriter outfile = new PrintWriter(
1365 new OutputStreamWriter(new FileOutputStream(tfile)));
1366 BufferedReader br = new BufferedReader(
1367 new InputStreamReader(System.in));
1369 while ((line = br.readLine()) != null)
1371 outfile.write(line + "\n");
1377 } catch (Exception ex)
1379 System.err.println("Failed to read from STDIN into tempfile "
1380 + ((tfile == null) ? "(tempfile wasn't created)"
1381 : tfile.toString()));
1382 ex.printStackTrace();
1387 sfile = tfile.toURI().toURL();
1388 } catch (Exception x)
1391 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1393 x.printStackTrace();
1401 sfile = new URI(groovyscript).toURL();
1402 } catch (Exception x)
1404 tfile = new File(groovyscript);
1405 if (!tfile.exists())
1407 System.err.println("File '" + groovyscript + "' does not exist.");
1410 if (!tfile.canRead())
1412 System.err.println("File '" + groovyscript + "' cannot be read.");
1415 if (tfile.length() < 1)
1417 System.err.println("File '" + groovyscript + "' is empty.");
1422 sfile = tfile.getAbsoluteFile().toURI().toURL();
1423 } catch (Exception ex)
1425 System.err.println("Failed to create a file URL for "
1426 + tfile.getAbsoluteFile());
1433 Map<String, java.lang.Object> vbinding = new HashMap<>();
1434 vbinding.put("Jalview", this);
1437 vbinding.put("currentAlFrame", af);
1439 Binding gbinding = new Binding(vbinding);
1440 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1441 gse.run(sfile.toString(), gbinding);
1442 if ("STDIN".equals(groovyscript))
1444 // delete temp file that we made -
1445 // only if it was successfully executed
1448 } catch (Exception e)
1450 System.err.println("Exception Whilst trying to execute file " + sfile
1451 + " as a groovy script.");
1452 e.printStackTrace(System.err);
1457 public static boolean isHeadlessMode()
1459 String isheadless = System.getProperty("java.awt.headless");
1460 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1467 public AlignFrame[] getAlignFrames()
1469 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1470 : Desktop.getAlignFrames();
1475 * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
1479 // System.exit will run the shutdownHook first
1483 public static AlignFrame getCurrentAlignFrame()
1485 return Jalview.currentAlignFrame;
1488 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1490 Jalview.currentAlignFrame = currentAlignFrame;