|
1 /* |
|
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.doclets.formats.html; |
|
27 |
|
28 import com.sun.tools.doclets.internal.toolkit.util.*; |
|
29 import com.sun.javadoc.*; |
|
30 import java.io.*; |
|
31 /** |
|
32 * Generate Class Hierarchy page for all the Classes in this run. Use |
|
33 * ClassTree for building the Tree. The name of |
|
34 * the generated file is "overview-tree.html" and it is generated in the |
|
35 * current or the destination directory. |
|
36 * |
|
37 * @author Atul M Dambalkar |
|
38 */ |
|
39 public class TreeWriter extends AbstractTreeWriter { |
|
40 |
|
41 /** |
|
42 * Packages in this run. |
|
43 */ |
|
44 private PackageDoc[] packages; |
|
45 |
|
46 /** |
|
47 * True if there are no packages specified on the command line, |
|
48 * False otherwise. |
|
49 */ |
|
50 private boolean classesonly; |
|
51 |
|
52 /** |
|
53 * Constructor to construct TreeWriter object. |
|
54 * |
|
55 * @param configuration the current configuration of the doclet. |
|
56 * @param filename String filename |
|
57 * @param classtree the tree being built. |
|
58 */ |
|
59 public TreeWriter(ConfigurationImpl configuration, |
|
60 String filename, ClassTree classtree) |
|
61 throws IOException { |
|
62 super(configuration, filename, classtree); |
|
63 packages = configuration.packages; |
|
64 classesonly = packages.length == 0; |
|
65 } |
|
66 |
|
67 /** |
|
68 * Create a TreeWriter object and use it to generate the |
|
69 * "overview-tree.html" file. |
|
70 * |
|
71 * @param classtree the class tree being documented. |
|
72 * @throws DocletAbortException |
|
73 */ |
|
74 public static void generate(ConfigurationImpl configuration, |
|
75 ClassTree classtree) { |
|
76 TreeWriter treegen; |
|
77 String filename = "overview-tree.html"; |
|
78 try { |
|
79 treegen = new TreeWriter(configuration, filename, classtree); |
|
80 treegen.generateTreeFile(); |
|
81 treegen.close(); |
|
82 } catch (IOException exc) { |
|
83 configuration.standardmessage.error( |
|
84 "doclet.exception_encountered", |
|
85 exc.toString(), filename); |
|
86 throw new DocletAbortException(); |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 * Print the interface hierarchy and class hierarchy in the file. |
|
92 */ |
|
93 public void generateTreeFile() throws IOException { |
|
94 printHtmlHeader(configuration.getText("doclet.Window_Class_Hierarchy"), |
|
95 null, true); |
|
96 |
|
97 printTreeHeader(); |
|
98 |
|
99 printPageHeading(); |
|
100 |
|
101 printPackageTreeLinks(); |
|
102 |
|
103 generateTree(classtree.baseclasses(), "doclet.Class_Hierarchy"); |
|
104 generateTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy"); |
|
105 generateTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy"); |
|
106 generateTree(classtree.baseEnums(), "doclet.Enum_Hierarchy"); |
|
107 |
|
108 printTreeFooter(); |
|
109 } |
|
110 |
|
111 /** |
|
112 * Generate the links to all the package tree files. |
|
113 */ |
|
114 protected void printPackageTreeLinks() { |
|
115 //Do nothing if only unnamed package is used |
|
116 if (packages.length == 1 && packages[0].name().length() == 0) { |
|
117 return; |
|
118 } |
|
119 if (!classesonly) { |
|
120 dl(); |
|
121 dt(); |
|
122 boldText("doclet.Package_Hierarchies"); |
|
123 dd(); |
|
124 for (int i = 0; i < packages.length; i++) { |
|
125 if (packages[i].name().length() == 0) { |
|
126 continue; |
|
127 } |
|
128 String filename = pathString(packages[i], "package-tree.html"); |
|
129 printHyperLink(filename, "", packages[i].name()); |
|
130 if (i < packages.length - 1) { |
|
131 print(", "); |
|
132 } |
|
133 } |
|
134 dlEnd(); |
|
135 hr(); |
|
136 } |
|
137 } |
|
138 |
|
139 /** |
|
140 * Print the top text (from the -top option) and |
|
141 * navigation bar at the top of page. |
|
142 */ |
|
143 protected void printTreeHeader() { |
|
144 printTop(); |
|
145 navLinks(true); |
|
146 hr(); |
|
147 } |
|
148 |
|
149 /** |
|
150 * Print the navigation bar and bottom text (from the -bottom option) |
|
151 * at the bottom of page. |
|
152 */ |
|
153 protected void printTreeFooter() { |
|
154 hr(); |
|
155 navLinks(false); |
|
156 printBottom(); |
|
157 printBodyHtmlEnd(); |
|
158 } |
|
159 |
|
160 /** |
|
161 * Print the page title "Hierarchy For All Packages" at the top of the tree |
|
162 * page. |
|
163 */ |
|
164 protected void printPageHeading() { |
|
165 center(); |
|
166 h2(); |
|
167 printText("doclet.Hierarchy_For_All_Packages"); |
|
168 h2End(); |
|
169 centerEnd(); |
|
170 } |
|
171 } |