FileDocCategorySizeDatePackage
SimpleHelp.javaAPI DocExample3694Fri May 30 09:16:08 BST 2003com.darwinsys.swingui

SimpleHelp

public class SimpleHelp extends JFrame implements HyperlinkListener
Simple Help Frame based on JFC JEditorPane.

May someday rewrite using JavaHelp API.

version
$Id: SimpleHelp.java,v 1.10 2003/05/30 13:16:07 ian Exp $

Fields Summary
protected Container
cp
The contentpane
JEditorPane
help
The editorpane
Constructors Summary
public SimpleHelp(String windowName, String helpIndexFileName)

		super(windowName + " Help Window");
		cp = getContentPane();
		getAccessibleContext().setAccessibleName(windowName + " Help Window");
		getAccessibleContext().setAccessibleDescription(
			"A window for viewing the help for " + windowName +
			", which is somewhat hyperlinked.");
	
		try {
			URL url = new File(helpIndexFileName).toURL();
			// Only create the window once.
			if (help == null) {
				// System.out.println("Creat-ing help window for " + url);
				help = new JEditorPane(url);
				// System.out.println("Done!");
				help.setEditable(false);
				help.addHyperlinkListener(this);
				JScrollPane scroller = new JScrollPane();
				scroller.setBorder(BorderFactory.createTitledBorder(windowName + " Help"));
				scroller.getViewport().add(help);
				cp.add(BorderLayout.CENTER, scroller);
				addWindowListener(new WindowAdapter() {
					public void windowClosing(WindowEvent e) {
						SimpleHelp.this.setVisible(false);
						SimpleHelp.this.dispose();
					}
				});
				setSize(500,400);
			} else {
				System.out.println("Re-using help window!");
			}
		} catch (MalformedURLException e) {
			System.out.println("Malformed URL: " + e);
		} catch (IOException e) {
			System.out.println("IOException: " + e);
		}
    
Methods Summary
public voidhyperlinkUpdate(javax.swing.event.HyperlinkEvent e)
Notification of a change relative to a hyperlink. From: java.swing.event.HyperlinkListener

		if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
			URL target = e.getURL();
			// System.out.println("linkto: " + target);

			// Get the help panel's cursor and the wait cursor
			Cursor oldCursor = help.getCursor();
			Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
			help.setCursor(waitCursor);

			// Now arrange for the page to get loaded asynchronously,
			// and the cursor to be set back to what it was.
			SwingUtilities.invokeLater(new PageLoader(target, oldCursor));
		}