1 35 36 39 package demo.swingset; 40 41 import swingwtx.swing.*; 42 import swingwtx.swing.event.*; 43 import swingwtx.swing.text.*; 44 import swingwtx.swing.border.*; 46 import swingwtx.swing.colorchooser.*; 47 import swingwtx.swing.filechooser.*; 48 import javax.accessibility.*; 49 50 import swingwt.awt.*; 51 import swingwt.awt.event.*; 52 import java.beans.*; 53 import java.util.*; 54 import java.io.*; 55 import java.applet.*; 56 import java.net.*; 57 58 64 public class HtmlDemo extends DemoModule { 65 66 JEditorPane html; 67 68 71 public static void main(String [] args) { 72 HtmlDemo demo = new HtmlDemo(null); 73 demo.mainImpl(); 74 } 75 76 79 public HtmlDemo(SwingSet2 swingset) { 80 super(swingset, "HtmlDemo", "toolbar/JEditorPane.gif"); 83 84 try { 85 URL url = null; 86 String path = null; 89 try { 90 99 File file = new File(""); 100 String link = file.getAbsolutePath(); 101 System.out.println("Working with: " + link); 102 103 if (link.endsWith(File.separator)) 106 link = link.substring(0, link.length() - 1); 107 108 link = link.substring(0, link.lastIndexOf(File.separator)); 110 111 link += File.separator + "demo" + File.separator + "swingset" + 113 File.separator + "htmldemo" + File.separator + "index.html"; 114 String surl = "file://" + link; 115 System.out.println("Using: " + surl); 116 url = new URL(surl); 117 118 } catch (Exception e) { 119 e.printStackTrace(); 120 System.err.println("Failed to open " + path); 121 url = null; 122 } 123 124 if(url != null) { 125 html = new JEditorPane(url); 126 html.setEditable(false); 127 html.addHyperlinkListener(createHyperLinkListener()); 128 129 JScrollPane scroller = new JScrollPane(); 130 JViewport vp = scroller.getViewport(); 131 vp.add(html); 132 getDemoPanel().add(scroller, BorderLayout.CENTER); 133 } 134 } catch (MalformedURLException e) { 135 System.out.println("Malformed URL: " + e); 136 } catch (IOException e) { 137 System.out.println("IOException: " + e); 138 } 139 } 140 141 public HyperlinkListener createHyperLinkListener() { 142 return new HyperlinkListener() { 143 public void hyperlinkUpdate(HyperlinkEvent e) { 144 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 145 try { 146 html.setPage(e.getURL()); 147 } catch (IOException ioe) { 148 System.out.println("IOE: " + ioe); 149 } 150 } 151 } 152 }; 153 } 154 155 } 156 | Popular Tags |