]> git.basschouten.com Git - openhab-addons.git/blob
1af25b09438efc45c5bb525a2bf594319ea1bf40
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.yamahareceiver.internal.state;
14
15 import org.apache.commons.lang.StringUtils;
16 import org.openhab.binding.yamahareceiver.internal.protocol.xml.InputWithNavigationControlXML;
17
18 /**
19  * The current state of the navigation
20  *
21  * @author David Graeff - Initial contribution
22  */
23 public class NavigationControlState implements Invalidateable {
24     public String menuName = null;
25     public int menuLayer = -1;
26     public int currentLine = 0;
27     public int maxLine = -1;
28     public String items[] = new String[InputWithNavigationControlXML.MAX_PER_PAGE];
29
30     public String getCurrentItemName() {
31         if (currentLine < 1 || currentLine > items.length) {
32             return "";
33         }
34         return items[currentLine - 1];
35     }
36
37     public String getAllItemLabels() {
38         StringBuilder sb = new StringBuilder();
39         for (String item : items) {
40             if (StringUtils.isNotEmpty(item)) {
41                 sb.append(item);
42                 sb.append(',');
43             }
44         }
45         return sb.toString();
46     }
47
48     public void clearItems() {
49         for (int i = 0; i < items.length; ++i) {
50             items[i] = null;
51         }
52     }
53
54     @Override
55     public void invalidate() {
56         this.menuName = "N/A";
57         this.maxLine = 0;
58         this.currentLine = 0;
59         this.menuLayer = 0;
60     }
61 }