-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAlphaMenuItem.java
More file actions
194 lines (173 loc) · 4.71 KB
/
AlphaMenuItem.java
File metadata and controls
194 lines (173 loc) · 4.71 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
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
package org.lcdproc.lcdjava;
/**
* AlphaMenuItem.
* <p>Is visible as a text. When selected, a screen comes up that shows the
* current string value, that you can edit with the cursor keys and Enter.
* The string is ended by selecting a 'null' input character. After that the
* menu returns.
* @author StefanKrupop
*/
public class AlphaMenuItem extends AbstractMenuItem
{
private String _value;
private int _minlength;
private int _maxlength;
private String _passwordchar;
private boolean _allowCaps;
private boolean _allowNonCaps;
private boolean _allowNumbers;
private String _allowedExtra;
/**
* Constructor.
* @param id the of the action.
* @param menu the Submenu that knows about this MenuItem.
*/
protected AlphaMenuItem(String id, Submenu menu)
{
super(id, menu);
_value = "";
_minlength = 0;
_maxlength = 10;
_passwordchar = "";
_allowCaps = true;
_allowNonCaps = true;
_allowNumbers = true;
_allowedExtra = "";
}
/**
* Get the menu item type.
* @return the menu item type.
*/
public String getType()
{
return MENUITEM_ALPHA;
}
/**
* Sets current value of the entry
* @param value current value
*/
public void setValue(String value) {
_value = value;
update();
}
/**
* Sets current value of the entry but does not send the change to LCDd
* @param value current value
*/
public void setValueNoUpdate(String value) {
_value = value;
}
/**
* Gets the currently set value
* @return value current value
*/
public String getValue() {
return _value;
}
/**
* Sets the minimum length of the string that can be entered
* @param value min length
*/
public void setMinLength(int value) {
_minlength = value;
update();
}
/**
* Sets the maximum length of the string that can be entered
* @param value max length
*/
public void setMaxLength(int value) {
_maxlength = value;
update();
}
/**
* Sets the character that should be displayed instead of typed characters
* @param value password character
*/
public void setPasswordChar(String value) {
_passwordchar = value;
update();
}
/**
* Sets if upper case characters can be entered
* @param value new state
*/
public void setAllowCaps(boolean value) {
_allowCaps = value;
update();
}
/**
* Sets if lower case characters can be entered
* @param value new state
*/
public void setAllowNonCaps(boolean value) {
_allowNonCaps = value;
update();
}
/**
* Sets if numbers can be entered
* @param value new state
*/
public void setAllowNumbers(boolean value) {
_allowNumbers = value;
update();
}
/**
* Sets additional characters that can be entered
* @param chars allowed characters
*/
public void setAllowExtra(String chars) {
_allowedExtra = chars;
update();
}
@Override
public String getData() {
StringBuilder strb = new StringBuilder();
strb.append(super.getData());
strb.append(" -value \"");
strb.append(_value);
strb.append("\" -minlength ");
strb.append(_minlength);
strb.append(" -maxlength ");
strb.append(_maxlength);
if (!_passwordchar.isEmpty()) {
strb.append(" -password_char \"");
strb.append(_passwordchar);
strb.append('"');
}
strb.append(" -allow_caps ");
strb.append(_allowCaps ? "true" : "false");
strb.append(" -allow_noncaps ");
strb.append(_allowNonCaps ? "true" : "false");
strb.append(" -allow_numbers ");
strb.append(_allowNumbers ? "true" : "false");
if (!_allowedExtra.isEmpty()) {
strb.append(" -allowed_extra \"");
strb.append(_allowedExtra);
strb.append('"');
}
return strb.toString();
}
/**
* Construct a new AlphaMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @param current the current string
* @return a new AlphaMenuItem.
*/
public static AlphaMenuItem construct(Submenu menu, String text, String current)
{
AlphaMenuItem menuItem = null;
try
{
menuItem = (AlphaMenuItem)menu.constructMenuItem(MENUITEM_ALPHA);
menuItem.setValue(current);
menuItem.setText(text);
}
catch (LCDException e) //NOPMD
{
// Supress, would only get one if we asked for an invalid menu item.
}
return menuItem;
}
}