-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCheckboxMenuItem.java
More file actions
141 lines (121 loc) · 3.08 KB
/
Copy pathCheckboxMenuItem.java
File metadata and controls
141 lines (121 loc) · 3.08 KB
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
package org.lcdproc.lcdjava;
/**
* CheckboxnMenuItem.
* <p>Item to display a slectable status indicator
* @author StefanKrupop
*/
public class CheckboxMenuItem extends AbstractMenuItem
{
public enum CheckboxValue {
/**
* Off
*/
Off("off"),
/**
* On
*/
On("on"),
/**
* Grayed out
*/
Gray("gray");
public String val;
CheckboxValue(String val) {
this.val = val;
}
}
private CheckboxValue _value;
private boolean _allowGray;
/**
* Constructor.
* @param id the of the action.
* @param menu the Submenu that knows about this MenuItem.
*/
protected CheckboxMenuItem(String id, Submenu menu)
{
super(id, menu);
_allowGray = false;
_value = CheckboxValue.Off;
}
/**
* Get the menu item type.
* @return the menu item type.
*/
public String getType()
{
return MENUITEM_CHECKBOX;
}
/**
* Sets if a grayed checkbox is allowed
* @param allowGray whether grayed checkbox is allowed
*/
public void setAllowGray(boolean allowGray) {
_allowGray = allowGray;
update();
}
/**
* Sets current value of a checkbox
* @param value current status
*/
public void setValue(CheckboxValue value) {
_value = value;
update();
}
/**
* Sets current value of a checkbox but does not send the change to LCDd
* @param value current status
*/
public void setValueNoUpdate(CheckboxValue value) {
_value = value;
}
/**
* Gets the current status of the checkbox
* @return status of the checkbox
*/
public CheckboxValue getValue() {
return _value;
}
/**
* Gets the current status of the checkbox
* @return whether the checkbox is On
*/
public boolean isSelected() {
return _value.equals(CheckboxValue.On);
}
@Override
public String getData() {
return super.getData() + " -value " + _value.val + " -allow_gray " + (_allowGray ? "true" : "false");
}
/**
* Construct a new CheckboxMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @return a new ActionMenuItem.
*/
public static CheckboxMenuItem construct(Submenu menu, String text)
{
return construct(menu, text, false);
}
/**
* Construct a new ActionMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @param allowGray whether the "Gray" state is allowed
* @return a new ActionMenuItem.
*/
public static CheckboxMenuItem construct(Submenu menu, String text, boolean allowGray)
{
CheckboxMenuItem menuItem = null;
try
{
menuItem = (CheckboxMenuItem)menu.constructMenuItem(MENUITEM_CHECKBOX);
menuItem.setAllowGray(allowGray);
menuItem.setText(text);
}
catch (LCDException e) //NOPMD
{
// Supress, would only get one if we asked for an invalid menu item.
}
return menuItem;
}
}