From: Ben Soares Date: Mon, 13 Jun 2022 16:22:52 +0000 (+0100) Subject: Merge branch 'develop' into improvement/JAL-1988+JAL-3416_Java8_macOS_APQHandlers_and... X-Git-Tag: Release_2_11_2_6~44^2~3 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=5022579ec6cc4eecfabd9df69e0fb039e3186a0a;hp=135c826c69042c04c64cb8df30fdaef92eeb4ffc Merge branch 'develop' into improvement/JAL-1988+JAL-3416_Java8_macOS_APQHandlers_and_FlatLaF_option --- diff --git a/j11lib/flatlaf-2.3.jar b/j11lib/flatlaf-2.3.jar new file mode 100644 index 0000000..9f292d2 Binary files /dev/null and b/j11lib/flatlaf-2.3.jar differ diff --git a/j11lib/flatlaf-extras-2.3.jar b/j11lib/flatlaf-extras-2.3.jar new file mode 100644 index 0000000..39e9701 Binary files /dev/null and b/j11lib/flatlaf-extras-2.3.jar differ diff --git a/j8lib/flatlaf-2.3.jar b/j8lib/flatlaf-2.3.jar new file mode 100644 index 0000000..9f292d2 Binary files /dev/null and b/j8lib/flatlaf-2.3.jar differ diff --git a/j8lib/flatlaf-extras-2.3.jar b/j8lib/flatlaf-extras-2.3.jar new file mode 100644 index 0000000..39e9701 Binary files /dev/null and b/j8lib/flatlaf-extras-2.3.jar differ diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index fc4c821..fd1783a 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -20,6 +20,7 @@ */ package jalview.bin; +import java.awt.Color; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -44,9 +45,12 @@ import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; +import com.formdev.flatlaf.FlatLightLaf; +import com.formdev.flatlaf.util.SystemInfo; import com.threerings.getdown.util.LaunchUtil; //import edu.stanford.ejalbert.launching.IBrowserLaunching; @@ -862,8 +866,8 @@ public class Jalview private static void setLookAndFeel() { - // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or - // "mac" + // property laf = "crossplatform", "system", "gtk", "metal", "nimbus", + // "mac" or "flat" // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac, // try Quaqua/Vaqua. String lafProp = System.getProperty("laf"); @@ -915,6 +919,13 @@ public class Jalview Console.error("Could not set requested laf=" + laf); } break; + case "flat": + lafSet = setFlatLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; case "quaqua": lafSet = setQuaquaLookAndFeel(); if (!lafSet) @@ -1035,6 +1046,45 @@ public class Jalview "javax.swing.plaf.nimbus.NimbusLookAndFeel", false); } + private static boolean setFlatLookAndFeel() + { + boolean set = setSpecificLookAndFeel("flatlaf light", + "com.formdev.flatlaf.FlatLightLaf", false); + if (set) + { + if (Platform.isMac()) + { + 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) + { + Desktop.desktop.getRootPane() + .putClientProperty("apple.awt.fullWindowContent", true); + Desktop.desktop.getRootPane() + .putClientProperty("apple.awt.transparentTitleBar", true); + } + + SwingUtilities.invokeLater(() -> { + FlatLightLaf.setup(); + }); + } + + UIManager.put("TabbedPane.showTabSeparators", true); + UIManager.put("TabbedPane.tabSeparatorsFullHeight", true); + UIManager.put("TabbedPane.tabsOverlapBorder", true); + // UIManager.put("TabbedPane.hasFullBorder", true); + UIManager.put("TabbedPane.tabLayoutPolicy", "scroll"); + UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded"); + UIManager.put("TabbedPane.smoothScrolling", true); + UIManager.put("TabbedPane.tabWidthMode", "compact"); + UIManager.put("TabbedPane.selectedBackground", Color.white); + } + return set; + } + private static boolean setQuaquaLookAndFeel() { return setSpecificLookAndFeel("quaqua", diff --git a/src/jalview/gui/APQHandlers.java b/src/jalview/gui/APQHandlers.java index e5e328f..3d4c91a 100644 --- a/src/jalview/gui/APQHandlers.java +++ b/src/jalview/gui/APQHandlers.java @@ -20,148 +20,54 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.util.MessageManager; -import jalview.util.Platform; +import javax.swing.JOptionPane; -import java.awt.Desktop; -import java.awt.desktop.AboutEvent; -import java.awt.desktop.AboutHandler; -import java.awt.desktop.PreferencesEvent; -import java.awt.desktop.PreferencesHandler; -import java.awt.desktop.QuitEvent; -import java.awt.desktop.QuitHandler; -import java.awt.desktop.QuitResponse; -import java.awt.desktop.QuitStrategy; +import com.formdev.flatlaf.extras.FlatDesktop; -import javax.swing.JOptionPane; +import jalview.util.MessageManager; public class APQHandlers { private static boolean setAPQHandlers = false; - public APQHandlers() - { - } - protected static boolean setAPQHandlers( jalview.gui.Desktop jalviewDesktop) { - // flagging this test to avoid unnecessary reflection - if (!setAPQHandlers) - { - // see if the Quit, About and Preferences handlers are available - Class desktopClass = Desktop.class; - Desktop hdesktop = Desktop.getDesktop(); - - try + FlatDesktop.setAboutHandler(() -> { + jalviewDesktop.aboutMenuItem_actionPerformed(null); + }); + FlatDesktop.setPreferencesHandler(() -> { + jalviewDesktop.preferences_actionPerformed(null); + }); + FlatDesktop.setQuitHandler(response -> { + boolean confirmQuit = jalview.bin.Cache + .getDefault(jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, true); + boolean canQuit = !confirmQuit; + int n; + if (confirmQuit) { - Float specversion = Float.parseFloat( - System.getProperty("java.specification.version")); - - if (specversion >= 9) - { - if (Platform.isAMacAndNotJS()) - { - if (desktopClass.getDeclaredMethod("setAboutHandler", - new Class[] - { AboutHandler.class }) != null) - { - - hdesktop.setAboutHandler(new AboutHandler() - { - @Override - public void handleAbout(AboutEvent e) - { - jalviewDesktop.aboutMenuItem_actionPerformed(null); - } - }); - - } - - if (desktopClass.getDeclaredMethod("setPreferencesHandler", - new Class[] - { PreferencesHandler.class }) != null) - { - - hdesktop.setPreferencesHandler(new PreferencesHandler() - { - @Override - public void handlePreferences(PreferencesEvent e) - { - jalviewDesktop.preferences_actionPerformed(null); - } - }); - - } - - if (desktopClass.getDeclaredMethod("setQuitHandler", - new Class[] - { QuitHandler.class }) != null) - { - - hdesktop.setQuitHandler(new QuitHandler() - { - @Override - public void handleQuitRequestWith(QuitEvent e, - QuitResponse r) - { - boolean confirmQuit = Cache.getDefault( - jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, true); - int n; - if (confirmQuit) - { - n = JOptionPane.showConfirmDialog(null, - MessageManager.getString("label.quit_jalview"), - MessageManager.getString("action.quit"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.PLAIN_MESSAGE, null); - } - else - { - n = JOptionPane.OK_OPTION; - } - if (n == JOptionPane.OK_OPTION) - { - System.out.println("Shortcut Quit confirmed by user"); - jalviewDesktop.quit(); - r.performQuit(); // probably won't reach this line, but just - // in - // case - } - else - { - r.cancelQuit(); - System.out.println("Shortcut Quit cancelled by user"); - } - } - }); - hdesktop.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS); - - } - } - setAPQHandlers = true; - } - else - { - System.out.println( - "Not going to try setting APQ Handlers as java.spec.version is " - + specversion); - } - - } catch (Exception e) + n = JOptionPane.showConfirmDialog(null, + MessageManager.getString("label.quit_jalview"), + MessageManager.getString("action.quit"), + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, + null); + } + else { - System.out.println( - "Exception when looking for About, Preferences, Quit Handlers"); - // e.printStackTrace(); - } catch (Throwable t) + n = JOptionPane.OK_OPTION; + } + canQuit = (n == JOptionPane.OK_OPTION); + if (canQuit) + { + response.performQuit(); + } + else { - System.out.println( - "Throwable when looking for About, Preferences, Quit Handlers"); - // t.printStackTrace(); + response.cancelQuit(); } + }); - } + setAPQHandlers = true; return setAPQHandlers; }