1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.devacfr.maven.skins.reflow.model;
20
21 import javax.annotation.Nonnull;
22
23 import org.devacfr.maven.skins.reflow.ISkinConfig;
24
25 /**
26 * @author devacfr
27 * @since 2.0
28 */
29 public class TocSidebar extends Toc<TocSidebar> {
30
31 /** fixed position by default */
32 private boolean fixed = true;
33
34 /** expanded by default. */
35 private boolean expanded = true;
36
37 /** auto expandable by default. */
38 private boolean autoExpandable = true;
39
40 /** heading level limit to display. all by default */
41 private int level = 0;
42
43 /**
44 * Default constructor.
45 *
46 * @param config
47 * a config (can <b>not</b> be {@code null}).
48 */
49 public TocSidebar(final @Nonnull ISkinConfig config) {
50 super("sidebar", "sidebar");
51 final String position = config.getAttributeValue("toc", "position", String.class, "fixed").toLowerCase();
52 this.withEnabled(true)
53 .withExpanded(config.getAttributeValue("toc", "expanded", Boolean.class, true))
54 .withAutoExpandable(config.getAttributeValue("toc", "autoExpandable", Boolean.class, true))
55 .withFixed("fixed".equals(position))
56 .withLevel(config.getAttributeValue("toc", "level", Integer.class, 0));
57 if (this.isEnabled()) {
58 this.addCssOptions("m-toc-sidebar-enabled");
59 }
60 if (isExpanded()) {
61 this.addCssOptions("m-toc-sidebar-expanded");
62 }
63 if (isAutoExpandable()) {
64 this.addCssOptions("m-toc-sidebar-autoexpandable");
65 }
66 if (isFixed()) {
67 this.addCssOptions("toc-sidebar-fixed");
68 } else {
69 this.addCssOptions("toc-sidebar-relative");
70 }
71 }
72
73 /**
74 * Gets the indicating whether is fixed.
75 *
76 * @return Returns {@code true} if is fixed, otherwise {@code false}.
77 */
78 public boolean isFixed() {
79 return fixed;
80 }
81
82 /**
83 * Sets the indicating whether is fixed.
84 *
85 * @param fixed
86 * {@code true} is fixed.
87 * @return Returns the fluent instance.
88 */
89 protected TocSidebar withFixed(final boolean fixed) {
90 this.fixed = fixed;
91 return self();
92 }
93
94 /**
95 * Gets the indicating whether is expanded.
96 *
97 * @return Returns {@code true} if is expanded, otherwise {@code false}.
98 */
99 public boolean isExpanded() {
100 return expanded;
101 }
102
103 /**
104 * Sets the indicating whether is expanded.
105 *
106 * @param expanded
107 * {@code true} is expanded.
108 * @return Returns the fluent instance.
109 */
110 protected TocSidebar withExpanded(final boolean expanded) {
111 this.expanded = expanded;
112 return self();
113 }
114
115 /**
116 * Gets the indicating whether is auto-expanded.
117 *
118 * @return Returns {@code true} if is expanded, otherwise {@code false}.
119 */
120 public boolean isAutoExpandable() {
121 return autoExpandable;
122 }
123
124 /**
125 * Sets the indicating whether is auto-expanded.
126 *
127 * @param autoExpandable
128 * {@code true} is auto-expanded.
129 * @return Returns the fluent instance.
130 */
131 protected TocSidebar withAutoExpandable(final boolean autoExpandable) {
132 this.autoExpandable = autoExpandable;
133 return self();
134 }
135
136 /**
137 * @return Returns the level limit to display.
138 */
139 public int getLevel() {
140 return level;
141 }
142
143 /**
144 * Sets the level limit to display
145 *
146 * @param level
147 * the level to use.
148 * @return Returns the fluent instance.
149 */
150 protected TocSidebar withLevel(final int level) {
151 if (level < 1) {
152 this.level = Integer.MAX_VALUE;
153 } else {
154 this.level = level;
155 }
156 return self();
157 }
158 }