src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexFrameWriter.java
changeset 54409 94986cf5e969
parent 54408 8fe16bf92ebd
parent 54373 13935056b05e
child 54410 7feb5e303c83
equal deleted inserted replaced
54408:8fe16bf92ebd 54409:94986cf5e969
     1 /*
       
     2  * Copyright (c) 2013, 2019, 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  */
       
    25 
       
    26 package jdk.javadoc.internal.doclets.formats.html;
       
    27 
       
    28 import java.util.Map;
       
    29 import java.util.Set;
       
    30 
       
    31 import javax.lang.model.element.ModuleElement;
       
    32 import javax.lang.model.element.PackageElement;
       
    33 
       
    34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlAttr;
       
    35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
       
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
       
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
       
    38 import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
       
    39 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
       
    40 import jdk.javadoc.internal.doclets.toolkit.Content;
       
    41 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
       
    42 import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
       
    43 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
       
    44 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
       
    45 
       
    46 /**
       
    47  * Generate the module index for the left-hand frame in the generated output.
       
    48  * A click on the module name in this frame will update the page in the top
       
    49  * left hand frame with the listing of packages of the clicked module.
       
    50  *
       
    51  *  <p><b>This is NOT part of any supported API.
       
    52  *  If you write code that depends on this, you do so at your own risk.
       
    53  *  This code and its internal interfaces are subject to change or
       
    54  *  deletion without notice.</b>
       
    55  *
       
    56  * @author Bhavesh Patel
       
    57  */
       
    58 public class ModuleIndexFrameWriter extends AbstractModuleIndexWriter {
       
    59     /**
       
    60      * The heading (h1 or h2) to use for the module list,
       
    61      * set by addNavigationBarHeader depending on whether or not there
       
    62      * is an additional initial heading.
       
    63      */
       
    64     private HtmlTag moduleListHeading;
       
    65 
       
    66     /**
       
    67      * Construct the ModuleIndexFrameWriter object.
       
    68      *
       
    69      * @param configuration the configuration object
       
    70      * @param filename Name of the module index file to be generated.
       
    71      */
       
    72     public ModuleIndexFrameWriter(HtmlConfiguration configuration,
       
    73                                    DocPath filename) {
       
    74         super(configuration, filename);
       
    75     }
       
    76 
       
    77     /**
       
    78      * Generate the module index file named "module-overview-frame.html".
       
    79      * @throws DocFileIOException
       
    80      * @param configuration the configuration object
       
    81      */
       
    82     public static void generate(HtmlConfiguration configuration) throws DocFileIOException {
       
    83         DocPath filename = DocPaths.MODULE_OVERVIEW_FRAME;
       
    84         ModuleIndexFrameWriter modulegen = new ModuleIndexFrameWriter(configuration, filename);
       
    85         modulegen.buildModuleIndexFile("doclet.Window_Overview", "module overview (frame)", false);
       
    86     }
       
    87 
       
    88     /**
       
    89      * {@inheritDoc}
       
    90      */
       
    91     @Override
       
    92     protected void addModulesList(Content main) {
       
    93         Content heading = HtmlTree.HEADING(moduleListHeading, true,
       
    94                 contents.modulesLabel);
       
    95         HtmlTree htmlTree = HtmlTree.DIV(HtmlStyle.indexContainer, heading);
       
    96         HtmlTree ul = new HtmlTree(HtmlTag.UL);
       
    97         ul.setTitle(contents.modulesLabel);
       
    98         for (ModuleElement mdle: configuration.modules) {
       
    99             ul.add(getModuleLink(mdle));
       
   100         }
       
   101         htmlTree.add(ul);
       
   102         main.add(htmlTree);
       
   103     }
       
   104 
       
   105     /**
       
   106      * Returns each module name as a separate link.
       
   107      *
       
   108      * @param mdle the module being documented
       
   109      * @return content for the module link
       
   110      */
       
   111     protected Content getModuleLink(ModuleElement mdle) {
       
   112         Content moduleLinkContent;
       
   113         Content mdlLabel = new StringContent(mdle.getQualifiedName());
       
   114         moduleLinkContent = getModuleFramesHyperLink(mdle, mdlLabel, "packageListFrame");
       
   115         Content li = HtmlTree.LI(moduleLinkContent);
       
   116         return li;
       
   117     }
       
   118 
       
   119     private Content getModuleFramesHyperLink(ModuleElement mdle, Content label, String target) {
       
   120         DocLink mdlLink = new DocLink(docPaths.moduleFrame(mdle));
       
   121         DocLink mtFrameLink = new DocLink(docPaths.moduleTypeFrame(mdle));
       
   122         DocLink cFrameLink = new DocLink(docPaths.moduleSummary(mdle));
       
   123         HtmlTree anchor = HtmlTree.A(mdlLink.toString(), label);
       
   124         String onclickStr = "updateModuleFrame('" + mtFrameLink + "','" + cFrameLink + "');";
       
   125         anchor.put(HtmlAttr.TARGET, target);
       
   126         anchor.put(HtmlAttr.ONCLICK, onclickStr);
       
   127         return anchor;
       
   128     }
       
   129 
       
   130     /**
       
   131      * {@inheritDoc}
       
   132      */
       
   133     protected void addNavigationBarHeader(Content header) {
       
   134         String headerContent = !configuration.packagesheader.isEmpty() ? configuration.packagesheader
       
   135                 : configuration.header;
       
   136         if (!headerContent.isEmpty()) {
       
   137             Content heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, true,
       
   138                     HtmlStyle.bar, new RawHtml(replaceDocRootDir(headerContent)));
       
   139             header.add(heading);
       
   140             moduleListHeading = Headings.IndexFrames.MODULE_HEADING;
       
   141         } else {
       
   142             moduleListHeading = Headings.PAGE_TITLE_HEADING;
       
   143         }
       
   144     }
       
   145 
       
   146     /**
       
   147      * Do nothing as there is no overview information in this page.
       
   148      */
       
   149     protected void addOverviewHeader(Content body) {
       
   150     }
       
   151 
       
   152     /**
       
   153      * Adds "All Classes" link for the top of the left-hand frame page to the
       
   154      * documentation tree.
       
   155      *
       
   156      * @param ul the Content object to which the all classes link should be added
       
   157      */
       
   158     protected void addAllClassesLink(Content ul) {
       
   159         Content linkContent = links.createLink(DocPaths.ALLCLASSES_FRAME,
       
   160                 contents.allClassesLabel, "", "packageFrame");
       
   161         Content li = HtmlTree.LI(linkContent);
       
   162         ul.add(li);
       
   163     }
       
   164 
       
   165     /**
       
   166      * Adds "All Packages" link for the top of the left-hand frame page to the
       
   167      * documentation tree.
       
   168      *
       
   169      * @param ul the Content object to which the all packages link should be added
       
   170      */
       
   171     protected void addAllPackagesLink(Content ul) {
       
   172         Content linkContent = links.createLink(DocPaths.OVERVIEW_FRAME,
       
   173                 contents.allPackagesLabel, "", "packageListFrame");
       
   174         Content li = HtmlTree.LI(linkContent);
       
   175         ul.add(li);
       
   176     }
       
   177 
       
   178     /**
       
   179      * {@inheritDoc}
       
   180      */
       
   181     protected void addNavigationBarFooter(Content footer) {
       
   182         Content p = HtmlTree.P(Contents.SPACE);
       
   183         footer.add(p);
       
   184     }
       
   185 
       
   186     protected void addModulePackagesList(Map<ModuleElement, Set<PackageElement>> modules, String text,
       
   187             String tableSummary, Content main, ModuleElement mdle) {
       
   188     }
       
   189 }