Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
214 lines (189 loc) · 5.58 KB

File metadata and controls

214 lines (189 loc) · 5.58 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package org.lcdproc.lcdjava;
import java.util.HashMap;
import java.util.Map;
/**
* Submenu.
* <p>Displays the submenus name with tailing submenu marker
* @author StefanKrupop
*/
public class Submenu extends AbstractMenuItem
{
/**
* The LCD that owns this Submenu.
*/
private LCD _lcd;
/**
* A Map of MenuItems added to this Submenu.
*/
private Map<String, MenuItem> _menuItems;
/**
* The count of menu items we have created.
*/
private int _menuItemCounter;
/**
* Constructor.
* @param lcd the LCD server object.
* @param id the of the submenu.
* @param menu the Submenu that knows about this MenuItem.
*/
protected Submenu(LCD lcd, String id, Submenu menu)
{
super(id, menu);
_lcd = lcd;
_menuItems = new HashMap<String, MenuItem>();
}
public Submenu(LCD lcd) {
this(lcd, "", null);
_menu = this;
}
/**
* Get the menu item type.
* @return the menu item type.
*/
public String getType()
{
return MENUITEM_MENU;
}
/**
* Construct a new Submenu.
* @param menu the Submenu that owns the submenu.
* @param text the menu text.
* @return a new Submenu.
*/
public static Submenu construct(Submenu menu, String text)
{
Submenu menuItem = null;
try
{
menuItem = (Submenu)menu.constructMenuItem(MENUITEM_MENU);
menuItem.setText(text);
}
catch (LCDException e) //NOPMD
{
// Supress, would only get one if we asked for an invalid menu item.
}
return menuItem;
}
/**
* Create a MenuItem for this Submenu.
* @param type the menu item type, see {@link MenuItem} for a list of types.
* @return the created MenuItem.
* @throws LCDException if the menu item type is not recognized.
*/
public MenuItem constructMenuItem(String type)
throws LCDException
{
MenuItem item;
synchronized (this) {
if (type.equals(MENUITEM_MENU))
{
item = new Submenu(_lcd, getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_ACTION))
{
item = new ActionMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_CHECKBOX))
{
item = new CheckboxMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_RING))
{
item = new RingMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_SLIDER))
{
item = new SliderMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_NUMERIC))
{
item = new NumericMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_ALPHA))
{
item = new AlphaMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else if (type.equals(MENUITEM_IP))
{
item = new IpMenuItem(getID() + "_" + Integer.toString(_menuItemCounter), this);
}
else
{
throw new LCDException(
"Unable to create a menu item of type " + type);
}
_menuItemCounter++;
}
return item;
}
/**
* Add a MenuItem to this Submenu.
* @param item the MenuItem to add.
* @return whether or not the menu item was added successfully.
*/
protected boolean addItem(MenuItem item)
{
boolean success = false;
String itemId = item.getID();
synchronized (this) {
if (!_menuItems.containsKey(itemId))
{
_menuItems.put(itemId, item);
_lcd.write(LCD.CMD_MENU_ADD + "\"" + _id + "\"" + " " + itemId +
" " + item.getType() + " \"\"");
success = updateItem(item);
}
}
return success;
}
/**
* Update a MenuItem on this Submenu.
* @param item the MenuItem to update.
* @return whether or not the MenuItem was updated successfully.
*/
protected boolean updateItem(MenuItem item)
{
boolean success = false;
String itemId = item.getID();
synchronized (this) {
if (_menuItems.containsKey(itemId))
{
_lcd.write(LCD.CMD_MENU_SET + "\"" + _id + "\"" + " " + itemId +
" " + item.getData());
success = true;
}
}
return success;
}
/**
* Delete a MenuItem from this Submenu.
* @param item the MenuItem to delete.
*/
protected void removeItem(MenuItem item)
{
String itemId = item.getID();
synchronized (this) {
if (_menuItems.containsKey(itemId))
{
_lcd.write(LCD.CMD_MENU_DEL + "\"" + _id + "\"" + " " + itemId);
_menuItems.remove(itemId);
}
}
}
/**
* Return menu item with the given id
* @param id the id of the menu item
* @return the MenuItem or null when the ID does not exist
*/
public MenuItem getMenuItem(String id) {
return _menuItems.get(id);
}
/**
* Sets this menu as the current main menu
*/
public void setAsMainMenu() {
synchronized (this) {
_lcd.write(LCD.CMD_MENU_SET_MAIN + "\"" + _id + "\"");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.