430N/A/*
2362N/A * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
430N/A *
430N/A * Redistribution and use in source and binary forms, with or without
430N/A * modification, are permitted provided that the following conditions
430N/A * are met:
2362N/A *
430N/A * - Redistributions of source code must retain the above copyright
2362N/A * notice, this list of conditions and the following disclaimer.
430N/A *
430N/A * - Redistributions in binary form must reproduce the above copyright
430N/A * notice, this list of conditions and the following disclaimer in the
430N/A * documentation and/or other materials provided with the distribution.
430N/A *
430N/A * - Neither the name of Oracle nor the names of its
430N/A * contributors may be used to endorse or promote products derived
430N/A * from this software without specific prior written permission.
430N/A *
430N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
430N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2362N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2362N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2362N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
430N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
430N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
430N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
430N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
430N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
430N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
430N/A */
430N/A
430N/A/*
430N/A * This source code is provided to illustrate the usage of a given feature
430N/A * or technique and has been deliberately simplified. Additional steps
430N/A * required for a production-quality application, such as security checks,
430N/A * input validation and proper error handling, might not be present in
430N/A * this sample code.
430N/A */
430N/A
430N/A
430N/A
430N/Aimport javax.swing.*;
430N/Aimport java.awt.*;
430N/Aimport java.net.URL;
430N/Aimport java.net.MalformedURLException;
430N/Aimport java.io.*;
430N/Aimport javax.swing.text.*;
430N/Aimport javax.swing.event.*;
430N/A
430N/A
430N/A/**
430N/A * @author Steve Wilson
430N/A * @author Alexander Kouznetsov
430N/A */
430N/A@SuppressWarnings("serial")
430N/Apublic class MetalworksHelp extends JInternalFrame {
430N/A
430N/A public MetalworksHelp() {
430N/A super("Help", true, true, true, true);
430N/A
430N/A setFrameIcon((Icon) UIManager.get("Tree.openIcon")); // PENDING(steve) need more general place to get this icon
430N/A setBounds(200, 25, 400, 400);
430N/A HtmlPane html = new HtmlPane();
430N/A setContentPane(html);
430N/A }
430N/A}
430N/A
430N/A
430N/A@SuppressWarnings("serial")
430N/Aclass HtmlPane extends JScrollPane implements HyperlinkListener {
430N/A
430N/A JEditorPane html;
430N/A
430N/A @SuppressWarnings("LeakingThisInConstructor")
430N/A public HtmlPane() {
430N/A try {
430N/A URL url = getClass().getResource("/resources/HelpFiles/toc.html");
430N/A html = new JEditorPane(url);
430N/A html.setEditable(false);
430N/A html.addHyperlinkListener(this);
430N/A html.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
430N/A Boolean.TRUE);
430N/A JViewport vp = getViewport();
430N/A vp.add(html);
430N/A } catch (MalformedURLException e) {
430N/A System.out.println("Malformed URL: " + e);
430N/A } catch (IOException e) {
430N/A System.out.println("IOException: " + e);
430N/A }
430N/A }
430N/A
430N/A /**
430N/A * Notification of a change relative to a
430N/A * hyperlink.
430N/A */
430N/A public void hyperlinkUpdate(HyperlinkEvent e) {
430N/A if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
430N/A linkActivated(e.getURL());
430N/A }
430N/A }
430N/A
430N/A /**
430N/A * Follows the reference in an
430N/A * link. The given url is the requested reference.
430N/A * By default this calls <a href="#setPage">setPage</a>,
430N/A * and if an exception is thrown the original previous
430N/A * document is restored and a beep sounded. If an
430N/A * attempt was made to follow a link, but it represented
430N/A * a malformed url, this method will be called with a
430N/A * null argument.
430N/A *
430N/A * @param u the URL to follow
430N/A */
430N/A protected void linkActivated(URL u) {
430N/A Cursor c = html.getCursor();
430N/A Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
430N/A html.setCursor(waitCursor);
430N/A SwingUtilities.invokeLater(new PageLoader(u, c));
430N/A }
430N/A
430N/A
430N/A /**
430N/A * temporary class that loads synchronously (although
430N/A * later than the request so that a cursor change
430N/A * can be done).
430N/A */
430N/A class PageLoader implements Runnable {
430N/A
430N/A PageLoader(URL u, Cursor c) {
430N/A url = u;
430N/A cursor = c;
430N/A }
430N/A
430N/A public void run() {
430N/A if (url == null) {
430N/A // restore the original cursor
430N/A html.setCursor(cursor);
430N/A
430N/A // PENDING(prinz) remove this hack when
430N/A // automatic validation is activated.
430N/A Container parent = html.getParent();
430N/A parent.repaint();
430N/A } else {
430N/A Document doc = html.getDocument();
430N/A try {
430N/A html.setPage(url);
430N/A } catch (IOException ioe) {
430N/A html.setDocument(doc);
430N/A getToolkit().beep();
430N/A } finally {
430N/A // schedule the cursor to revert after
430N/A // the paint has happended.
430N/A url = null;
430N/A SwingUtilities.invokeLater(this);
430N/A }
430N/A }
430N/A }
430N/A URL url;
430N/A Cursor cursor;
430N/A }
430N/A}
430N/A