KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Preview


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 import java.awt.EventQueue JavaDoc;
21 import java.awt.event.WindowAdapter JavaDoc;
22 import java.awt.event.WindowEvent JavaDoc;
23 import java.io.File JavaDoc;
24 import java.net.URL JavaDoc;
25 import javax.help.HelpSet;
26 import javax.help.JHelp;
27 import javax.swing.JFrame JavaDoc;
28 import org.apache.tools.ant.BuildException;
29 import org.apache.tools.ant.Task;
30
31 // XXX does not work inside NB, why?
32

33 /**
34  * Previews the manual.
35  * @author Jesse Glick
36  */

37 public class Preview extends Task {
38
39     private File JavaDoc custom;
40     public void setCustom(File JavaDoc f) {
41         custom = f;
42     }
43
44     public void execute() throws BuildException {
45         assert custom != null;
46         try {
47             final URL JavaDoc url = custom.toURI().toURL();
48             final HelpSet hs = new HelpSet(Preview.class.getClassLoader(), url);
49             final JHelp jh = new JHelp(hs);
50             final JFrame JavaDoc[] f = new JFrame JavaDoc[1];
51             EventQueue.invokeAndWait(new Runnable JavaDoc() {
52                 public void run() {
53                     try {
54                         f[0] = new JFrame JavaDoc(hs.getTitle());
55                         f[0].addWindowListener(new WindowAdapter JavaDoc() {
56                             public void windowClosing(WindowEvent JavaDoc 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 JavaDoc x) {
68                         throw new RuntimeException JavaDoc(x);
69                     }
70                 }
71             });
72             synchronized (f) {
73                 f.wait();
74             }
75         } catch (Exception JavaDoc x) {
76             throw new BuildException(x);
77         }
78     }
79
80 }
Popular Tags