blob: bd0a77992ee867abbbc1ff3fd18ac227c66d4d09 (
plain)
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
|
package edu.wpi.first.smartdashboard.livewindow.elements;
import edu.wpi.first.smartdashboard.gui.elements.bindings.NumberBindable;
import edu.wpi.first.smartdashboard.gui.elements.bindings.AbstractTableWidget;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import edu.wpi.first.smartdashboard.gui.elements.*;
import edu.wpi.first.smartdashboard.properties.*;
import edu.wpi.first.smartdashboard.types.*;
import edu.wpi.first.smartdashboard.types.named.*;
/**
* Used to control SpeedControllers such as Victors.
* @author Sam
*/
public class SpeedController extends AbstractTableWidget implements Controller {
public static final DataType[] TYPES = {SpeedControllerType.get()};
private NumberSlider controller;
/** Used to turn off the speed controller */
private final JButton zeroButton = new JButton("Zero");
private final String defaultText = "0.0";
private final UneditableNumberField feedback = new UneditableNumberField();
private final NumberBindable valueEntry = getTableEntryBindable("Value");
@Override
public void init() {
nameTag = new NameTag(getFieldName());
controller = new NumberSlider(valueEntry);
controller.setMin(-1.0);
controller.setMax(1.0);
controller.setBindableValue(0.0);
controller.setSnapToTicks(false);
controller.setMajorTickSpacing(50);
controller.setPaintTicks(true);
feedback.setText(defaultText);
feedback.setColumns(4);
setNumberBinding("Value", new NumberMultiBindable(feedback));
controller.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
zeroButton.doClick();
}
}
});
feedback.setEditable(false);
zeroButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reset();
}
});
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
add(nameTag, c);
c.gridy = 1;
c.weightx = 1.0;
add(controller, c);
c.weightx = 0.0;
c.gridx = 2;
add(feedback, c);
c.gridx = 3;
add(zeroButton, c);
c.gridx = 4;
}
/**
* Resets the slider value to zero and tells the robot
* to turn the motor off.
*/
public void reset() {
controller.setBindableValue(0.0);
valueEntry.setBindableValue(0.0);
}
public void propertyChanged(Property property) {
}
}
|