001    /*
002     * Copyright 1997-2005 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    import com.sun.javadoc.*;
030    import java.io.*;
031    /**
032     * Generate Class Hierarchy page for all the Classes in this run.  Use
033     * ClassTree for building the Tree. The name of
034     * the generated file is "overview-tree.html" and it is generated in the
035     * current or the destination directory.
036     *
037     * @author Atul M Dambalkar
038     */
039    public class TreeWriter extends AbstractTreeWriter {
040    
041        /**
042         * Packages in this run.
043         */
044        private PackageDoc[] packages;
045    
046        /**
047         * True if there are no packages specified on the command line,
048         * False otherwise.
049         */
050        private boolean classesonly;
051    
052        /**
053         * Constructor to construct TreeWriter object.
054         *
055         * @param configuration the current configuration of the doclet.
056         * @param filename String filename
057         * @param classtree the tree being built.
058         */
059        public TreeWriter(ConfigurationImpl configuration,
060                String filename, ClassTree classtree)
061        throws IOException {
062            super(configuration, filename, classtree);
063            packages = configuration.packages;
064        classesonly = packages.length == 0;
065        }
066    
067        /**
068         * Create a TreeWriter object and use it to generate the
069         * "overview-tree.html" file.
070         *
071         * @param classtree the class tree being documented.
072         * @throws  DocletAbortException
073         */
074        public static void generate(ConfigurationImpl configuration,
075                                    ClassTree classtree) {
076            TreeWriter treegen;
077            String filename = "overview-tree.html";
078            try {
079                treegen = new TreeWriter(configuration, filename, classtree);
080                treegen.generateTreeFile();
081                treegen.close();
082            } catch (IOException exc) {
083                configuration.standardmessage.error(
084                            "doclet.exception_encountered",
085                            exc.toString(), filename);
086                throw new DocletAbortException();
087            }
088        }
089    
090        /**
091         * Print the interface hierarchy and class hierarchy in the file.
092         */
093        public void generateTreeFile() throws IOException {
094            printHtmlHeader(configuration.getText("doclet.Window_Class_Hierarchy"),
095                null, true);
096    
097            printTreeHeader();
098    
099            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                strongText("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    }