001    /*
002     * Copyright 1998-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    /**
033     * Class to generate Tree page for a package. The name of the file generated is
034     * "package-tree.html" and it is generated in the respective package directory.
035     *
036     * @author Atul M Dambalkar
037     */
038    public class PackageTreeWriter extends AbstractTreeWriter {
039    
040        /**
041         * Package for which tree is to be generated.
042         */
043        protected PackageDoc packagedoc;
044    
045        /**
046         * The previous package name in the alpha-order list.
047         */
048        protected PackageDoc prev;
049    
050        /**
051         * The next package name in the alpha-order list.
052         */
053        protected PackageDoc next;
054    
055        /**
056         * Constructor.
057         * @throws IOException
058         * @throws DocletAbortException
059         */
060        public PackageTreeWriter(ConfigurationImpl configuration,
061                                 String path, String filename,
062                                 PackageDoc packagedoc,
063                                 PackageDoc prev, PackageDoc next)
064                          throws IOException {
065            super(configuration, path, filename,
066                  new ClassTree(
067                    configuration.classDocCatalog.allClasses(packagedoc),
068                    configuration),
069                  packagedoc);
070            this.packagedoc = packagedoc;
071            this.prev = prev;
072            this.next = next;
073        }
074    
075        /**
076         * Construct a PackageTreeWriter object and then use it to generate the
077         * package tree page.
078         *
079         * @param pkg      Package for which tree file is to be generated.
080         * @param prev     Previous package in the alpha-ordered list.
081         * @param next     Next package in the alpha-ordered list.
082         * @param noDeprecated  If true, do not generate any information for
083         * deprecated classe or interfaces.
084         * @throws DocletAbortException
085         */
086        public static void generate(ConfigurationImpl configuration,
087                                    PackageDoc pkg, PackageDoc prev,
088                                    PackageDoc next, boolean noDeprecated) {
089            PackageTreeWriter packgen;
090            String path = DirectoryManager.getDirectoryPath(pkg);
091            String filename = "package-tree.html";
092            try {
093                packgen = new PackageTreeWriter(configuration, path, filename, pkg,
094                    prev, next);
095                packgen.generatePackageTreeFile();
096                packgen.close();
097            } catch (IOException exc) {
098                configuration.standardmessage.error(
099                            "doclet.exception_encountered",
100                            exc.toString(), filename);
101                throw new DocletAbortException();
102            }
103        }
104    
105        /**
106         * Generate a separate tree file for each package.
107         */
108        protected void generatePackageTreeFile() throws IOException {
109            printHtmlHeader(packagedoc.name() + " "
110                + configuration.getText("doclet.Window_Class_Hierarchy"), null, true);
111    
112            printPackageTreeHeader();
113    
114            if (configuration.packages.length > 1) {
115                printLinkToMainTree();
116            }
117    
118            generateTree(classtree.baseclasses(), "doclet.Class_Hierarchy");
119            generateTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy");
120            generateTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy");
121            generateTree(classtree.baseEnums(), "doclet.Enum_Hierarchy");
122    
123            printPackageTreeFooter();
124            printBottom();
125            printBodyHtmlEnd();
126        }
127    
128        /**
129         * Print the navigation bar header for the package tree file.
130         */
131        protected void printPackageTreeHeader() {
132            printTop();
133            navLinks(true);
134            hr();
135            center();
136            h2(configuration.getText("doclet.Hierarchy_For_Package",
137                Util.getPackageName(packagedoc)));
138            centerEnd();
139        }
140    
141        /**
142         * Generate a link to the tree for all the packages.
143         */
144        protected void printLinkToMainTree() {
145            dl();
146            dt();
147            strongText("doclet.Package_Hierarchies");
148            dd();
149            navLinkMainTree(configuration.getText("doclet.All_Packages"));
150            dlEnd();
151            hr();
152        }
153    
154        /**
155         * Print the navigation bar footer for the package tree file.
156         */
157        protected void printPackageTreeFooter() {
158            hr();
159            navLinks(false);
160        }
161    
162        /**
163         * Link for the previous package tree file.
164         */
165        protected void navLinkPrevious() {
166            if (prev == null) {
167                navLinkPrevious(null);
168            } else {
169                String path = DirectoryManager.getRelativePath(packagedoc.name(),
170                                                               prev.name());
171                navLinkPrevious(path + "package-tree.html");
172            }
173        }
174    
175        /**
176         * Link for the next package tree file.
177         */
178        protected void navLinkNext() {
179            if (next == null) {
180                navLinkNext(null);
181            } else {
182                String path = DirectoryManager.getRelativePath(packagedoc.name(),
183                                                               next.name());
184                navLinkNext(path + "package-tree.html");
185            }
186        }
187    
188        /**
189         * Link to the package summary page for the package of this tree.
190         */
191        protected void navLinkPackage() {
192            navCellStart();
193            printHyperLink("package-summary.html", "", configuration.getText("doclet.Package"),
194                            true, "NavBarFont1");
195            navCellEnd();
196        }
197    }