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

Wed, 18 Dec 2013 19:48:47 -0800

author
bpatel
date
Wed, 18 Dec 2013 19:48:47 -0800
changeset 2225
b8ebde062692
parent 2147
130b8c0e570e
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8016549: jdk7 javadocs are hard to read
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1997, 2013, 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.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.formats.html.markup.*;
    33 import com.sun.tools.doclets.internal.toolkit.*;
    34 import com.sun.tools.doclets.internal.toolkit.util.*;
    36 /**
    37  * Class to generate file for each package contents in the right-hand
    38  * frame. This will list all the Class Kinds in the package. A click on any
    39  * class-kind will update the frame with the clicked class-kind page.
    40  *
    41  *  <p><b>This is NOT part of any supported API.
    42  *  If you write code that depends on this, you do so at your own risk.
    43  *  This code and its internal interfaces are subject to change or
    44  *  deletion without notice.</b>
    45  *
    46  * @author Atul M Dambalkar
    47  * @author Bhavesh Patel (Modified)
    48  */
    49 public class PackageWriterImpl extends HtmlDocletWriter
    50     implements PackageSummaryWriter {
    52     /**
    53      * The prev package name in the alpha-order list.
    54      */
    55     protected PackageDoc prev;
    57     /**
    58      * The next package name in the alpha-order list.
    59      */
    60     protected PackageDoc next;
    62     /**
    63      * The package being documented.
    64      */
    65     protected PackageDoc packageDoc;
    67     /**
    68      * Constructor to construct PackageWriter object and to generate
    69      * "package-summary.html" file in the respective package directory.
    70      * For example for package "java.lang" this will generate file
    71      * "package-summary.html" file in the "java/lang" directory. It will also
    72      * create "java/lang" directory in the current or the destination directory
    73      * if it doesn't exist.
    74      *
    75      * @param configuration the configuration of the doclet.
    76      * @param packageDoc    PackageDoc under consideration.
    77      * @param prev          Previous package in the sorted array.
    78      * @param next            Next package in the sorted array.
    79      */
    80     public PackageWriterImpl(ConfigurationImpl configuration,
    81             PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
    82             throws IOException {
    83         super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_SUMMARY));
    84         this.prev = prev;
    85         this.next = next;
    86         this.packageDoc = packageDoc;
    87     }
    89     /**
    90      * {@inheritDoc}
    91      */
    92     public Content getPackageHeader(String heading) {
    93         String pkgName = packageDoc.name();
    94         Content bodyTree = getBody(true, getWindowTitle(pkgName));
    95         addTop(bodyTree);
    96         addNavLinks(true, bodyTree);
    97         HtmlTree div = new HtmlTree(HtmlTag.DIV);
    98         div.addStyle(HtmlStyle.header);
    99         Content annotationContent = new HtmlTree(HtmlTag.P);
   100         addAnnotationInfo(packageDoc, annotationContent);
   101         div.addContent(annotationContent);
   102         Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
   103                 HtmlStyle.title, packageLabel);
   104         tHeading.addContent(getSpace());
   105         Content packageHead = new StringContent(heading);
   106         tHeading.addContent(packageHead);
   107         div.addContent(tHeading);
   108         addDeprecationInfo(div);
   109         if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
   110             HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
   111             docSummaryDiv.addStyle(HtmlStyle.docSummary);
   112             addSummaryComment(packageDoc, docSummaryDiv);
   113             div.addContent(docSummaryDiv);
   114             Content space = getSpace();
   115             Content descLink = getHyperLink(getDocLink(
   116                     SectionName.PACKAGE_DESCRIPTION),
   117                     descriptionLabel, "", "");
   118             Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
   119             div.addContent(descPara);
   120         }
   121         bodyTree.addContent(div);
   122         return bodyTree;
   123     }
   125     /**
   126      * {@inheritDoc}
   127      */
   128     public Content getContentHeader() {
   129         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   130         div.addStyle(HtmlStyle.contentContainer);
   131         return div;
   132     }
   134     /**
   135      * Add the package deprecation information to the documentation tree.
   136      *
   137      * @param div the content tree to which the deprecation information will be added
   138      */
   139     public void addDeprecationInfo(Content div) {
   140         Tag[] deprs = packageDoc.tags("deprecated");
   141         if (Util.isDeprecated(packageDoc)) {
   142             HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
   143             deprDiv.addStyle(HtmlStyle.deprecatedContent);
   144             Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase);
   145             deprDiv.addContent(deprPhrase);
   146             if (deprs.length > 0) {
   147                 Tag[] commentTags = deprs[0].inlineTags();
   148                 if (commentTags.length > 0) {
   149                     addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
   150                 }
   151             }
   152             div.addContent(deprDiv);
   153         }
   154     }
   156     /**
   157      * {@inheritDoc}
   158      */
   159     public Content getSummaryHeader() {
   160         HtmlTree ul = new HtmlTree(HtmlTag.UL);
   161         ul.addStyle(HtmlStyle.blockList);
   162         return ul;
   163     }
   165     /**
   166      * {@inheritDoc}
   167      */
   168     public void addClassesSummary(ClassDoc[] classes, String label,
   169             String tableSummary, String[] tableHeader, Content summaryContentTree) {
   170         if(classes.length > 0) {
   171             Arrays.sort(classes);
   172             Content caption = getTableCaption(new RawHtml(label));
   173             Content table = HtmlTree.TABLE(HtmlStyle.typeSummary, 0, 3, 0,
   174                     tableSummary, caption);
   175             table.addContent(getSummaryTableHeader(tableHeader, "col"));
   176             Content tbody = new HtmlTree(HtmlTag.TBODY);
   177             for (int i = 0; i < classes.length; i++) {
   178                 if (!Util.isCoreClass(classes[i]) ||
   179                     !configuration.isGeneratedDoc(classes[i])) {
   180                     continue;
   181                 }
   182                 Content classContent = getLink(new LinkInfoImpl(
   183                         configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
   184                 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
   185                 HtmlTree tr = HtmlTree.TR(tdClass);
   186                 if (i%2 == 0)
   187                     tr.addStyle(HtmlStyle.altColor);
   188                 else
   189                     tr.addStyle(HtmlStyle.rowColor);
   190                 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
   191                 tdClassDescription.addStyle(HtmlStyle.colLast);
   192                 if (Util.isDeprecated(classes[i])) {
   193                     tdClassDescription.addContent(deprecatedLabel);
   194                     if (classes[i].tags("deprecated").length > 0) {
   195                         addSummaryDeprecatedComment(classes[i],
   196                             classes[i].tags("deprecated")[0], tdClassDescription);
   197                     }
   198                 }
   199                 else
   200                     addSummaryComment(classes[i], tdClassDescription);
   201                 tr.addContent(tdClassDescription);
   202                 tbody.addContent(tr);
   203             }
   204             table.addContent(tbody);
   205             Content li = HtmlTree.LI(HtmlStyle.blockList, table);
   206             summaryContentTree.addContent(li);
   207         }
   208     }
   210     /**
   211      * {@inheritDoc}
   212      */
   213     public void addPackageDescription(Content packageContentTree) {
   214         if (packageDoc.inlineTags().length > 0) {
   215             packageContentTree.addContent(
   216                     getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION));
   217             Content h2Content = new StringContent(
   218                     configuration.getText("doclet.Package_Description",
   219                     packageDoc.name()));
   220             packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
   221                     true, h2Content));
   222             addInlineComment(packageDoc, packageContentTree);
   223         }
   224     }
   226     /**
   227      * {@inheritDoc}
   228      */
   229     public void addPackageTags(Content packageContentTree) {
   230         addTagsInfo(packageDoc, packageContentTree);
   231     }
   233     /**
   234      * {@inheritDoc}
   235      */
   236     public void addPackageFooter(Content contentTree) {
   237         addNavLinks(false, contentTree);
   238         addBottom(contentTree);
   239     }
   241     /**
   242      * {@inheritDoc}
   243      */
   244     public void printDocument(Content contentTree) throws IOException {
   245         printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
   246                 true, contentTree);
   247     }
   249     /**
   250      * Get "Use" link for this pacakge in the navigation bar.
   251      *
   252      * @return a content tree for the class use link
   253      */
   254     protected Content getNavLinkClassUse() {
   255         Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
   256                 useLabel, "", "");
   257         Content li = HtmlTree.LI(useLink);
   258         return li;
   259     }
   261     /**
   262      * Get "PREV PACKAGE" link in the navigation bar.
   263      *
   264      * @return a content tree for the previous link
   265      */
   266     public Content getNavLinkPrevious() {
   267         Content li;
   268         if (prev == null) {
   269             li = HtmlTree.LI(prevpackageLabel);
   270         } else {
   271             DocPath path = DocPath.relativePath(packageDoc, prev);
   272             li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
   273                 prevpackageLabel, "", ""));
   274         }
   275         return li;
   276     }
   278     /**
   279      * Get "NEXT PACKAGE" link in the navigation bar.
   280      *
   281      * @return a content tree for the next link
   282      */
   283     public Content getNavLinkNext() {
   284         Content li;
   285         if (next == null) {
   286             li = HtmlTree.LI(nextpackageLabel);
   287         } else {
   288             DocPath path = DocPath.relativePath(packageDoc, next);
   289             li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
   290                 nextpackageLabel, "", ""));
   291         }
   292         return li;
   293     }
   295     /**
   296      * Get "Tree" link in the navigation bar. This will be link to the package
   297      * tree file.
   298      *
   299      * @return a content tree for the tree link
   300      */
   301     protected Content getNavLinkTree() {
   302         Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
   303                 treeLabel, "", "");
   304         Content li = HtmlTree.LI(useLink);
   305         return li;
   306     }
   308     /**
   309      * Highlight "Package" in the navigation bar, as this is the package page.
   310      *
   311      * @return a content tree for the package link
   312      */
   313     protected Content getNavLinkPackage() {
   314         Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
   315         return li;
   316     }
   317 }

mercurial