Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File Help.java

 

Coverage histogram

../../img/srcFileCovDistChart2.png
51% of files have more coverage

Code metrics

2
15
5
2
110
55
7
0.47
3
2.5
1.4

Classes

Class Line # Actions
Help 36 13 5 18
0.00%
Help.HelpId 38 2 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import java.net.URL;
24   
25    import javax.help.BadIDException;
26    import javax.help.HelpBroker;
27    import javax.help.HelpSet;
28    import javax.help.HelpSetException;
29   
30    /**
31    * Utility class to show the help documentation window.
32    *
33    * @author gmcarstairs
34    *
35    */
 
36    public class Help
37    {
 
38    public enum HelpId
39    {
40    Home("home"), SequenceFeatureSettings("seqfeatures.settings"),
41    StructureViewer("viewingpdbs");
42   
43    private String id;
44   
 
45  3 toggle private HelpId(String loc)
46    {
47  3 this.id = loc;
48    }
49   
 
50  3 toggle @Override
51    public String toString()
52    {
53  3 return this.id;
54    }
55    }
56   
57    private static final long HALF_A_MO = 500; // half a second
58   
59    private static long lastOpenedTime = 0L;
60   
61    /**
62    * Not instantiable
63    */
 
64  0 toggle private Help()
65    {
66   
67    }
68   
69    /**
70    * Show help text in a new window. But do nothing if within half a second of
71    * the last invocation.
72    *
73    * This is a workaround for issue JAL-914 - both Desktop and AlignFrame
74    * responding to F1 key, resulting in duplicate help windows opened.
75    *
76    * @param id
77    * TODO
78    *
79    * @throws HelpSetException
80    */
 
81  0 toggle public static void showHelpWindow(HelpId id) throws HelpSetException
82    {
83  0 long timeNow = System.currentTimeMillis();
84   
85  0 if (timeNow - lastOpenedTime > HALF_A_MO)
86    {
87  0 lastOpenedTime = timeNow;
88  0 ClassLoader cl = Desktop.class.getClassLoader();
89  0 URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$
90  0 HelpSet hs = new HelpSet(cl, url);
91   
92  0 HelpBroker hb = hs.createHelpBroker();
93  0 try
94    {
95  0 hb.setCurrentID(id.toString());
96    } catch (BadIDException bad)
97    {
98  0 System.out.println("Bad help link: " + id.toString()
99    + ": must match a target in help.jhm");
100  0 throw bad;
101    }
102  0 hb.setDisplayed(true);
103    }
104    }
105   
 
106  0 toggle public static void showHelpWindow() throws HelpSetException
107    {
108  0 showHelpWindow(HelpId.Home);
109    }
110    }