/* * Copyright(c)1998 Forward Computing and Control Pty. Ltd. * ACN 003 669 994, NSW, Australia All rights Reserved * * Written by Dr. M.P. Ford */ import java.awt.Component; import java.awt.MenuItem; import java.net.URL; import javax.help.CSH; import javax.help.DefaultHelpBroker; import javax.help.HelpBroker; import javax.help.HelpSet; import javax.help.HelpSetException; import javax.help.Map; /** * This class provides user help facility using JavaHelp API. * *@author Matthew Ford *@created 13 October 2002 */ public class ApplicationHelp { //~ Static variables/initializers ............................................ /** the application help set, null if not found */ private static HelpSet helpSet = null; /** the helpBroker, null if not set */ private static HelpBroker helpBroker = null; /** the name of the help set */ private static final String HS_NAME = "au/com/forward/parallel/help/Parallel.hs"; /** the help map, if this is null then there was an error initializing the help set */ private static Map map = null; /** the default topic ID, if no help available for a topic */ private static final String DEFAULT_ID = "no_help_available"; /** * try and load the help set on startup */ static { URL url = null; try { // load the help set from the same path as the main class. url = HelpSet.findHelpSet( au.com.forward.parallel.Parallel.class.getClassLoader(), HS_NAME); if (url != null) { try { helpSet = new HelpSet(null, url); helpBroker = helpSet.createHelpBroker(); map = helpSet.getCombinedMap(); } catch (HelpSetException e) { // log an error here and continue, don't stop the application LogStdStreams.getLogStream().println("Cannot create HelpSet for " + HS_NAME + "\n"+ StringUtils.toString(e)); } } else { // log an error here and continue, don't stop the application LogStdStreams.getLogStream().println("Cannot create HelpSet for " + HS_NAME); } } catch (Exception ee) { // log an error here and continue, don't stop the application LogStdStreams.getLogStream().println("Unexpected exception occurred.\n" + StringUtils.toString(ee)); } } /** * Private constructor ensures nobody can create an instance. */ private ApplicationHelp() { } /** * Is help available for this application * *@return The Available value */ public static boolean isAvailable() { return (map != null); } /** * Show help for this topicID * This method does not throw any exceptions * *@param id help topicID */ public static void showHelp(String id) { try { if (map == null) { // no help set available return; } String mapID = DEFAULT_ID; // set default no_help_available if (map.isValidID(id, helpSet)) { mapID = id; // ok found topic } else { String msg = "Help Id:'" + id + "' not found."; RuntimeException pex = new RuntimeException(msg); // don't throw it just log it with its stacktrace LogStdStreams.getLogStream().println(msg + "\n" + StringUtils.toString(pex)); } try { helpBroker.setDisplayed(true); // display Java help first helpBroker.setCurrentID(mapID); // then switch to this topic } catch (Exception e) { // log an error here and continue, don't stop the application LogStdStreams.getLogStream().println("Error setting help context\n" + StringUtils.toString(e)); } } catch (Throwable t) { // log an error here and continue, don't stop the application LogStdStreams.getLogStream().println("Unexpected exception occurred.\n" + StringUtils.toString(ee)); } } }