001: /*
002: * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.formats.html;
027:
028: import com.sun.tools.doclets.internal.toolkit.util.*;
029:
030: import com.sun.javadoc.*;
031: import java.io.*;
032: import java.util.*;
033:
034: /**
035: * Abstract class to print the class hierarchy page for all the Classes. This
036: * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
037: * generate the Package Tree and global Tree(for all the classes and packages)
038: * pages.
039: *
040: * @author Atul M Dambalkar
041: */
042: public abstract class AbstractTreeWriter extends HtmlDocletWriter {
043:
044: /**
045: * The class and interface tree built by using {@link ClassTree}
046: */
047: protected final ClassTree classtree;
048:
049: /**
050: * Constructor initilises classtree variable. This constructor will be used
051: * while generating global tree file "overview-tree.html".
052: *
053: * @param filename File to be generated.
054: * @param classtree Tree built by {@link ClassTree}.
055: * @throws IOException
056: * @throws DocletAbortException
057: */
058: protected AbstractTreeWriter(ConfigurationImpl configuration,
059: String filename, ClassTree classtree) throws IOException {
060: super (configuration, filename);
061: this .classtree = classtree;
062: }
063:
064: /**
065: * Create appropriate directory for the package and also initilise the
066: * relative path from this generated file to the current or
067: * the destination directory. This constructor will be used while
068: * generating "package tree" file.
069: *
070: * @param path Directories in this path will be created if they are not
071: * already there.
072: * @param filename Name of the package tree file to be generated.
073: * @param classtree The tree built using {@link ClassTree}.
074: * for the package pkg.
075: * @param pkg PackageDoc for which tree file will be generated.
076: * @throws IOException
077: * @throws DocletAbortException
078: */
079: protected AbstractTreeWriter(ConfigurationImpl configuration,
080: String path, String filename, ClassTree classtree,
081: PackageDoc pkg) throws IOException {
082: super (configuration, path, filename, DirectoryManager
083: .getRelativePath(pkg.name()));
084: this .classtree = classtree;
085: }
086:
087: /**
088: * Generate each level of the class tree. For each sub-class or
089: * sub-interface indents the next level information.
090: * Recurses itself to generate subclasses info.
091: * To iterate is human, to recurse is divine - L. Peter Deutsch.
092: *
093: * @param parent the superclass or superinterface of the list.
094: * @param list list of the sub-classes at this level.
095: * @param isEnum true if we are generating a tree for enums.
096: */
097: protected void generateLevelInfo(ClassDoc parent, List list,
098: boolean isEnum) {
099: if (list.size() > 0) {
100: ul();
101: for (int i = 0; i < list.size(); i++) {
102: ClassDoc local = (ClassDoc) list.get(i);
103: printPartialInfo(local);
104: printExtendsImplements(parent, local);
105: generateLevelInfo(local, classtree.subs(local, isEnum),
106: isEnum); // Recurse
107: }
108: ulEnd();
109: }
110: }
111:
112: /**
113: * Generate the heading for the tree depending upon tree type if it's a
114: * Class Tree or Interface tree and also print the tree.
115: *
116: * @param list List of classes which are at the most base level, all the
117: * other classes in this run will derive from these classes.
118: * @param heading Heading for the tree.
119: */
120: protected void generateTree(List list, String heading) {
121: if (list.size() > 0) {
122: ClassDoc firstClassDoc = (ClassDoc) list.get(0);
123: printTreeHeading(heading);
124: generateLevelInfo(
125: !firstClassDoc.isInterface() ? firstClassDoc : null,
126: list, list == classtree.baseEnums());
127: }
128: }
129:
130: /**
131: * Print the information regarding the classes which this class extends or
132: * implements.
133: *
134: * @param cd The classdoc under consideration.
135: */
136: protected void printExtendsImplements(ClassDoc parent, ClassDoc cd) {
137: ClassDoc[] interfaces = cd.interfaces();
138: if (interfaces.length > (cd.isInterface() ? 1 : 0)) {
139: Arrays.sort(interfaces);
140: int counter = 0;
141: for (int i = 0; i < interfaces.length; i++) {
142: if (parent != interfaces[i]) {
143: if (!(interfaces[i].isPublic() || Util.isLinkable(
144: interfaces[i], configuration()))) {
145: continue;
146: }
147: if (counter == 0) {
148: if (cd.isInterface()) {
149: print(" ("
150: + configuration
151: .getText("doclet.also")
152: + " extends ");
153: } else {
154: print(" (implements ");
155: }
156: } else {
157: print(", ");
158: }
159: printPreQualifiedClassLink(
160: LinkInfoImpl.CONTEXT_TREE, interfaces[i]);
161: counter++;
162: }
163: }
164: if (counter > 0) {
165: println(")");
166: }
167: }
168: }
169:
170: /**
171: * Print information about the class kind, if it's a "class" or "interface".
172: *
173: * @param cd classdoc.
174: */
175: protected void printPartialInfo(ClassDoc cd) {
176: li("circle");
177: printPreQualifiedBoldClassLink(LinkInfoImpl.CONTEXT_TREE, cd);
178: }
179:
180: /**
181: * Print the heading for the tree.
182: *
183: * @param heading Heading for the tree.
184: */
185: protected void printTreeHeading(String heading) {
186: h2();
187: println(configuration.getText(heading));
188: h2End();
189: }
190:
191: /**
192: * Highlight "Tree" word in the navigation bar, since this is the tree page.
193: */
194: protected void navLinkTree() {
195: navCellRevStart();
196: fontStyle("NavBarFont1Rev");
197: boldText("doclet.Tree");
198: fontEnd();
199: navCellEnd();
200: }
201: }
|