1 /*
2 * Copyright 2012-2025 Christophe Friederich
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.devacfr.maven.skins.reflow.model;
17
18 import javax.annotation.Nonnull;
19 import org.devacfr.maven.skins.reflow.ISkinConfig;
20
21 /**
22 * @author devacfr
23 * @since 2.0
24 */
25 public class TocTopBar extends Toc<TocTopBar> {
26
27 /** no flatten attribute (default) - flatten if single top heading */
28 private boolean flatten = false;
29
30 /** -1 or no numberItems attribute (default) - unlimited */
31 private int numberItems = -1;
32
33 /**
34 * Default constructor.
35 *
36 * @param config
37 * a config (can <b>not</b> be {@code null}).
38 */
39 public TocTopBar(final @Nonnull ISkinConfig config) {
40 super(config, "top", "navbar");
41 this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, "light"));
42 this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, "light"));
43 this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null));
44 this.withFlatten(config.getAttributeValue(COMPONENT, "flatten", Boolean.class, false))
45 .withNumberItems(config.getAttributeValue(COMPONENT, "numberItems", Integer.class, -1))
46 .withEnabled(true);
47 if (isEnabled()) {
48 this.addCssOptions("toc-top-enabled");
49 }
50 }
51
52 /**
53 * Gets the indicating whether is flatten.
54 *
55 * @return Returns {@code true} if is flatten, otherwise {@code false}.
56 */
57 public boolean isFlatten() {
58 return flatten;
59 }
60
61 /**
62 * Sets the indicating whether is flatten.
63 *
64 * @param flatten
65 * {@code true} to flat.
66 * @return Returns the fluent instance.
67 */
68 protected TocTopBar withFlatten(final boolean flatten) {
69 this.flatten = flatten;
70 return self();
71 }
72
73 /**
74 * @return Returns the number of items to display.
75 */
76 public int getNumberItems() {
77 return numberItems;
78 }
79
80 /**
81 * Sets the number of items to display.
82 *
83 * @param numberItems
84 * -1 or the number of items to display
85 * @return Returns the fluent instance.
86 */
87 protected TocTopBar withNumberItems(final int numberItems) {
88 this.numberItems = numberItems;
89 return self();
90 }
91 }