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 TocTopBar extends Toc<TocTopBar> {
30
31 /** no flatten attribute (default) - flatten if single top heading */
32 private boolean flatten = false;
33
34 /** -1 or no numberItems attribute (default) - unlimited */
35 private int numberItems = -1;
36
37 /**
38 * Default constructor.
39 *
40 * @param config
41 * a config (can <b>not</b> be {@code null}).
42 */
43 public TocTopBar(final @Nonnull ISkinConfig config) {
44 super("top", "navbar");
45 this.setTheme(config.getAttributeValue(COMPONENT, "theme", String.class, "light"));
46 this.setBackground(config.getAttributeValue(COMPONENT, "background", String.class, "light"));
47 this.setCssClass(config.getAttributeValue(COMPONENT, "cssClass", String.class, null));
48 this.withFlatten(config.getAttributeValue(COMPONENT, "flatten", Boolean.class, false))
49 .withNumberItems(config.getAttributeValue(COMPONENT, "numberItems", Integer.class, -1))
50 .withEnabled(true);
51 if (isEnabled()) {
52 this.addCssOptions("m-toc-top-enabled");
53 }
54 }
55
56 /**
57 * Gets the indicating whether is flatten.
58 *
59 * @return Returns {@code true} if is flatten, otherwise {@code false}.
60 */
61 public boolean isFlatten() {
62 return flatten;
63 }
64
65 /**
66 * Sets the indicating whether is flatten.
67 *
68 * @param flatten
69 * {@code true} to flat.
70 * @return Returns the fluent instance.
71 */
72 protected TocTopBar withFlatten(final boolean flatten) {
73 this.flatten = flatten;
74 return self();
75 }
76
77 /**
78 * @return Returns the number of items to display.
79 */
80 public int getNumberItems() {
81 return numberItems;
82 }
83
84 /**
85 * Sets the number of items to display.
86 *
87 * @param numberItems
88 * -1 or the number of items to display
89 * @return Returns the fluent instance.
90 */
91 protected TocTopBar withNumberItems(final int numberItems) {
92 this.numberItems = numberItems;
93 return self();
94 }
95 }