src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AllClassesFrameWriter.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) 1998, 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 
       
    29 import javax.lang.model.element.Element;
       
    30 import javax.lang.model.element.TypeElement;
       
    31 
       
    32 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
       
    33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
       
    34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
       
    35 import jdk.javadoc.internal.doclets.toolkit.Content;
       
    36 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
       
    37 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
       
    38 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
       
    39 import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
       
    40 
       
    41 
       
    42 /**
       
    43  * Generate the file with list of all the classes in this run. This page will be
       
    44  * used in the left-hand bottom frame, when "All Classes" link is clicked in
       
    45  * the left-hand top frame. The name of the generated file is
       
    46  * "allclasses-frame.html".
       
    47  *
       
    48  *  <p><b>This is NOT part of any supported API.
       
    49  *  If you write code that depends on this, you do so at your own risk.
       
    50  *  This code and its internal interfaces are subject to change or
       
    51  *  deletion without notice.</b>
       
    52  *
       
    53  * @author Atul M Dambalkar
       
    54  * @author Doug Kramer
       
    55  * @author Bhavesh Patel (Modified)
       
    56  */
       
    57 public class AllClassesFrameWriter extends HtmlDocletWriter {
       
    58 
       
    59     /**
       
    60      * Index of all the classes.
       
    61      */
       
    62     protected IndexBuilder indexbuilder;
       
    63 
       
    64     /**
       
    65      * BR tag to be used within a document tree.
       
    66      */
       
    67     final HtmlTree BR = new HtmlTree(HtmlTag.BR);
       
    68 
       
    69     /**
       
    70      * Construct AllClassesFrameWriter object. Also initializes the indexbuilder
       
    71      * variable in this class.
       
    72      * @param configuration  The current configuration
       
    73      * @param filename       Path to the file which is getting generated.
       
    74      * @param indexbuilder   Unicode based Index from {@link IndexBuilder}
       
    75      */
       
    76     public AllClassesFrameWriter(HtmlConfiguration configuration,
       
    77                                  DocPath filename, IndexBuilder indexbuilder) {
       
    78         super(configuration, filename);
       
    79         this.indexbuilder = indexbuilder;
       
    80     }
       
    81 
       
    82     /**
       
    83      * Create AllClassesFrameWriter object. Then use it to generate the
       
    84      * "allclasses-frame.html" file. Generate the file in the current or the
       
    85      * destination directory.
       
    86      *
       
    87      * @param configuration the configuration for this javadoc run
       
    88      * @throws DocFileIOException
       
    89      */
       
    90     public static void generate(HtmlConfiguration configuration,
       
    91             IndexBuilder indexBuilder) throws DocFileIOException {
       
    92         if (configuration.frames) {
       
    93             generate(configuration, indexBuilder, DocPaths.ALLCLASSES_FRAME, true);
       
    94         }
       
    95     }
       
    96 
       
    97     private static void generate(HtmlConfiguration configuration, IndexBuilder indexBuilder,
       
    98                                  DocPath fileName, boolean wantFrames) throws DocFileIOException {
       
    99         AllClassesFrameWriter allclassgen = new AllClassesFrameWriter(configuration,
       
   100                 fileName, indexBuilder);
       
   101         allclassgen.buildAllClassesFile(wantFrames);
       
   102         allclassgen = new AllClassesFrameWriter(configuration,
       
   103                                                 fileName, indexBuilder);
       
   104     }
       
   105 
       
   106     /**
       
   107      * Print all the classes in the file.
       
   108      * @param wantFrames True if we want frames.
       
   109      */
       
   110     protected void buildAllClassesFile(boolean wantFrames) throws DocFileIOException {
       
   111         String label = resources.getText("doclet.All_Classes");
       
   112         Content body = getBody(false, getWindowTitle(label));
       
   113         Content htmlTree = HtmlTree.MAIN();
       
   114         Content heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
       
   115                 HtmlStyle.bar, contents.allClassesLabel);
       
   116         htmlTree.add(heading);
       
   117         Content ul = new HtmlTree(HtmlTag.UL);
       
   118         // Generate the class links and add it to the tdFont tree.
       
   119         addAllClasses(ul, wantFrames);
       
   120         HtmlTree div = HtmlTree.DIV(HtmlStyle.indexContainer, ul);
       
   121         htmlTree.add(div);
       
   122         body.add(htmlTree);
       
   123         printHtmlDocument(null, "all classes (frame)", body);
       
   124     }
       
   125 
       
   126     /**
       
   127      * Use the sorted index of all the classes and add all the classes to the
       
   128      * content list.
       
   129      *
       
   130      * @param content HtmlTree content to which all classes information will be added
       
   131      * @param wantFrames True if we want frames.
       
   132      */
       
   133     protected void addAllClasses(Content content, boolean wantFrames) {
       
   134         for (Character unicode : indexbuilder.index()) {
       
   135             addContents(indexbuilder.getMemberList(unicode), wantFrames, content);
       
   136         }
       
   137     }
       
   138 
       
   139     /**
       
   140      * Given a list of classes, generate links for each class or interface.
       
   141      * If the class kind is interface, print it in the italics font. Also all
       
   142      * links should target the right-hand frame. If clicked on any class name
       
   143      * in this page, appropriate class page should get opened in the right-hand
       
   144      * frame.
       
   145      *
       
   146      * @param classlist Sorted list of classes.
       
   147      * @param wantFrames True if we want frames.
       
   148      * @param content HtmlTree content to which the links will be added
       
   149      */
       
   150     protected void addContents(Iterable<? extends Element> classlist, boolean wantFrames,
       
   151                                Content content) {
       
   152         for (Element element : classlist) {
       
   153             TypeElement typeElement = (TypeElement)element;
       
   154             if (!utils.isCoreClass(typeElement)) {
       
   155                 continue;
       
   156             }
       
   157             Content label = interfaceName(typeElement, false);
       
   158             Content linkContent;
       
   159             if (wantFrames) {
       
   160                 linkContent = getLink(new LinkInfoImpl(configuration,
       
   161                                                        LinkInfoImpl.Kind.ALL_CLASSES_FRAME, typeElement).label(label).target("classFrame"));
       
   162             } else {
       
   163                 linkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, typeElement).label(label));
       
   164             }
       
   165             Content li = HtmlTree.LI(linkContent);
       
   166             content.add(li);
       
   167         }
       
   168     }
       
   169 }