src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java

Mon, 19 Nov 2012 16:10:34 -0800

author
bpatel
date
Mon, 19 Nov 2012 16:10:34 -0800
changeset 1417
522a1ee72340
parent 1373
4a1c57a1c410
child 1736
74cd21f2c2fe
permissions
-rw-r--r--

8002304: Group methods by types in methods summary section
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.formats.html.markup.*;
    32 import com.sun.tools.doclets.internal.toolkit.*;
    33 import com.sun.tools.doclets.internal.toolkit.util.*;
    35 /**
    36  * Class to generate Tree page for a package. The name of the file generated is
    37  * "package-tree.html" and it is generated in the respective package directory.
    38  *
    39  *  <p><b>This is NOT part of any supported API.
    40  *  If you write code that depends on this, you do so at your own risk.
    41  *  This code and its internal interfaces are subject to change or
    42  *  deletion without notice.</b>
    43  *
    44  * @author Atul M Dambalkar
    45  * @author Bhavesh Patel (Modified)
    46  */
    47 public class PackageTreeWriter extends AbstractTreeWriter {
    49     /**
    50      * Package for which tree is to be generated.
    51      */
    52     protected PackageDoc packagedoc;
    54     /**
    55      * The previous package name in the alpha-order list.
    56      */
    57     protected PackageDoc prev;
    59     /**
    60      * The next package name in the alpha-order list.
    61      */
    62     protected PackageDoc next;
    64     /**
    65      * Constructor.
    66      * @throws IOException
    67      * @throws DocletAbortException
    68      */
    69     public PackageTreeWriter(ConfigurationImpl configuration,
    70                              DocPath path,
    71                              PackageDoc packagedoc,
    72                              PackageDoc prev, PackageDoc next)
    73                       throws IOException {
    74         super(configuration, path,
    75               new ClassTree(
    76                 configuration.classDocCatalog.allClasses(packagedoc),
    77                 configuration));
    78         this.packagedoc = packagedoc;
    79         this.prev = prev;
    80         this.next = next;
    81     }
    83     /**
    84      * Construct a PackageTreeWriter object and then use it to generate the
    85      * package tree page.
    86      *
    87      * @param pkg      Package for which tree file is to be generated.
    88      * @param prev     Previous package in the alpha-ordered list.
    89      * @param next     Next package in the alpha-ordered list.
    90      * @param noDeprecated  If true, do not generate any information for
    91      * deprecated classe or interfaces.
    92      * @throws DocletAbortException
    93      */
    94     public static void generate(ConfigurationImpl configuration,
    95                                 PackageDoc pkg, PackageDoc prev,
    96                                 PackageDoc next, boolean noDeprecated) {
    97         PackageTreeWriter packgen;
    98         DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE);
    99         try {
   100             packgen = new PackageTreeWriter(configuration, path, pkg,
   101                 prev, next);
   102             packgen.generatePackageTreeFile();
   103             packgen.close();
   104         } catch (IOException exc) {
   105             configuration.standardmessage.error(
   106                         "doclet.exception_encountered",
   107                         exc.toString(), path.getPath());
   108             throw new DocletAbortException();
   109         }
   110     }
   112     /**
   113      * Generate a separate tree file for each package.
   114      */
   115     protected void generatePackageTreeFile() throws IOException {
   116         Content body = getPackageTreeHeader();
   117         Content headContent = getResource("doclet.Hierarchy_For_Package",
   118                 Util.getPackageName(packagedoc));
   119         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
   120                 HtmlStyle.title, headContent);
   121         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
   122         if (configuration.packages.length > 1) {
   123             addLinkToMainTree(div);
   124         }
   125         body.addContent(div);
   126         HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
   127         divTree.addStyle(HtmlStyle.contentContainer);
   128         addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
   129         addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
   130         addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
   131         addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
   132         body.addContent(divTree);
   133         addNavLinks(false, body);
   134         addBottom(body);
   135         printHtmlDocument(null, true, body);
   136     }
   138     /**
   139      * Get the package tree header.
   140      *
   141      * @return a content tree for the header
   142      */
   143     protected Content getPackageTreeHeader() {
   144         String title = packagedoc.name() + " " +
   145                 configuration.getText("doclet.Window_Class_Hierarchy");
   146         Content bodyTree = getBody(true, getWindowTitle(title));
   147         addTop(bodyTree);
   148         addNavLinks(true, bodyTree);
   149         return bodyTree;
   150     }
   152     /**
   153      * Add a link to the tree for all the packages.
   154      *
   155      * @param div the content tree to which the link will be added
   156      */
   157     protected void addLinkToMainTree(Content div) {
   158         Content span = HtmlTree.SPAN(HtmlStyle.strong,
   159                 getResource("doclet.Package_Hierarchies"));
   160         div.addContent(span);
   161         HtmlTree ul = new HtmlTree (HtmlTag.UL);
   162         ul.addStyle(HtmlStyle.horizontal);
   163         ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages")));
   164         div.addContent(ul);
   165     }
   167     /**
   168      * Get link for the previous package tree file.
   169      *
   170      * @return a content tree for the link
   171      */
   172     protected Content getNavLinkPrevious() {
   173         if (prev == null) {
   174             return getNavLinkPrevious(null);
   175         } else {
   176             DocPath path = DocPath.relativePath(packagedoc, prev);
   177             return getNavLinkPrevious(path.resolve(DocPaths.PACKAGE_TREE));
   178         }
   179     }
   181     /**
   182      * Get link for the next package tree file.
   183      *
   184      * @return a content tree for the link
   185      */
   186     protected Content getNavLinkNext() {
   187         if (next == null) {
   188             return getNavLinkNext(null);
   189         } else {
   190             DocPath path = DocPath.relativePath(packagedoc, next);
   191             return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE));
   192         }
   193     }
   195     /**
   196      * Get link to the package summary page for the package of this tree.
   197      *
   198      * @return a content tree for the package link
   199      */
   200     protected Content getNavLinkPackage() {
   201         Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
   202                 packageLabel);
   203         Content li = HtmlTree.LI(linkContent);
   204         return li;
   205     }
   206 }

mercurial