-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNumericMenuItem.java
More file actions
149 lines (133 loc) · 3.61 KB
/
NumericMenuItem.java
File metadata and controls
149 lines (133 loc) · 3.61 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
package org.lcdproc.lcdjava;
/**
* NumericMenuItem.
* <p>Allows the user to input an integer value. Is visible as a text. When
* selected, a screen comes up that shows the current numeric value, that you
* can edit with the cursor keys and Enter. The number is ended by selecting
* a 'null' input digit. After that the menu returns.
* @author StefanKrupop
*/
public class NumericMenuItem extends AbstractMenuItem
{
private int _value;
private int _minvalue;
private int _maxvalue;
/**
* Constructor.
* @param id the of the action.
* @param menu the Submenu that knows about this MenuItem.
*/
protected NumericMenuItem(String id, Submenu menu)
{
super(id, menu);
_value = 0;
_minvalue = 0;
_maxvalue = 100;
}
/**
* Get the menu item type.
* @return the menu item type.
*/
public String getType()
{
return MENUITEM_NUMERIC;
}
/**
* Sets current value of the entry
* @param value current value
*/
public void setValue(int value) {
if (value >= _minvalue && value <= _maxvalue) {
_value = value;
update();
}
}
/**
* Sets current value of the entry but does not send the change to LCDd
* @param value current value
*/
public void setValueNoUpdate(int value) {
if (value >= _minvalue && value <= _maxvalue) {
_value = value;
}
}
/**
* Gets the current value of the entry
* @return value of the entry
*/
public int getValue() {
return _value;
}
/**
* Sets minimum value of the entry
* @param value min value
*/
public void setMinValue(int value) {
_minvalue = value;
if (_value < _minvalue) {
_value = _minvalue;
}
if (_minvalue <= _maxvalue) {
update();
}
}
/**
* Sets maximum value of the entry
* @param value max value
*/
public void setMaxValue(int value) {
_maxvalue = value;
if (_value > _maxvalue) {
_value = _maxvalue;
}
if (_maxvalue >= _minvalue) {
update();
}
}
@Override
public String getData() {
StringBuilder strb = new StringBuilder();
strb.append(super.getData());
strb.append(" -value ");
strb.append(_value);
strb.append(" -minvalue ");
strb.append(_minvalue);
strb.append(" -maxvalue ");
strb.append(_maxvalue);
return strb.toString();
}
/**
* Construct a new NumericMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @return a new NumericMenuItem.
*/
public static NumericMenuItem construct(Submenu menu, String text)
{
return construct(menu, text, 0, 100);
}
/**
* Construct a new NumericMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @param minValue the minimum value of the entry
* @param maxValue the maximum value of the entry
* @return a new NumericMenuItem.
*/
public static NumericMenuItem construct(Submenu menu, String text, int minValue, int maxValue)
{
NumericMenuItem menuItem = null;
try
{
menuItem = (NumericMenuItem)menu.constructMenuItem(MENUITEM_NUMERIC);
menuItem.setText(text);
menuItem.setMinValue(minValue);
menuItem.setMaxValue(maxValue);
}
catch (LCDException e) //NOPMD
{
// Supress, would only get one if we asked for an invalid menu item.
}
return menuItem;
}
}