JAL-1988 Make sensible choices if only the opening file has been opened, and alter...
[jalview.git] / src / jalview / bin / Jalview.java
index 9472fb3..cb078b8 100755 (executable)
@@ -45,6 +45,8 @@ import java.util.logging.ConsoleHandler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.swing.JDialog;
+import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
@@ -52,6 +54,7 @@ import javax.swing.UIManager.LookAndFeelInfo;
 import javax.swing.UnsupportedLookAndFeelException;
 
 import com.formdev.flatlaf.FlatLightLaf;
+import com.formdev.flatlaf.themes.FlatMacLightLaf;
 import com.formdev.flatlaf.util.SystemInfo;
 import com.threerings.getdown.util.LaunchUtil;
 
@@ -877,8 +880,6 @@ public class Jalview
      * @j2sIgnore
      */
     {
-      boolean defaultStartupFile = Cache.getDefault("STARTUP_FILE",
-              null) == null;
       file = Cache.getDefault("STARTUP_FILE",
               Cache.getDefault("www.jalview.org", "https://www.jalview.org")
                       + "/examples/exampleFile_2_7.jvp");
@@ -892,7 +893,6 @@ public class Jalview
         file.replace("2_7.jar", "2_7.jvp");
         // and remove the stale setting
         Cache.removeProperty("STARTUP_FILE");
-        defaultStartupFile = true;
       }
 
       protocol = AppletFormatAdapter.checkProtocol(file);
@@ -914,11 +914,10 @@ public class Jalview
 
       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
               format);
-      if (defaultStartupFile)
-      {
-        Console.debug("Resetting up-to-date flag for startup file");
-        startUpAlframe.getViewport().setSavedUpToDate(true);
-      }
+      // don't ask to save when quitting if only the startup file has been
+      // opened
+      Console.debug("Resetting up-to-date flag for startup file");
+      startUpAlframe.getViewport().setSavedUpToDate(true);
       // extract groovy arguments before anything else.
     }
 
@@ -1010,20 +1009,6 @@ public class Jalview
         Console.error("Could not set requested laf=" + laf);
       }
       break;
-    case "quaqua":
-      lafSet = setQuaquaLookAndFeel();
-      if (!lafSet)
-      {
-        Console.error("Could not set requested laf=" + laf);
-      }
-      break;
-    case "vaqua":
-      lafSet = setVaquaLookAndFeel();
-      if (!lafSet)
-      {
-        Console.error("Could not set requested laf=" + laf);
-      }
-      break;
     case "mac":
       lafSet = setMacLookAndFeel();
       if (!lafSet)
@@ -1133,19 +1118,39 @@ public class Jalview
   private static boolean setFlatLookAndFeel()
   {
     boolean set = false;
-    if (Platform.isMac())
+    if (SystemInfo.isMacOS)
     {
       try
       {
         UIManager.setLookAndFeel(
                 "com.formdev.flatlaf.themes.FlatMacLightLaf");
         set = true;
-        Console.debug("*** Loaded FlatMacLightLaf");
+        Console.debug("Using FlatMacLightLaf");
       } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException e)
       {
-        Console.debug("Exception loading FlatMacLightLaf", e);
+        Console.debug("Exception loading FlatLightLaf", e);
       }
+      System.setProperty("apple.laf.useScreenMenuBar", "true");
+      System.setProperty("apple.awt.application.name",
+              ChannelProperties.getProperty("app_name"));
+      System.setProperty("apple.awt.application.appearance", "system");
+      if (SystemInfo.isMacFullWindowContentSupported
+              && Desktop.desktop != null)
+      {
+        Console.debug("Setting transparent title bar");
+        Desktop.desktop.getRootPane()
+                .putClientProperty("apple.awt.fullWindowContent", true);
+        Desktop.desktop.getRootPane()
+                .putClientProperty("apple.awt.transparentTitleBar", true);
+        Desktop.desktop.getRootPane()
+                .putClientProperty("apple.awt.fullscreenable", true);
+      }
+      SwingUtilities.invokeLater(() -> {
+        FlatMacLightLaf.setup();
+      });
+      Console.debug("Using FlatMacLightLaf");
+      set = true;
     }
     if (!set)
     {
@@ -1153,40 +1158,63 @@ public class Jalview
       {
         UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
         set = true;
-        Console.debug("*** Loaded FlatLightLaf");
+        Console.debug("Using FlatLightLaf");
       } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException e)
       {
         Console.debug("Exception loading FlatLightLaf", e);
       }
+      // Windows specific properties here
+      SwingUtilities.invokeLater(() -> {
+        FlatLightLaf.setup();
+      });
+      Console.debug("Using FlatLightLaf");
+      set = true;
     }
-    if (set)
+    else if (SystemInfo.isLinux)
     {
-      if (Platform.isMac())
+      try
       {
-        System.setProperty("apple.laf.useScreenMenuBar", "true");
-        System.setProperty("apple.awt.application.name",
-                ChannelProperties.getProperty("app_name"));
-        System.setProperty("apple.awt.application.appearance", "system");
-        if (SystemInfo.isMacFullWindowContentSupported
-                && Desktop.desktop != null)
-        {
-          Console.debug("Setting transparent title bar");
-          Desktop.desktop.getRootPane()
-                  .putClientProperty("apple.awt.fullWindowContent", true);
-          Desktop.desktop.getRootPane()
-                  .putClientProperty("apple.awt.transparentTitleBar", true);
-        }
+        UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
+        set = true;
+        Console.debug("Using FlatLightLaf");
+      } catch (ClassNotFoundException | InstantiationException
+              | IllegalAccessException | UnsupportedLookAndFeelException e)
+      {
+        Console.debug("Exception loading FlatLightLaf", e);
+      }
+      // enable custom window decorations
+      JFrame.setDefaultLookAndFeelDecorated(true);
+      JDialog.setDefaultLookAndFeelDecorated(true);
+      SwingUtilities.invokeLater(() -> {
+        FlatLightLaf.setup();
+      });
+      Console.debug("Using FlatLightLaf");
+      set = true;
+    }
 
-        SwingUtilities.invokeLater(() -> {
-          FlatLightLaf.setup();
-        });
+    if (!set)
+    {
+      try
+      {
+        UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
+        set = true;
+        Console.debug("Using FlatLightLaf");
+      } catch (ClassNotFoundException | InstantiationException
+              | IllegalAccessException | UnsupportedLookAndFeelException e)
+      {
+        Console.debug("Exception loading FlatLightLaf", e);
       }
+    }
 
+    if (set)
+    {
+      UIManager.put("TabbedPane.tabType", "card");
       UIManager.put("TabbedPane.showTabSeparators", true);
+      UIManager.put("TabbedPane.showContentSeparator", true);
       UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
       UIManager.put("TabbedPane.tabsOverlapBorder", true);
-      // UIManager.put("TabbedPane.hasFullBorder", true);
+      UIManager.put("TabbedPane.hasFullBorder", true);
       UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
       UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
       UIManager.put("TabbedPane.smoothScrolling", true);
@@ -1198,20 +1226,6 @@ public class Jalview
     return set;
   }
 
-  private static boolean setQuaquaLookAndFeel()
-  {
-    return setSpecificLookAndFeel("quaqua",
-            ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
-                    .getName(),
-            false);
-  }
-
-  private static boolean setVaquaLookAndFeel()
-  {
-    return setSpecificLookAndFeel("vaqua",
-            "org.violetlib.aqua.AquaLookAndFeel", false);
-  }
-
   private static boolean setMacLookAndFeel()
   {
     boolean set = false;