]> git.basschouten.com Git - openhab-addons.git/blob
bd67650af9815277b64730467455b758c5fd87a3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.openhab.binding.yamahareceiver.internal.protocol.xml.InputWithNavigationControlXML;
16
17 /**
18  * The current state of the navigation
19  *
20  * @author David Graeff - Initial contribution
21  */
22 public class NavigationControlState implements Invalidateable {
23     public String menuName = null;
24     public int menuLayer = -1;
25     public int currentLine = 0;
26     public int maxLine = -1;
27     public String items[] = new String[InputWithNavigationControlXML.MAX_PER_PAGE];
28
29     public String getCurrentItemName() {
30         if (currentLine < 1 || currentLine > items.length) {
31             return "";
32         }
33         return items[currentLine - 1];
34     }
35
36     public String getAllItemLabels() {
37         StringBuilder sb = new StringBuilder();
38         for (String item : items) {
39             if (item != null && !item.isEmpty()) {
40                 sb.append(item);
41                 sb.append(',');
42             }
43         }
44         return sb.toString();
45     }
46
47     public void clearItems() {
48         for (int i = 0; i < items.length; ++i) {
49             items[i] = null;
50         }
51     }
52
53     @Override
54     public void invalidate() {
55         this.menuName = "N/A";
56         this.maxLine = 0;
57         this.currentLine = 0;
58         this.menuLayer = 0;
59     }
60 }