From 35626511226b6eca47a7610f4682a3c686d64fa2 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 3 Oct 2014 12:00:10 +0100 Subject: [PATCH] JAL-914 don't open help window twice --- src/jalview/gui/Desktop.java | 16 ++++-------- src/jalview/gui/Help.java | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 src/jalview/gui/Help.java diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index b7057d1..eb4f968 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -89,9 +89,9 @@ import javax.swing.JPopupMenu; import javax.swing.JProgressBar; import javax.swing.SwingUtilities; import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkEvent.EventType; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; -import javax.swing.event.HyperlinkEvent.EventType; /** * Jalview Desktop @@ -317,8 +317,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements else { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - setBounds((int) (screenSize.width - 900) / 2, - (int) (screenSize.height - 650) / 2, 900, 650); + setBounds((screenSize.width - 900) / 2, + (screenSize.height - 650) / 2, 900, 650); } jconsole = new Console(this, showjconsole); // add essential build information @@ -1183,13 +1183,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { try { - ClassLoader cl = jalview.gui.Desktop.class.getClassLoader(); - java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help"); - javax.help.HelpSet hs = new javax.help.HelpSet(cl, url); - - javax.help.HelpBroker hb = hs.createHelpBroker(); - hb.setCurrentID("home"); - hb.setDisplayed(true); + Help.showHelpWindow(); } catch (Exception ex) { } @@ -2369,7 +2363,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements "call setProgressBar before registering the progress bar's handler."); } progressBarHandlers.put(new Long(id), handler); - final JPanel progressPanel = (JPanel) progressBars.get(new Long(id)); + final JPanel progressPanel = progressBars.get(new Long(id)); if (handler.canCancel()) { JButton cancel = new JButton( diff --git a/src/jalview/gui/Help.java b/src/jalview/gui/Help.java new file mode 100644 index 0000000..dac17c0 --- /dev/null +++ b/src/jalview/gui/Help.java @@ -0,0 +1,55 @@ +package jalview.gui; + +import java.net.URL; + +import javax.help.HelpBroker; +import javax.help.HelpSet; +import javax.help.HelpSetException; + +/** + * Utility class to show the help documentation window. + * + * @author gmcarstairs + * + */ +public class Help +{ + + private static final long HALF_A_MO = 500; // half a second + + private static long lastOpenedTime = 0L; + + /** + * Not instantiable + */ + private Help() + { + + } + + /** + * Show help text in a new window. But do nothing if within half a second of + * the last invocation. + * + * This is a workaround for issue JAL-914 - both Desktop and AlignFrame + * responding to F1 key, resulting in duplicate help windows opened. + * + * @throws HelpSetException + */ + public static void showHelpWindow() throws HelpSetException + { + long timeNow = System.currentTimeMillis(); + + if (timeNow - lastOpenedTime > HALF_A_MO) + { + lastOpenedTime = timeNow; + ClassLoader cl = Desktop.class.getClassLoader(); + URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$ + HelpSet hs = new HelpSet(cl, url); + + HelpBroker hb = hs.createHelpBroker(); + hb.setCurrentID("home"); + hb.setDisplayed(true); + } + } +} -- 1.7.10.2