duke@1: /* ohair@554: * Copyright (c) 1997, 2005, Oracle and/or its affiliates. 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 ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle 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: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@233: import java.io.*; bpatel@233: bpatel@233: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; bpatel@766: import com.sun.tools.doclets.internal.toolkit.*; bpatel@233: 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 bpatel@766: * @author Bhavesh Patel (Modified) 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: /** bpatel@766: * Generate the interface hierarchy and class hierarchy. duke@1: */ duke@1: public void generateTreeFile() throws IOException { bpatel@766: Content body = getTreeHeader(); bpatel@766: Content headContent = getResource("doclet.Hierarchy_For_All_Packages"); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, bpatel@766: HtmlStyle.title, headContent); bpatel@766: Content div = HtmlTree.DIV(HtmlStyle.header, heading); bpatel@766: addPackageTreeLinks(div); bpatel@766: body.addContent(div); bpatel@766: HtmlTree divTree = new HtmlTree(HtmlTag.DIV); bpatel@766: divTree.addStyle(HtmlStyle.contentContainer); bpatel@766: addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); bpatel@766: addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); bpatel@766: addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); bpatel@766: addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); bpatel@766: body.addContent(divTree); bpatel@766: addNavLinks(false, body); bpatel@766: addBottom(body); bpatel@766: printHtmlDocument(null, true, body); duke@1: } duke@1: duke@1: /** bpatel@766: * Add the links to all the package tree files. bpatel@766: * bpatel@766: * @param contentTree the content tree to which the links will be added duke@1: */ bpatel@766: protected void addPackageTreeLinks(Content contentTree) { 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) { bpatel@766: Content span = HtmlTree.SPAN(HtmlStyle.strong, bpatel@766: getResource("doclet.Package_Hierarchies")); bpatel@766: contentTree.addContent(span); bpatel@766: HtmlTree ul = new HtmlTree(HtmlTag.UL); bpatel@766: ul.addStyle(HtmlStyle.horizontal); duke@1: for (int i = 0; i < packages.length; i++) { duke@1: if (packages[i].name().length() == 0) { duke@1: continue; duke@1: } bpatel@766: String link = pathString(packages[i], "package-tree.html"); bpatel@766: Content li = HtmlTree.LI(getHyperLink( bpatel@766: link, "", new StringContent(packages[i].name()))); duke@1: if (i < packages.length - 1) { bpatel@766: li.addContent(", "); duke@1: } bpatel@766: ul.addContent(li); duke@1: } bpatel@766: contentTree.addContent(ul); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get the tree header. bpatel@766: * bpatel@766: * @return a content tree for the tree header duke@1: */ bpatel@766: protected Content getTreeHeader() { bpatel@766: String title = configuration.getText("doclet.Window_Class_Hierarchy"); bpatel@766: Content bodyTree = getBody(true, getWindowTitle(title)); bpatel@766: addTop(bodyTree); bpatel@766: addNavLinks(true, bodyTree); bpatel@766: return bodyTree; duke@1: } duke@1: }