duke@1: /* duke@1: * Copyright 1998-2004 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: import com.sun.javadoc.*; duke@1: import java.io.*; duke@1: import java.util.*; duke@1: duke@1: /** duke@1: * Abstract class to print the class hierarchy page for all the Classes. This duke@1: * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to duke@1: * generate the Package Tree and global Tree(for all the classes and packages) duke@1: * pages. duke@1: * duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public abstract class AbstractTreeWriter extends HtmlDocletWriter { duke@1: duke@1: /** duke@1: * The class and interface tree built by using {@link ClassTree} duke@1: */ duke@1: protected final ClassTree classtree; duke@1: duke@1: /** duke@1: * Constructor initilises classtree variable. This constructor will be used duke@1: * while generating global tree file "overview-tree.html". duke@1: * duke@1: * @param filename File to be generated. duke@1: * @param classtree Tree built by {@link ClassTree}. duke@1: * @throws IOException duke@1: * @throws DocletAbortException duke@1: */ duke@1: protected AbstractTreeWriter(ConfigurationImpl configuration, duke@1: String filename, ClassTree classtree) duke@1: throws IOException { duke@1: super(configuration, filename); duke@1: this.classtree = classtree; duke@1: } duke@1: duke@1: /** duke@1: * Create appropriate directory for the package and also initilise the duke@1: * relative path from this generated file to the current or duke@1: * the destination directory. This constructor will be used while duke@1: * generating "package tree" file. duke@1: * duke@1: * @param path Directories in this path will be created if they are not duke@1: * already there. duke@1: * @param filename Name of the package tree file to be generated. duke@1: * @param classtree The tree built using {@link ClassTree}. duke@1: * for the package pkg. duke@1: * @param pkg PackageDoc for which tree file will be generated. duke@1: * @throws IOException duke@1: * @throws DocletAbortException duke@1: */ duke@1: protected AbstractTreeWriter(ConfigurationImpl configuration, duke@1: String path, String filename, duke@1: ClassTree classtree, PackageDoc pkg) duke@1: throws IOException { duke@1: super(configuration, duke@1: path, filename, DirectoryManager.getRelativePath(pkg.name())); duke@1: this.classtree = classtree; duke@1: } duke@1: duke@1: /** duke@1: * Generate each level of the class tree. For each sub-class or duke@1: * sub-interface indents the next level information. duke@1: * Recurses itself to generate subclasses info. duke@1: * To iterate is human, to recurse is divine - L. Peter Deutsch. duke@1: * duke@1: * @param parent the superclass or superinterface of the list. duke@1: * @param list list of the sub-classes at this level. duke@1: * @param isEnum true if we are generating a tree for enums. duke@1: */ mcimadamore@184: protected void generateLevelInfo(ClassDoc parent, List list, duke@1: boolean isEnum) { duke@1: if (list.size() > 0) { duke@1: ul(); duke@1: for (int i = 0; i < list.size(); i++) { mcimadamore@184: ClassDoc local = list.get(i); duke@1: printPartialInfo(local); duke@1: printExtendsImplements(parent, local); duke@1: generateLevelInfo(local, classtree.subs(local, isEnum), duke@1: isEnum); // Recurse duke@1: } duke@1: ulEnd(); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Generate the heading for the tree depending upon tree type if it's a duke@1: * Class Tree or Interface tree and also print the tree. duke@1: * duke@1: * @param list List of classes which are at the most base level, all the duke@1: * other classes in this run will derive from these classes. duke@1: * @param heading Heading for the tree. duke@1: */ mcimadamore@184: protected void generateTree(List list, String heading) { duke@1: if (list.size() > 0) { mcimadamore@184: ClassDoc firstClassDoc = list.get(0); duke@1: printTreeHeading(heading); duke@1: generateLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null, duke@1: list, duke@1: list == classtree.baseEnums()); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print the information regarding the classes which this class extends or duke@1: * implements. duke@1: * duke@1: * @param cd The classdoc under consideration. duke@1: */ duke@1: protected void printExtendsImplements(ClassDoc parent, ClassDoc cd) { duke@1: ClassDoc[] interfaces = cd.interfaces(); duke@1: if (interfaces.length > (cd.isInterface()? 1 : 0)) { duke@1: Arrays.sort(interfaces); duke@1: int counter = 0; duke@1: for (int i = 0; i < interfaces.length; i++) { duke@1: if (parent != interfaces[i]) { duke@1: if (! (interfaces[i].isPublic() || duke@1: Util.isLinkable(interfaces[i], configuration()))) { duke@1: continue; duke@1: } duke@1: if (counter == 0) { duke@1: if (cd.isInterface()) { duke@1: print(" (" + configuration.getText("doclet.also") + " extends "); duke@1: } else { duke@1: print(" (implements "); duke@1: } duke@1: } else { duke@1: print(", "); duke@1: } duke@1: printPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE, duke@1: interfaces[i]); duke@1: counter++; duke@1: } duke@1: } duke@1: if (counter > 0) { duke@1: println(")"); duke@1: } duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print information about the class kind, if it's a "class" or "interface". duke@1: * duke@1: * @param cd classdoc. duke@1: */ duke@1: protected void printPartialInfo(ClassDoc cd) { duke@1: li("circle"); bpatel@182: printPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd); duke@1: } duke@1: duke@1: /** duke@1: * Print the heading for the tree. duke@1: * duke@1: * @param heading Heading for the tree. duke@1: */ duke@1: protected void printTreeHeading(String heading) { duke@1: h2(); duke@1: println(configuration.getText(heading)); duke@1: h2End(); duke@1: } duke@1: duke@1: /** duke@1: * Highlight "Tree" word in the navigation bar, since this is the tree page. duke@1: */ duke@1: protected void navLinkTree() { duke@1: navCellRevStart(); duke@1: fontStyle("NavBarFont1Rev"); bpatel@182: strongText("doclet.Tree"); duke@1: fontEnd(); duke@1: navCellEnd(); duke@1: } duke@1: }