duke@1: /* duke@1: * Copyright 1997-2005 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: import com.sun.javadoc.*; duke@1: import java.io.*; duke@1: /** duke@1: * Generate Class Hierarchy page for all the Classes in this run. Use duke@1: * ClassTree for building the Tree. The name of duke@1: * the generated file is "overview-tree.html" and it is generated in the duke@1: * current or the destination directory. duke@1: * duke@1: * @author Atul M Dambalkar duke@1: */ duke@1: public class TreeWriter extends AbstractTreeWriter { duke@1: duke@1: /** duke@1: * Packages in this run. duke@1: */ duke@1: private PackageDoc[] packages; duke@1: duke@1: /** duke@1: * True if there are no packages specified on the command line, duke@1: * False otherwise. duke@1: */ duke@1: private boolean classesonly; duke@1: duke@1: /** duke@1: * Constructor to construct TreeWriter object. duke@1: * duke@1: * @param configuration the current configuration of the doclet. duke@1: * @param filename String filename duke@1: * @param classtree the tree being built. duke@1: */ duke@1: public TreeWriter(ConfigurationImpl configuration, duke@1: String filename, ClassTree classtree) duke@1: throws IOException { duke@1: super(configuration, filename, classtree); duke@1: packages = configuration.packages; duke@1: classesonly = packages.length == 0; duke@1: } duke@1: duke@1: /** duke@1: * Create a TreeWriter object and use it to generate the duke@1: * "overview-tree.html" file. duke@1: * duke@1: * @param classtree the class tree being documented. duke@1: * @throws DocletAbortException duke@1: */ duke@1: public static void generate(ConfigurationImpl configuration, duke@1: ClassTree classtree) { duke@1: TreeWriter treegen; duke@1: String filename = "overview-tree.html"; duke@1: try { duke@1: treegen = new TreeWriter(configuration, filename, classtree); duke@1: treegen.generateTreeFile(); duke@1: treegen.close(); duke@1: } catch (IOException exc) { duke@1: configuration.standardmessage.error( duke@1: "doclet.exception_encountered", duke@1: exc.toString(), filename); duke@1: throw new DocletAbortException(); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print the interface hierarchy and class hierarchy in the file. duke@1: */ duke@1: public void generateTreeFile() throws IOException { duke@1: printHtmlHeader(configuration.getText("doclet.Window_Class_Hierarchy"), duke@1: null, true); duke@1: duke@1: printTreeHeader(); duke@1: duke@1: printPageHeading(); duke@1: duke@1: printPackageTreeLinks(); duke@1: duke@1: generateTree(classtree.baseclasses(), "doclet.Class_Hierarchy"); duke@1: generateTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy"); duke@1: generateTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy"); duke@1: generateTree(classtree.baseEnums(), "doclet.Enum_Hierarchy"); duke@1: duke@1: printTreeFooter(); duke@1: } duke@1: duke@1: /** duke@1: * Generate the links to all the package tree files. duke@1: */ duke@1: protected void printPackageTreeLinks() { duke@1: //Do nothing if only unnamed package is used duke@1: if (packages.length == 1 && packages[0].name().length() == 0) { duke@1: return; duke@1: } duke@1: if (!classesonly) { duke@1: dl(); duke@1: dt(); duke@1: boldText("doclet.Package_Hierarchies"); duke@1: dd(); duke@1: for (int i = 0; i < packages.length; i++) { duke@1: if (packages[i].name().length() == 0) { duke@1: continue; duke@1: } duke@1: String filename = pathString(packages[i], "package-tree.html"); duke@1: printHyperLink(filename, "", packages[i].name()); duke@1: if (i < packages.length - 1) { duke@1: print(", "); duke@1: } duke@1: } duke@1: dlEnd(); duke@1: hr(); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Print the top text (from the -top option) and duke@1: * navigation bar at the top of page. duke@1: */ duke@1: protected void printTreeHeader() { duke@1: printTop(); duke@1: navLinks(true); duke@1: hr(); duke@1: } duke@1: duke@1: /** duke@1: * Print the navigation bar and bottom text (from the -bottom option) duke@1: * at the bottom of page. duke@1: */ duke@1: protected void printTreeFooter() { duke@1: hr(); duke@1: navLinks(false); duke@1: printBottom(); duke@1: printBodyHtmlEnd(); duke@1: } duke@1: duke@1: /** duke@1: * Print the page title "Hierarchy For All Packages" at the top of the tree duke@1: * page. duke@1: */ duke@1: protected void printPageHeading() { duke@1: center(); duke@1: h2(); duke@1: printText("doclet.Hierarchy_For_All_Packages"); duke@1: h2End(); duke@1: centerEnd(); duke@1: } duke@1: }