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 package jdk.javadoc.internal.doclets.formats.html.markup;
26
27 import java.util.ArrayList;
28 import java.util.Deque;
29 import java.util.List;
30 import java.util.Set;
31 import java.util.SortedSet;
32
33 import javax.lang.model.element.Element;
34 import javax.lang.model.element.ElementKind;
35 import javax.lang.model.element.ModuleElement;
36 import javax.lang.model.element.PackageElement;
37 import javax.lang.model.element.TypeElement;
38
39 import jdk.javadoc.internal.doclets.formats.html.AbstractMemberWriter;
40 import jdk.javadoc.internal.doclets.formats.html.Contents;
41 import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration;
42 import jdk.javadoc.internal.doclets.formats.html.MarkerComments;
43 import jdk.javadoc.internal.doclets.formats.html.SectionName;
44 import jdk.javadoc.internal.doclets.toolkit.Content;
45 import jdk.javadoc.internal.doclets.toolkit.builders.MemberSummaryBuilder;
46 import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
47 import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
48 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
49 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
50 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
51
52 import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*;
53
54 /**
55 * Factory for navigation bar.
56 *
57 * <p>
58 * <b>This is NOT part of any supported API. If you write code that depends on this, you do so at
59 * your own risk. This code and its internal interfaces are subject to change or deletion without
60 * notice.</b>
61 */
62 public class Navigation {
63
64 private final HtmlConfiguration configuration;
65 private final Element element;
66 private final Contents contents;
67 private final DocPath path;
68 private final DocPath pathToRoot;
69 private final Links links;
70 private final PageMode documentedPage;
71 private Content navLinkModule;
72 private Content navLinkPackage;
73 private Content navLinkClass;
74 private MemberSummaryBuilder memberSummaryBuilder;
75 private boolean displaySummaryModuleDescLink;
76 private boolean displaySummaryModulesLink;
77 private boolean displaySummaryPackagesLink;
78 private boolean displaySummaryServicesLink;
79 private Content userHeader;
80 private Content userFooter;
81 private final String rowListTitle;
82 private final Content searchLabel;
83
84 private static final Content EMPTY_COMMENT = new Comment(" ");
116 Content startOfNav() {
117 return startOfNav;
118 }
119
120 Content endOfNav() {
121 return endOfNav;
122 }
123 }
124
125 /**
126 * Creates a {@code Navigation} object for a specific file, to be written in a specific HTML
127 * version.
128 *
129 * @param element element being documented. null if its not an element documentation page
130 * @param configuration the configuration object
131 * @param page the kind of page being documented
132 * @param path the DocPath object
133 */
134 public Navigation(Element element, HtmlConfiguration configuration, PageMode page, DocPath path) {
135 this.configuration = configuration;
136 this.element = element;
137 this.contents = configuration.contents;
138 this.documentedPage = page;
139 this.path = path;
140 this.pathToRoot = path.parent().invert();
141 this.links = new Links(path);
142 this.rowListTitle = configuration.getResources().getText("doclet.Navigation");
143 this.searchLabel = contents.getContent("doclet.search");
144 }
145
146 public Navigation setNavLinkModule(Content navLinkModule) {
147 this.navLinkModule = navLinkModule;
148 return this;
149 }
150
151 public Navigation setNavLinkPackage(Content navLinkPackage) {
152 this.navLinkPackage = navLinkPackage;
153 return this;
154 }
155
184 }
185
186 public Navigation setUserHeader(Content userHeader) {
187 this.userHeader = userHeader;
188 return this;
189 }
190
191 public Navigation setUserFooter(Content userFooter) {
192 this.userFooter = userFooter;
193 return this;
194 }
195
196 /**
197 * Add the links for the main navigation.
198 *
199 * @param tree the content tree to which the main navigation will added
200 */
201 private void addMainNavLinks(Content tree) {
202 switch (documentedPage) {
203 case OVERVIEW:
204 addActivePageLink(tree, contents.overviewLabel, configuration.createoverview);
205 addModuleLink(tree);
206 addPackageLink(tree);
207 addPageLabel(tree, contents.classLabel, true);
208 addPageLabel(tree, contents.useLabel, configuration.classuse);
209 addTreeLink(tree);
210 addDeprecatedLink(tree);
211 addIndexLink(tree);
212 addHelpLink(tree);
213 break;
214 case MODULE:
215 addOverviewLink(tree);
216 addActivePageLink(tree, contents.moduleLabel, configuration.showModules);
217 addPackageLink(tree);
218 addPageLabel(tree, contents.classLabel, true);
219 addPageLabel(tree, contents.useLabel, configuration.classuse);
220 addTreeLink(tree);
221 addDeprecatedLink(tree);
222 addIndexLink(tree);
223 addHelpLink(tree);
224 break;
225 case PACKAGE:
226 addOverviewLink(tree);
227 addModuleOfElementLink(tree);
228 addActivePageLink(tree, contents.packageLabel, true);
229 addPageLabel(tree, contents.classLabel, true);
230 if (configuration.classuse) {
231 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_USE,
232 contents.useLabel, "", ""));
233 }
234 if (configuration.createtree) {
235 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_TREE,
236 contents.treeLabel, "", ""));
237 }
238 addDeprecatedLink(tree);
239 addIndexLink(tree);
240 addHelpLink(tree);
241 break;
242 case CLASS:
243 addOverviewLink(tree);
244 addModuleOfElementLink(tree);
245 addPackageSummaryLink(tree);
246 addActivePageLink(tree, contents.classLabel, true);
247 if (configuration.classuse) {
248 addContentToTree(tree, links.createLink(DocPaths.CLASS_USE.resolve(path.basename()),
249 contents.useLabel));
250 }
251 if (configuration.createtree) {
252 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_TREE,
253 contents.treeLabel, "", ""));
254 }
255 addDeprecatedLink(tree);
256 addIndexLink(tree);
257 addHelpLink(tree);
258 break;
259 case USE:
260 addOverviewLink(tree);
261 addModuleOfElementLink(tree);
262 if (element instanceof PackageElement) {
263 addPackageSummaryLink(tree);
264 addPageLabel(tree, contents.classLabel, true);
265 } else {
266 addPackageOfElementLink(tree);
267 addContentToTree(tree, navLinkClass);
268 }
269 addActivePageLink(tree, contents.useLabel, configuration.classuse);
270 if (element instanceof PackageElement) {
271 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_TREE, contents.treeLabel));
272 } else {
273 addContentToTree(tree, configuration.utils.isEnclosingPackageIncluded((TypeElement) element)
274 ? links.createLink(DocPath.parent.resolve(DocPaths.PACKAGE_TREE), contents.treeLabel)
275 : links.createLink(pathToRoot.resolve(DocPaths.OVERVIEW_TREE), contents.treeLabel));
276 }
277 addDeprecatedLink(tree);
278 addIndexLink(tree);
279 addHelpLink(tree);
280 break;
281 case TREE:
282 addOverviewLink(tree);
283 if (element == null) {
284 addPageLabel(tree, contents.moduleLabel, configuration.showModules);
285 addPageLabel(tree, contents.packageLabel, true);
286 } else {
287 addModuleOfElementLink(tree);
288 addPackageSummaryLink(tree);
289 }
290 addPageLabel(tree, contents.classLabel, true);
291 addPageLabel(tree, contents.useLabel, configuration.classuse);
292 addActivePageLink(tree, contents.treeLabel, configuration.createtree);
293 addDeprecatedLink(tree);
294 addIndexLink(tree);
295 addHelpLink(tree);
296 break;
297 case DEPRECATED:
298 case INDEX:
299 case HELP:
300 addOverviewLink(tree);
301 addModuleLink(tree);
302 addPackageLink(tree);
303 addPageLabel(tree, contents.classLabel, true);
304 addPageLabel(tree, contents.useLabel, configuration.classuse);
305 addTreeLink(tree);
306 if (documentedPage == PageMode.DEPRECATED) {
307 addActivePageLink(tree, contents.deprecatedLabel, !(configuration.nodeprecated
308 || configuration.nodeprecatedlist));
309 } else {
310 addDeprecatedLink(tree);
311 }
312 if (documentedPage == PageMode.INDEX) {
313 addActivePageLink(tree, contents.indexLabel, configuration.createindex);
314 } else {
315 addIndexLink(tree);
316 }
317 if (documentedPage == PageMode.HELP) {
318 addActivePageLink(tree, contents.helpLabel, !configuration.nohelp);
319 } else {
320 addHelpLink(tree);
321 }
322 break;
323 case ALLCLASSES:
324 case ALLPACKAGES:
325 case CONSTANTVALUES:
326 case SERIALIZEDFORM:
327 case SYSTEMPROPERTIES:
328 addOverviewLink(tree);
329 addModuleLink(tree);
330 addPackageLink(tree);
331 addPageLabel(tree, contents.classLabel, true);
332 addPageLabel(tree, contents.useLabel, configuration.classuse);
333 addTreeLink(tree);
334 addDeprecatedLink(tree);
335 addIndexLink(tree);
336 addHelpLink(tree);
337 break;
338 case DOCFILE:
339 addOverviewLink(tree);
340 addModuleOfElementLink(tree);
341 addContentToTree(tree, navLinkPackage);
342 addPageLabel(tree, contents.classLabel, true);
343 addPageLabel(tree, contents.useLabel, configuration.classuse);
344 addTreeLink(tree);
345 addDeprecatedLink(tree);
346 addIndexLink(tree);
347 addHelpLink(tree);
348 break;
349 default:
350 break;
351 }
352 }
353
354 /**
355 * Add the summary links to the sub-navigation.
356 *
357 * @param tree the content tree to which the sub-navigation will added
358 */
359 private void addSummaryLinks(Content tree) {
360 List<Content> listContents = new ArrayList<>();
361 switch (documentedPage) {
362 case CLASS:
363 if (element.getKind() == ElementKind.ANNOTATION_TYPE) {
766 liContent.add(Entity.NO_BREAK_SPACE);
767 }
768 tree.add(liContent);
769 count++;
770 }
771 }
772
773 private void addActivePageLink(Content tree, Content label, boolean display) {
774 if (display) {
775 tree.add(HtmlTree.LI(HtmlStyle.navBarCell1Rev, label));
776 }
777 }
778
779 private void addPageLabel(Content tree, Content label, boolean display) {
780 if (display) {
781 tree.add(HtmlTree.LI(label));
782 }
783 }
784
785 private void addOverviewLink(Content tree) {
786 if (configuration.createoverview) {
787 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(DocPaths.INDEX),
788 contents.overviewLabel, "", "")));
789 }
790 }
791
792 private void addModuleLink(Content tree) {
793 if (configuration.showModules) {
794 if (configuration.modules.size() == 1) {
795 ModuleElement mdle = configuration.modules.first();
796 boolean included = configuration.utils.isIncluded(mdle);
797 tree.add(HtmlTree.LI((included)
798 ? links.createLink(pathToRoot.resolve(configuration.docPaths.moduleSummary(mdle)), contents.moduleLabel, "", "")
799 : contents.moduleLabel));
800 } else if (!configuration.modules.isEmpty()) {
801 addPageLabel(tree, contents.moduleLabel, true);
802 }
803 }
804 }
805
806 private void addModuleOfElementLink(Content tree) {
832 tree.add(HtmlTree.LI(links.createLink(crossPkgLink, contents.packageLabel)));
833 } else {
834 tree.add(HtmlTree.LI(contents.packageLabel));
835 }
836 }
837 } else if (!configuration.packages.isEmpty()) {
838 addPageLabel(tree, contents.packageLabel, true);
839 }
840 }
841
842 private void addPackageOfElementLink(Content tree) {
843 tree.add(HtmlTree.LI(links.createLink(DocPath.parent.resolve(DocPaths.PACKAGE_SUMMARY),
844 contents.packageLabel)));
845 }
846
847 private void addPackageSummaryLink(Content tree) {
848 tree.add(HtmlTree.LI(links.createLink(DocPaths.PACKAGE_SUMMARY, contents.packageLabel)));
849 }
850
851 private void addTreeLink(Content tree) {
852 if (configuration.createtree) {
853 List<PackageElement> packages = new ArrayList<>(configuration.getSpecifiedPackageElements());
854 DocPath docPath = packages.size() == 1 && configuration.getSpecifiedTypeElements().isEmpty()
855 ? pathToRoot.resolve(configuration.docPaths.forPackage(packages.get(0)).resolve(DocPaths.PACKAGE_TREE))
856 : pathToRoot.resolve(DocPaths.OVERVIEW_TREE);
857 tree.add(HtmlTree.LI(links.createLink(docPath, contents.treeLabel, "", "")));
858 }
859 }
860
861 private void addDeprecatedLink(Content tree) {
862 if (!(configuration.nodeprecated || configuration.nodeprecatedlist)) {
863 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(DocPaths.DEPRECATED_LIST),
864 contents.deprecatedLabel, "", "")));
865 }
866 }
867
868 private void addIndexLink(Content tree) {
869 if (configuration.createindex) {
870 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(
871 (configuration.splitindex
872 ? DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1))
873 : DocPaths.INDEX_ALL)),
874 contents.indexLabel, "", "")));
875 }
876 }
877
878 private void addHelpLink(Content tree) {
879 if (!configuration.nohelp) {
880 String helpfile = configuration.helpfile;
881 DocPath helpfilenm;
882 if (helpfile.isEmpty()) {
883 helpfilenm = DocPaths.HELP_DOC;
884 } else {
885 DocFile file = DocFile.createFileForInput(configuration, helpfile);
886 helpfilenm = DocPath.create(file.getName());
887 }
888 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(helpfilenm),
889 contents.helpLabel, "", "")));
890 }
891 }
892
893 private void addSearch(Content tree) {
894 String searchValueId = "search";
895 String reset = "reset";
896 HtmlTree inputText = HtmlTree.INPUT("text", searchValueId, searchValueId);
897 HtmlTree inputReset = HtmlTree.INPUT(reset, reset, reset);
898 HtmlTree searchDiv = HtmlTree.DIV(HtmlStyle.navListSearch, HtmlTree.LABEL(searchValueId, searchLabel));
899 searchDiv.add(inputText);
900 searchDiv.add(inputReset);
901 tree.add(searchDiv);
902 }
903
904 /**
905 * Get the navigation content.
906 *
907 * @param top true if the top navigation bar is to be printed
908 * @return the navigation contents
909 */
910 public Content getContent(boolean top) {
911 if (configuration.nonavbar) {
912 return new ContentBuilder();
913 }
914 Content tree = HtmlTree.NAV();
915 HtmlTree navDiv = new HtmlTree(HtmlTag.DIV);
916 Content skipNavLinks = contents.getContent("doclet.Skip_navigation_links");
917 if (top) {
918 tree.add(Position.TOP.startOfNav());
919 navDiv.setStyle(HtmlStyle.topNav)
920 .setId(SectionName.NAVBAR_TOP.getName())
921 .add(HtmlTree.DIV(HtmlStyle.skipNav,
922 links.createLink(SectionName.SKIP_NAVBAR_TOP, skipNavLinks,
923 skipNavLinks.toString(), "")));
924 } else {
925 tree.add(Position.BOTTOM.startOfNav());
926 navDiv.setStyle(HtmlStyle.bottomNav)
927 .setId(SectionName.NAVBAR_BOTTOM.getName())
928 .add(HtmlTree.DIV(HtmlStyle.skipNav,
929 links.createLink(SectionName.SKIP_NAVBAR_BOTTOM, skipNavLinks,
930 skipNavLinks.toString(), "")));
931 }
936 navList.put(HtmlAttr.TITLE, rowListTitle);
937 addMainNavLinks(navList);
938 navDiv.add(navList);
939 Content aboutDiv = HtmlTree.DIV(HtmlStyle.aboutLanguage, top ? userHeader : userFooter);
940 navDiv.add(aboutDiv);
941 tree.add(navDiv);
942 HtmlTree subDiv = new HtmlTree(HtmlTag.DIV);
943 subDiv.setStyle(HtmlStyle.subNav);
944 HtmlTree div = new HtmlTree(HtmlTag.DIV);
945 // Add the summary links if present.
946 HtmlTree ulNavSummary = new HtmlTree(HtmlTag.UL);
947 ulNavSummary.setStyle(HtmlStyle.subNavList);
948 addSummaryLinks(ulNavSummary);
949 div.add(ulNavSummary);
950 // Add the detail links if present.
951 HtmlTree ulNavDetail = new HtmlTree(HtmlTag.UL);
952 ulNavDetail.setStyle(HtmlStyle.subNavList);
953 addDetailLinks(ulNavDetail);
954 div.add(ulNavDetail);
955 subDiv.add(div);
956 if (top && configuration.createindex) {
957 addSearch(subDiv);
958 }
959 tree.add(subDiv);
960 if (top) {
961 tree.add(Position.TOP.endOfNav());
962 tree.add(HtmlTree.SPAN(HtmlStyle.skipNav, EMPTY_COMMENT)
963 .setId(SectionName.SKIP_NAVBAR_TOP.getName()));
964 } else {
965 tree.add(Position.BOTTOM.endOfNav());
966 tree.add(HtmlTree.SPAN(HtmlStyle.skipNav, EMPTY_COMMENT)
967 .setId(SectionName.SKIP_NAVBAR_BOTTOM.getName()));
968 }
969 return tree;
970 }
971 }
|
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 package jdk.javadoc.internal.doclets.formats.html.markup;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Set;
30 import java.util.SortedSet;
31
32 import javax.lang.model.element.Element;
33 import javax.lang.model.element.ElementKind;
34 import javax.lang.model.element.ModuleElement;
35 import javax.lang.model.element.PackageElement;
36 import javax.lang.model.element.TypeElement;
37
38 import jdk.javadoc.internal.doclets.formats.html.AbstractMemberWriter;
39 import jdk.javadoc.internal.doclets.formats.html.Contents;
40 import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration;
41 import jdk.javadoc.internal.doclets.formats.html.HtmlOptions;
42 import jdk.javadoc.internal.doclets.formats.html.MarkerComments;
43 import jdk.javadoc.internal.doclets.formats.html.SectionName;
44 import jdk.javadoc.internal.doclets.toolkit.Content;
45 import jdk.javadoc.internal.doclets.toolkit.builders.MemberSummaryBuilder;
46 import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
47 import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
48 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
49 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
50 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable;
51
52 import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*;
53
54 /**
55 * Factory for navigation bar.
56 *
57 * <p>
58 * <b>This is NOT part of any supported API. If you write code that depends on this, you do so at
59 * your own risk. This code and its internal interfaces are subject to change or deletion without
60 * notice.</b>
61 */
62 public class Navigation {
63
64 private final HtmlConfiguration configuration;
65 private final HtmlOptions options;
66 private final Element element;
67 private final Contents contents;
68 private final DocPath path;
69 private final DocPath pathToRoot;
70 private final Links links;
71 private final PageMode documentedPage;
72 private Content navLinkModule;
73 private Content navLinkPackage;
74 private Content navLinkClass;
75 private MemberSummaryBuilder memberSummaryBuilder;
76 private boolean displaySummaryModuleDescLink;
77 private boolean displaySummaryModulesLink;
78 private boolean displaySummaryPackagesLink;
79 private boolean displaySummaryServicesLink;
80 private Content userHeader;
81 private Content userFooter;
82 private final String rowListTitle;
83 private final Content searchLabel;
84
85 private static final Content EMPTY_COMMENT = new Comment(" ");
117 Content startOfNav() {
118 return startOfNav;
119 }
120
121 Content endOfNav() {
122 return endOfNav;
123 }
124 }
125
126 /**
127 * Creates a {@code Navigation} object for a specific file, to be written in a specific HTML
128 * version.
129 *
130 * @param element element being documented. null if its not an element documentation page
131 * @param configuration the configuration object
132 * @param page the kind of page being documented
133 * @param path the DocPath object
134 */
135 public Navigation(Element element, HtmlConfiguration configuration, PageMode page, DocPath path) {
136 this.configuration = configuration;
137 this.options = configuration.getOptions();
138 this.element = element;
139 this.contents = configuration.contents;
140 this.documentedPage = page;
141 this.path = path;
142 this.pathToRoot = path.parent().invert();
143 this.links = new Links(path);
144 this.rowListTitle = configuration.getResources().getText("doclet.Navigation");
145 this.searchLabel = contents.getContent("doclet.search");
146 }
147
148 public Navigation setNavLinkModule(Content navLinkModule) {
149 this.navLinkModule = navLinkModule;
150 return this;
151 }
152
153 public Navigation setNavLinkPackage(Content navLinkPackage) {
154 this.navLinkPackage = navLinkPackage;
155 return this;
156 }
157
186 }
187
188 public Navigation setUserHeader(Content userHeader) {
189 this.userHeader = userHeader;
190 return this;
191 }
192
193 public Navigation setUserFooter(Content userFooter) {
194 this.userFooter = userFooter;
195 return this;
196 }
197
198 /**
199 * Add the links for the main navigation.
200 *
201 * @param tree the content tree to which the main navigation will added
202 */
203 private void addMainNavLinks(Content tree) {
204 switch (documentedPage) {
205 case OVERVIEW:
206 addActivePageLink(tree, contents.overviewLabel, options.createOverview);
207 addModuleLink(tree);
208 addPackageLink(tree);
209 addPageLabel(tree, contents.classLabel, true);
210 addPageLabel(tree, contents.useLabel, options.classUse);
211 addTreeLink(tree);
212 addDeprecatedLink(tree);
213 addIndexLink(tree);
214 addHelpLink(tree);
215 break;
216 case MODULE:
217 addOverviewLink(tree);
218 addActivePageLink(tree, contents.moduleLabel, configuration.showModules);
219 addPackageLink(tree);
220 addPageLabel(tree, contents.classLabel, true);
221 addPageLabel(tree, contents.useLabel, options.classUse);
222 addTreeLink(tree);
223 addDeprecatedLink(tree);
224 addIndexLink(tree);
225 addHelpLink(tree);
226 break;
227 case PACKAGE:
228 addOverviewLink(tree);
229 addModuleOfElementLink(tree);
230 addActivePageLink(tree, contents.packageLabel, true);
231 addPageLabel(tree, contents.classLabel, true);
232 if (options.classUse) {
233 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_USE,
234 contents.useLabel, "", ""));
235 }
236 if (options.createTree) {
237 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_TREE,
238 contents.treeLabel, "", ""));
239 }
240 addDeprecatedLink(tree);
241 addIndexLink(tree);
242 addHelpLink(tree);
243 break;
244 case CLASS:
245 addOverviewLink(tree);
246 addModuleOfElementLink(tree);
247 addPackageSummaryLink(tree);
248 addActivePageLink(tree, contents.classLabel, true);
249 if (options.classUse) {
250 addContentToTree(tree, links.createLink(DocPaths.CLASS_USE.resolve(path.basename()),
251 contents.useLabel));
252 }
253 if (options.createTree) {
254 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_TREE,
255 contents.treeLabel, "", ""));
256 }
257 addDeprecatedLink(tree);
258 addIndexLink(tree);
259 addHelpLink(tree);
260 break;
261 case USE:
262 addOverviewLink(tree);
263 addModuleOfElementLink(tree);
264 if (element instanceof PackageElement) {
265 addPackageSummaryLink(tree);
266 addPageLabel(tree, contents.classLabel, true);
267 } else {
268 addPackageOfElementLink(tree);
269 addContentToTree(tree, navLinkClass);
270 }
271 addActivePageLink(tree, contents.useLabel, options.classUse);
272 if (element instanceof PackageElement) {
273 addContentToTree(tree, links.createLink(DocPaths.PACKAGE_TREE, contents.treeLabel));
274 } else {
275 addContentToTree(tree, configuration.utils.isEnclosingPackageIncluded((TypeElement) element)
276 ? links.createLink(DocPath.parent.resolve(DocPaths.PACKAGE_TREE), contents.treeLabel)
277 : links.createLink(pathToRoot.resolve(DocPaths.OVERVIEW_TREE), contents.treeLabel));
278 }
279 addDeprecatedLink(tree);
280 addIndexLink(tree);
281 addHelpLink(tree);
282 break;
283 case TREE:
284 addOverviewLink(tree);
285 if (element == null) {
286 addPageLabel(tree, contents.moduleLabel, configuration.showModules);
287 addPageLabel(tree, contents.packageLabel, true);
288 } else {
289 addModuleOfElementLink(tree);
290 addPackageSummaryLink(tree);
291 }
292 addPageLabel(tree, contents.classLabel, true);
293 addPageLabel(tree, contents.useLabel, options.classUse);
294 addActivePageLink(tree, contents.treeLabel, options.createTree);
295 addDeprecatedLink(tree);
296 addIndexLink(tree);
297 addHelpLink(tree);
298 break;
299 case DEPRECATED:
300 case INDEX:
301 case HELP:
302 addOverviewLink(tree);
303 addModuleLink(tree);
304 addPackageLink(tree);
305 addPageLabel(tree, contents.classLabel, true);
306 addPageLabel(tree, contents.useLabel, options.classUse);
307 addTreeLink(tree);
308 if (documentedPage == PageMode.DEPRECATED) {
309 addActivePageLink(tree, contents.deprecatedLabel, !(options.noDeprecated
310 || options.noDeprecatedList));
311 } else {
312 addDeprecatedLink(tree);
313 }
314 if (documentedPage == PageMode.INDEX) {
315 addActivePageLink(tree, contents.indexLabel, options.createIndex);
316 } else {
317 addIndexLink(tree);
318 }
319 if (documentedPage == PageMode.HELP) {
320 addActivePageLink(tree, contents.helpLabel, !options.noHelp);
321 } else {
322 addHelpLink(tree);
323 }
324 break;
325 case ALLCLASSES:
326 case ALLPACKAGES:
327 case CONSTANTVALUES:
328 case SERIALIZEDFORM:
329 case SYSTEMPROPERTIES:
330 addOverviewLink(tree);
331 addModuleLink(tree);
332 addPackageLink(tree);
333 addPageLabel(tree, contents.classLabel, true);
334 addPageLabel(tree, contents.useLabel, options.classUse);
335 addTreeLink(tree);
336 addDeprecatedLink(tree);
337 addIndexLink(tree);
338 addHelpLink(tree);
339 break;
340 case DOCFILE:
341 addOverviewLink(tree);
342 addModuleOfElementLink(tree);
343 addContentToTree(tree, navLinkPackage);
344 addPageLabel(tree, contents.classLabel, true);
345 addPageLabel(tree, contents.useLabel, options.classUse);
346 addTreeLink(tree);
347 addDeprecatedLink(tree);
348 addIndexLink(tree);
349 addHelpLink(tree);
350 break;
351 default:
352 break;
353 }
354 }
355
356 /**
357 * Add the summary links to the sub-navigation.
358 *
359 * @param tree the content tree to which the sub-navigation will added
360 */
361 private void addSummaryLinks(Content tree) {
362 List<Content> listContents = new ArrayList<>();
363 switch (documentedPage) {
364 case CLASS:
365 if (element.getKind() == ElementKind.ANNOTATION_TYPE) {
768 liContent.add(Entity.NO_BREAK_SPACE);
769 }
770 tree.add(liContent);
771 count++;
772 }
773 }
774
775 private void addActivePageLink(Content tree, Content label, boolean display) {
776 if (display) {
777 tree.add(HtmlTree.LI(HtmlStyle.navBarCell1Rev, label));
778 }
779 }
780
781 private void addPageLabel(Content tree, Content label, boolean display) {
782 if (display) {
783 tree.add(HtmlTree.LI(label));
784 }
785 }
786
787 private void addOverviewLink(Content tree) {
788 if (options.createOverview) {
789 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(DocPaths.INDEX),
790 contents.overviewLabel, "", "")));
791 }
792 }
793
794 private void addModuleLink(Content tree) {
795 if (configuration.showModules) {
796 if (configuration.modules.size() == 1) {
797 ModuleElement mdle = configuration.modules.first();
798 boolean included = configuration.utils.isIncluded(mdle);
799 tree.add(HtmlTree.LI((included)
800 ? links.createLink(pathToRoot.resolve(configuration.docPaths.moduleSummary(mdle)), contents.moduleLabel, "", "")
801 : contents.moduleLabel));
802 } else if (!configuration.modules.isEmpty()) {
803 addPageLabel(tree, contents.moduleLabel, true);
804 }
805 }
806 }
807
808 private void addModuleOfElementLink(Content tree) {
834 tree.add(HtmlTree.LI(links.createLink(crossPkgLink, contents.packageLabel)));
835 } else {
836 tree.add(HtmlTree.LI(contents.packageLabel));
837 }
838 }
839 } else if (!configuration.packages.isEmpty()) {
840 addPageLabel(tree, contents.packageLabel, true);
841 }
842 }
843
844 private void addPackageOfElementLink(Content tree) {
845 tree.add(HtmlTree.LI(links.createLink(DocPath.parent.resolve(DocPaths.PACKAGE_SUMMARY),
846 contents.packageLabel)));
847 }
848
849 private void addPackageSummaryLink(Content tree) {
850 tree.add(HtmlTree.LI(links.createLink(DocPaths.PACKAGE_SUMMARY, contents.packageLabel)));
851 }
852
853 private void addTreeLink(Content tree) {
854 if (options.createTree) {
855 List<PackageElement> packages = new ArrayList<>(configuration.getSpecifiedPackageElements());
856 DocPath docPath = packages.size() == 1 && configuration.getSpecifiedTypeElements().isEmpty()
857 ? pathToRoot.resolve(configuration.docPaths.forPackage(packages.get(0)).resolve(DocPaths.PACKAGE_TREE))
858 : pathToRoot.resolve(DocPaths.OVERVIEW_TREE);
859 tree.add(HtmlTree.LI(links.createLink(docPath, contents.treeLabel, "", "")));
860 }
861 }
862
863 private void addDeprecatedLink(Content tree) {
864 if (!(options.noDeprecated || options.noDeprecatedList)) {
865 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(DocPaths.DEPRECATED_LIST),
866 contents.deprecatedLabel, "", "")));
867 }
868 }
869
870 private void addIndexLink(Content tree) {
871 if (options.createIndex) {
872 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(
873 (options.splitIndex
874 ? DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1))
875 : DocPaths.INDEX_ALL)),
876 contents.indexLabel, "", "")));
877 }
878 }
879
880 private void addHelpLink(Content tree) {
881 if (!options.noHelp) {
882 String helpfile = options.helpFile;
883 DocPath helpfilenm;
884 if (helpfile.isEmpty()) {
885 helpfilenm = DocPaths.HELP_DOC;
886 } else {
887 DocFile file = DocFile.createFileForInput(configuration, helpfile);
888 helpfilenm = DocPath.create(file.getName());
889 }
890 tree.add(HtmlTree.LI(links.createLink(pathToRoot.resolve(helpfilenm),
891 contents.helpLabel, "", "")));
892 }
893 }
894
895 private void addSearch(Content tree) {
896 String searchValueId = "search";
897 String reset = "reset";
898 HtmlTree inputText = HtmlTree.INPUT("text", searchValueId, searchValueId);
899 HtmlTree inputReset = HtmlTree.INPUT(reset, reset, reset);
900 HtmlTree searchDiv = HtmlTree.DIV(HtmlStyle.navListSearch, HtmlTree.LABEL(searchValueId, searchLabel));
901 searchDiv.add(inputText);
902 searchDiv.add(inputReset);
903 tree.add(searchDiv);
904 }
905
906 /**
907 * Get the navigation content.
908 *
909 * @param top true if the top navigation bar is to be printed
910 * @return the navigation contents
911 */
912 public Content getContent(boolean top) {
913 if (options.noNavbar) {
914 return new ContentBuilder();
915 }
916 Content tree = HtmlTree.NAV();
917 HtmlTree navDiv = new HtmlTree(HtmlTag.DIV);
918 Content skipNavLinks = contents.getContent("doclet.Skip_navigation_links");
919 if (top) {
920 tree.add(Position.TOP.startOfNav());
921 navDiv.setStyle(HtmlStyle.topNav)
922 .setId(SectionName.NAVBAR_TOP.getName())
923 .add(HtmlTree.DIV(HtmlStyle.skipNav,
924 links.createLink(SectionName.SKIP_NAVBAR_TOP, skipNavLinks,
925 skipNavLinks.toString(), "")));
926 } else {
927 tree.add(Position.BOTTOM.startOfNav());
928 navDiv.setStyle(HtmlStyle.bottomNav)
929 .setId(SectionName.NAVBAR_BOTTOM.getName())
930 .add(HtmlTree.DIV(HtmlStyle.skipNav,
931 links.createLink(SectionName.SKIP_NAVBAR_BOTTOM, skipNavLinks,
932 skipNavLinks.toString(), "")));
933 }
938 navList.put(HtmlAttr.TITLE, rowListTitle);
939 addMainNavLinks(navList);
940 navDiv.add(navList);
941 Content aboutDiv = HtmlTree.DIV(HtmlStyle.aboutLanguage, top ? userHeader : userFooter);
942 navDiv.add(aboutDiv);
943 tree.add(navDiv);
944 HtmlTree subDiv = new HtmlTree(HtmlTag.DIV);
945 subDiv.setStyle(HtmlStyle.subNav);
946 HtmlTree div = new HtmlTree(HtmlTag.DIV);
947 // Add the summary links if present.
948 HtmlTree ulNavSummary = new HtmlTree(HtmlTag.UL);
949 ulNavSummary.setStyle(HtmlStyle.subNavList);
950 addSummaryLinks(ulNavSummary);
951 div.add(ulNavSummary);
952 // Add the detail links if present.
953 HtmlTree ulNavDetail = new HtmlTree(HtmlTag.UL);
954 ulNavDetail.setStyle(HtmlStyle.subNavList);
955 addDetailLinks(ulNavDetail);
956 div.add(ulNavDetail);
957 subDiv.add(div);
958 if (top && options.createIndex) {
959 addSearch(subDiv);
960 }
961 tree.add(subDiv);
962 if (top) {
963 tree.add(Position.TOP.endOfNav());
964 tree.add(HtmlTree.SPAN(HtmlStyle.skipNav, EMPTY_COMMENT)
965 .setId(SectionName.SKIP_NAVBAR_TOP.getName()));
966 } else {
967 tree.add(Position.BOTTOM.endOfNav());
968 tree.add(HtmlTree.SPAN(HtmlStyle.skipNav, EMPTY_COMMENT)
969 .setId(SectionName.SKIP_NAVBAR_BOTTOM.getName()));
970 }
971 return tree;
972 }
973 }
|