    001    package escjava.gui;
    002    import javax.swing.*;
    003    import javax.swing.text.html.*;
    004    import javax.swing.event.*;
    005
    006    import java.net.*;
    007    import java.util.jar.*;
    008
    009    public class EscHtml extends JFrame {
    010
    011        final JEditorPane editor;
    012        final JScrollPane scroll;
    013        private EscHtml() {
    014            editor = new JEditorPane();
    015            scroll = new JScrollPane(editor);
    016            editor.setContentType("text/html");
    017            editor.setEditable(false);
    018            editor.addHyperlinkListener(new Hyperactive());
    019            getContentPane().add(scroll);
    020        }
    021
    022        /** Launches a non-editable HTML display window. */
    023        public static EscHtml make(String title, String filename, JFrame jf,
    024                                            int x, int y, int w, int h) {
    025            try {
    026                java.net.URL url =
    027                  GUI.class.getClassLoader().getResource(filename);
    028                return new EscHtml(title,url,x,y,w,h);
    029            } catch (Exception e) {
    030                JOptionPane.showMessageDialog(jf,
    031                    "Internal error - Could not find html file " +
    032                    filename + ":" + System.getProperty("line.separator")
    033                    + e);
    034            }
    035            return null;
    036        }
    037
    038        // Displays a local file that might be in the jar file
    039        public EscHtml(String title, java.net.URL url, int x, int y, int w, int h)
    040                                            throws java.io.IOException {
    041            this();
    042            setTitle(title);
    043            editor.setPage(url);
    044            //pack();
    045            if (w != 0) setSize(w,h);
    046            setLocation(x,y);
    047        }
    048
    049        public void showit() {
    050            FrameShower.show(this);
    051        }
    052
    053        static class Hyperactive implements HyperlinkListener {
    054
    055            public void hyperlinkUpdate(HyperlinkEvent e) {
    056                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    057                    JEditorPane pane = (JEditorPane) e.getSource();
    058                    if (e instanceof HTMLFrameHyperlinkEvent) {
    059                        HTMLFrameHyperlinkEvent  evt = (HTMLFrameHyperlinkEvent)e;
    060                        HTMLDocument doc = (HTMLDocument)pane.getDocument();
    061                        doc.processHTMLFrameHyperlinkEvent(evt);
    062                    } else {
    063                        try {
    064                            pane.setPage(e.getURL());
    065                        } catch (Throwable t) {
    066                            t.printStackTrace();
    067                        }
    068                    }
    069                }
    070            }
    071        }
    072    }