1 19 20 import java.awt.EventQueue ; 21 import java.awt.event.WindowAdapter ; 22 import java.awt.event.WindowEvent ; 23 import java.io.File ; 24 import java.net.URL ; 25 import javax.help.HelpSet; 26 import javax.help.JHelp; 27 import javax.swing.JFrame ; 28 import org.apache.tools.ant.BuildException; 29 import org.apache.tools.ant.Task; 30 31 33 37 public class Preview extends Task { 38 39 private File custom; 40 public void setCustom(File f) { 41 custom = f; 42 } 43 44 public void execute() throws BuildException { 45 assert custom != null; 46 try { 47 final URL url = custom.toURI().toURL(); 48 final HelpSet hs = new HelpSet(Preview.class.getClassLoader(), url); 49 final JHelp jh = new JHelp(hs); 50 final JFrame [] f = new JFrame [1]; 51 EventQueue.invokeAndWait(new Runnable () { 52 public void run() { 53 try { 54 f[0] = new JFrame (hs.getTitle()); 55 f[0].addWindowListener(new WindowAdapter () { 56 public void windowClosing(WindowEvent e) { 57 f[0].dispose(); 58 synchronized (f) { 59 f.notify(); 60 } 61 } 62 }); 63 f[0].add(jh); 64 f[0].pack(); 65 f[0].setExtendedState(JFrame.MAXIMIZED_BOTH); 66 f[0].setVisible(true); 67 } catch (Exception x) { 68 throw new RuntimeException (x); 69 } 70 } 71 }); 72 synchronized (f) { 73 f.wait(); 74 } 75 } catch (Exception x) { 76 throw new BuildException(x); 77 } 78 } 79 80 } | Popular Tags |