1 36 37 40 41 import javax.swing.*; 42 import java.awt.*; 43 import java.net.URL ; 44 import java.net.MalformedURLException ; 45 import java.io.*; 46 import javax.swing.text.*; 47 import javax.swing.event.*; 48 49 53 public class MetalworksHelp extends JInternalFrame { 54 55 public MetalworksHelp() { 56 super("Help", true, true, true, true); 57 58 setFrameIcon( (Icon)UIManager.get("Tree.openIcon")); setBounds( 200, 25, 400, 400); 60 HtmlPane html = new HtmlPane(); 61 setContentPane(html); 62 } 63 64 } 65 66 67 class HtmlPane extends JScrollPane implements HyperlinkListener { 68 JEditorPane html; 69 70 public HtmlPane() { 71 try { 72 URL url = getClass().getResource("/resources/HelpFiles/toc.html"); 73 html = new JEditorPane(url); 74 html.setEditable(false); 75 html.addHyperlinkListener(this); 76 html.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, 77 Boolean.TRUE); 78 JViewport vp = getViewport(); 79 vp.add(html); 80 } catch (MalformedURLException e) { 81 System.out.println("Malformed URL: " + e); 82 } catch (IOException e) { 83 System.out.println("IOException: " + e); 84 } 85 } 86 87 91 public void hyperlinkUpdate(HyperlinkEvent e) { 92 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 93 linkActivated(e.getURL()); 94 } 95 } 96 97 109 protected void linkActivated(URL u) { 110 Cursor c = html.getCursor(); 111 Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); 112 html.setCursor(waitCursor); 113 SwingUtilities.invokeLater(new PageLoader(u, c)); 114 } 115 116 121 class PageLoader implements Runnable { 122 123 PageLoader(URL u, Cursor c) { 124 url = u; 125 cursor = c; 126 } 127 128 public void run() { 129 if (url == null) { 130 html.setCursor(cursor); 132 133 Container parent = html.getParent(); 136 parent.repaint(); 137 } else { 138 Document doc = html.getDocument(); 139 try { 140 html.setPage(url); 141 } catch (IOException ioe) { 142 html.setDocument(doc); 143 getToolkit().beep(); 144 } finally { 145 url = null; 148 SwingUtilities.invokeLater(this); 149 } 150 } 151 } 152 153 URL url; 154 Cursor cursor; 155 } 156 157 } 158 | Popular Tags |