-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSliderMenuItem.java
More file actions
124 lines (110 loc) · 3.03 KB
/
SliderMenuItem.java
File metadata and controls
124 lines (110 loc) · 3.03 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
package org.lcdproc.lcdjava;
/**
* SliderMenuItem.
* <p>Is visible as a text. When selected, a screen comes up that shows a
* slider. You can set the slider using the cursor keys. When Enter is
* pressed, the menu returns.
* @author StefanKrupop
*/
public class SliderMenuItem extends NumericMenuItem
{
private String _mintext;
private String _maxtext;
private int _stepsize;
/**
* Constructor.
* @param id the of the action.
* @param menu the Submenu that knows about this MenuItem.
*/
protected SliderMenuItem(String id, Submenu menu)
{
super(id, menu);
_mintext = "";
_maxtext = "";
_stepsize = 1;
}
/**
* Get the menu item type.
* @return the menu item type.
*/
public String getType()
{
return MENUITEM_SLIDER;
}
/**
* Sets label for minimum value of the slider
* @param value text to be shown on left side of slider
*/
public void setMinText(String value) {
_mintext = value;
update();
}
/**
* Sets label for maximum value of the slider
* @param value text to be shown on right side of slider
*/
public void setMaxText(String value) {
_maxtext = value;
update();
}
/**
* Sets step size of the slider
* @param size step size
*/
public void setStepSize(int size) {
_stepsize = size;
update();
}
@Override
public String getData() {
StringBuilder strb = new StringBuilder();
strb.append(super.getData());
strb.append(" -stepsize ");
strb.append(_stepsize);
if (!_mintext.isEmpty()) {
strb.append(" -mintext \"");
strb.append(_mintext);
strb.append('"');
}
if (!_maxtext.isEmpty()) {
strb.append(" -maxtext \"");
strb.append(_maxtext);
strb.append('"');
}
return strb.toString();
}
/**
* Construct a new SliderMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @return a new SliderMenuItem.
*/
public static SliderMenuItem construct(Submenu menu, String text)
{
return construct(menu, text, 0, 100);
}
/**
* Construct a new SliderMenuItem.
* @param menu the Submenu that owns the menu item.
* @param text the menu text.
* @param minValue the minimum value of the slider
* @param maxValue the maximum value of the slider
* @return a new SliderMenuItem.
*/
public static SliderMenuItem construct(Submenu menu, String text, int minValue, int maxValue)
{
SliderMenuItem menuItem = null;
try
{
menuItem = (SliderMenuItem)menu.constructMenuItem(MENUITEM_SLIDER);
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;
}
}