dac17c02afc50a42b9b6fe2305be7a09124cf35b
[jalview.git] / src / jalview / gui / Help.java
1 package jalview.gui;
2
3 import java.net.URL;
4
5 import javax.help.HelpBroker;
6 import javax.help.HelpSet;
7 import javax.help.HelpSetException;
8
9 /**
10  * Utility class to show the help documentation window.
11  * 
12  * @author gmcarstairs
13  *
14  */
15 public class Help
16 {
17
18   private static final long HALF_A_MO = 500; // half a second
19
20   private static long lastOpenedTime = 0L;
21
22   /**
23    * Not instantiable
24    */
25   private Help()
26   {
27
28   }
29
30   /**
31    * Show help text in a new window. But do nothing if within half a second of
32    * the last invocation.
33    * 
34    * This is a workaround for issue JAL-914 - both Desktop and AlignFrame
35    * responding to F1 key, resulting in duplicate help windows opened.
36    * 
37    * @throws HelpSetException
38    */
39   public static void showHelpWindow() throws HelpSetException
40   {
41     long timeNow = System.currentTimeMillis();
42
43     if (timeNow - lastOpenedTime > HALF_A_MO)
44     {
45       lastOpenedTime = timeNow;
46       ClassLoader cl = Desktop.class.getClassLoader();
47       URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$
48       HelpSet hs = new HelpSet(cl, url);
49
50       HelpBroker hb = hs.createHelpBroker();
51       hb.setCurrentID("home");
52       hb.setDisplayed(true);
53     }
54   }
55 }