From dda7fb15c035fe454eae0fe85c29c0df922ec271 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 13 Jun 2022 18:14:11 +0100 Subject: [PATCH] JAL-1988 Moved APQHandlers to jalview.jbgui and called from jalview.jbgui.GDesktop. Use result to not add About and Preferences to normal menus. --- src/jalview/gui/Desktop.java | 23 ++--------------- src/jalview/{gui => jbgui}/APQHandlers.java | 12 ++++----- src/jalview/jbgui/GDesktop.java | 37 ++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 34 deletions(-) rename src/jalview/{gui => jbgui}/APQHandlers.java (87%) diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index aeb0fac..3ad5384 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -20,8 +20,6 @@ */ package jalview.gui; -import java.util.Locale; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -64,6 +62,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.ListIterator; +import java.util.Locale; import java.util.Vector; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -183,7 +182,7 @@ public class Desktop extends jalview.jbgui.GDesktop private static final String EXPERIMENTAL_FEATURES = "EXPERIMENTAL_FEATURES"; - protected static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT"; + public static final String CONFIRM_KEYBOARD_QUIT = "CONFIRM_KEYBOARD_QUIT"; public static HashMap savingFiles = new HashMap(); @@ -444,24 +443,6 @@ public class Desktop extends jalview.jbgui.GDesktop } } - /** - * APQHandlers sets handlers for About, Preferences and Quit actions - * peculiar to macOS's application menu. APQHandlers will check to see if a - * handler is supported before setting it. - */ - try - { - APQHandlers.setAPQHandlers(this); - } catch (Exception e) - { - System.out.println("Cannot set APQHandlers"); - // e.printStackTrace(); - } catch (Throwable t) - { - jalview.bin.Console - .warn("Error setting APQHandlers: " + t.toString()); - jalview.bin.Console.trace(Cache.getStackTraceString(t)); - } setIconImages(ChannelProperties.getIconList()); addWindowListener(new WindowAdapter() diff --git a/src/jalview/gui/APQHandlers.java b/src/jalview/jbgui/APQHandlers.java similarity index 87% rename from src/jalview/gui/APQHandlers.java rename to src/jalview/jbgui/APQHandlers.java index 3d4c91a..27c53b9 100644 --- a/src/jalview/gui/APQHandlers.java +++ b/src/jalview/jbgui/APQHandlers.java @@ -18,26 +18,26 @@ * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ -package jalview.gui; +package jalview.jbgui; import javax.swing.JOptionPane; import com.formdev.flatlaf.extras.FlatDesktop; +import jalview.gui.Desktop; import jalview.util.MessageManager; public class APQHandlers { - private static boolean setAPQHandlers = false; + protected static boolean setAPQHandlers = false; - protected static boolean setAPQHandlers( - jalview.gui.Desktop jalviewDesktop) + public static boolean setAPQHandlers(GDesktop desktop) { FlatDesktop.setAboutHandler(() -> { - jalviewDesktop.aboutMenuItem_actionPerformed(null); + desktop.aboutMenuItem_actionPerformed(null); }); FlatDesktop.setPreferencesHandler(() -> { - jalviewDesktop.preferences_actionPerformed(null); + desktop.preferences_actionPerformed(null); }); FlatDesktop.setQuitHandler(response -> { boolean confirmQuit = jalview.bin.Cache diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index e1224c2..f3d9a65 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -20,11 +20,6 @@ */ package jalview.jbgui; -import jalview.api.AlignmentViewPanel; -import jalview.io.FileFormatException; -import jalview.util.MessageManager; -import jalview.util.Platform; - import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -35,6 +30,12 @@ import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; +import jalview.io.FileFormatException; +import jalview.util.MessageManager; +import jalview.util.Platform; + /** * DOCUMENT ME! * @@ -139,6 +140,25 @@ public class GDesktop extends JFrame */ private void jbInit() throws Exception { + /** + * APQHandlers sets handlers for About, Preferences and Quit actions + * peculiar to macOS's application menu. APQHandlers will check to see if a + * handler is supported before setting it. + */ + try + { + APQHandlers.setAPQHandlers(this); + } catch (Exception e) + { + System.out.println("Cannot set APQHandlers"); + // e.printStackTrace(); + } catch (Throwable t) + { + jalview.bin.Console + .warn("Error setting APQHandlers: " + t.toString()); + jalview.bin.Console.trace(Cache.getStackTraceString(t)); + } + setName("jalview-desktop"); FileMenu.setText(MessageManager.getString("action.file")); HelpMenu.setText(MessageManager.getString("action.help")); @@ -385,9 +405,12 @@ public class GDesktop extends JFrame FileMenu.add(loadState); FileMenu.addSeparator(); FileMenu.add(quit); - HelpMenu.add(aboutMenuItem); + if (!APQHandlers.setAPQHandlers) + { + HelpMenu.add(aboutMenuItem); + } HelpMenu.add(documentationMenuItem); - if (!Platform.isAMacAndNotJS() || specversion < 11) + if (!APQHandlers.setAPQHandlers) { toolsMenu.add(preferences); } -- 1.7.10.2