package jalview.gui; import java.net.URL; import javax.help.BadIDException; 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 { public enum HelpId { Home("home"), SequenceFeatureSettings("seqfeatures.settings"), StructureViewer( "viewingpdbs"); private String id; private HelpId(String loc) { this.id = loc; } @Override public String toString() { return this.id; } } 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. * @param id TODO * * @throws HelpSetException */ public static void showHelpWindow(HelpId id) 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(); 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); } } public static void showHelpWindow() throws HelpSetException { showHelpWindow(HelpId.Home); } }