X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FHelp.java;h=83fcaf708ebd1944e9718d1f18ca0a3929451748;hb=5d4b4eb70fb510e1720259328bfc7ac201373c5e;hp=f2d81139d3f5cf878af872939d31ff0b6411cee2;hpb=37de9310bec3501cbc6381e0c3dcb282fcaad812;p=jalview.git diff --git a/src/jalview/gui/Help.java b/src/jalview/gui/Help.java index f2d8113..83fcaf7 100644 --- a/src/jalview/gui/Help.java +++ b/src/jalview/gui/Help.java @@ -20,6 +20,11 @@ */ package jalview.gui; +import jalview.util.BrowserLauncher; +import jalview.util.Platform; + +import java.awt.Point; +import java.io.IOException; import java.net.URL; import javax.help.BadIDException; @@ -28,35 +33,47 @@ import javax.help.HelpSet; import javax.help.HelpSetException; /** - * Utility class to show the help documentation window. + * Utility class to show the help documentation window * * @author gmcarstairs - * */ public class Help { + private static final String HELP_PAGE_ROOT = "http://www.jalview.org/help/"; + + /** + * Defines selected help targets with links to inbuilt (Java) help page target, + * and externally hosted help page. Will need to be maintained manually if help + * pages are reorganised in future. + */ public enum HelpId { - Home("home"), SequenceFeatureSettings("seqfeatures.settings"), - StructureViewer("viewingpdbs"); + Home("home", "help.html"), SequenceFeatureSettings("seqfeatures.settings", "html/features/featuresettings.html"), + StructureViewer("viewingpdbs", "html/features/viewingpdbs.html"), PdbFts("pdbfts", "html/features/pdbsequencefetcher.html#pdbfts"), + UniprotFts("uniprotfts", "html/features/uniprotsequencefetcher.html#uniprotfts"); private String id; + + private String path; - private HelpId(String loc) + private HelpId(String hepLoc, String htmlPath) { - this.id = loc; + this.id = hepLoc; + this.path = htmlPath; } - @Override - public String toString() + String getId() { return this.id; } - } - private static final long HALF_A_MO = 500; // half a second + String getPath() + { + return this.path; + } + } - private static long lastOpenedTime = 0L; + private static HelpBroker hb; /** * Not instantiable @@ -67,42 +84,59 @@ public class 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. + * Shows the help window, at the entry specified by the given helpId * * @param id - * TODO * * @throws HelpSetException */ public static void showHelpWindow(HelpId id) throws HelpSetException { - long timeNow = System.currentTimeMillis(); + if (Platform.isJS()) + { + try + { + BrowserLauncher.openURL(HELP_PAGE_ROOT + id.getPath()); + } catch (IOException e) {} + return; + } + + ClassLoader cl = Desktop.class.getClassLoader(); + URL url = HelpSet.findHelpSet(cl, "help/help"); // $NON-NLS-$ + HelpSet hs = new HelpSet(cl, url); - if (timeNow - lastOpenedTime > HALF_A_MO) + if (hb == null) { - 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(); - try - { - hb.setCurrentID(id.toString()); - } catch (BadIDException bad) - { - System.out.println("Bad help link: " + id.toString() - + ": must match a target in help.jhm"); - throw bad; - } - hb.setDisplayed(true); + /* + * create help broker first time (only) + */ + hb = hs.createHelpBroker(); } + + try + { + hb.setCurrentID(id.getId()); + } catch (BadIDException bad) + { + System.out.println("Bad help link: " + id.getId() + + ": must match a target in help.jhm"); + throw bad; + } + + /* + * set Help visible - at its current location if it is already shown, + * else at a location as determined by the window manager + */ + Point p = hb.getLocation(); + hb.setLocation(p); + hb.setDisplayed(true); } + /** + * Show the Help window at the root entry + * + * @throws HelpSetException + */ public static void showHelpWindow() throws HelpSetException { showHelpWindow(HelpId.Home);