src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/BodyContents.java
author hannesw
Wed, 27 Nov 2019 13:08:16 +0100
changeset 59294 48b88b9c11eb
permissions -rw-r--r--
8223378: CSS solution for navbar problem with <a> elements is not ideal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59294
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     1
/*
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     4
 *
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    10
 *
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    15
 * accompanied this code).
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    16
 *
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    20
 *
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    23
 * questions.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    24
 */
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    25
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    26
package jdk.javadoc.internal.doclets.formats.html.markup;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    27
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    28
import jdk.javadoc.internal.doclets.toolkit.Content;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    29
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    30
import java.util.ArrayList;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    31
import java.util.List;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    32
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    33
/**
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    34
 * A builder for the contents of the BODY element.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    35
 *
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    36
 *  <p><b>This is NOT part of any supported API.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    37
 *  If you write code that depends on this, you do so at your own risk.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    39
 *  deletion without notice.</b>
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    40
 */
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    41
public class BodyContents {
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    42
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    43
    private List<Content> mainContents = new ArrayList<>();
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    44
    private Content header = HtmlTree.EMPTY;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    45
    private Content footer = HtmlTree.EMPTY;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    46
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    47
    public BodyContents addMainContent(Content content) {
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    48
        mainContents.add(content);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    49
        return this;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    50
    }
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    51
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    52
    public BodyContents setHeader(Content header) {
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    53
        this.header = header;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    54
        return this;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    55
    }
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    56
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    57
    public BodyContents setFooter(Content footer) {
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    58
        this.footer = footer;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    59
        return this;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    60
    }
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    61
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    62
    /**
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    63
     * Returns the HTML for the contents of the BODY element.
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    64
     *
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    65
     * @return the HTML
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    66
     */
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    67
    public Content toContent() {
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    68
        HtmlTree mainTree = HtmlTree.MAIN();
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    69
        mainContents.forEach(mainTree::add);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    70
        HtmlTree flexHeader = HtmlTree.HEADER().setStyle(HtmlStyle.flexHeader);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    71
        flexHeader.add(header);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    72
        HtmlTree flexBox = HtmlTree.DIV(HtmlStyle.flexBox, flexHeader);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    73
        HtmlTree flexContent = HtmlTree.DIV(HtmlStyle.flexContent, mainTree);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    74
        flexContent.add(footer);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    75
        flexBox.add(flexContent);
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    76
        return flexBox;
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    77
    }
48b88b9c11eb 8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
diff changeset
    78
}