mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
Reduced duplication between formatting scripts with Task base class (#80)
Also added scripts for EOF newline management and for removing trailing whitespace. configure.bat was rewritten to use CRLF line endings. Documentation for the existing scripts was also improved.
This commit is contained in:
committed by
Peter Johnson
parent
ea6876e81f
commit
aafca4ed7f
@@ -32,13 +32,13 @@ import gazebo.msgs.GzDriverStation.DriverStation;
|
||||
public class DS {
|
||||
private JoystickProvider joystickProvider;
|
||||
private JoystickList joysticks;
|
||||
|
||||
|
||||
private JFrame mainframe;
|
||||
private JPanel modePanel;
|
||||
private ActionListener modeListener;
|
||||
private ButtonGroup modes;
|
||||
private JButton enable, refresh;
|
||||
|
||||
|
||||
public enum State {
|
||||
Disabled, Teleop, Autonomous, Test;
|
||||
}
|
||||
@@ -46,14 +46,14 @@ public class DS {
|
||||
private State state = State.Teleop;
|
||||
private DriverStation.State protoState = DriverStation.State.TELEOP;
|
||||
private Publisher<DriverStation> pub;
|
||||
|
||||
|
||||
public DS(JoystickProvider joystickProvider) {
|
||||
this.joystickProvider = joystickProvider;
|
||||
mainframe = new JFrame();
|
||||
mainframe.setTitle("FRC Simulation DriverStation");
|
||||
mainframe.setLayout(new GridBagLayout());
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
|
||||
|
||||
makeModeButtons(constraints);
|
||||
mainframe.pack();
|
||||
constraints.gridy = 1;
|
||||
@@ -65,15 +65,15 @@ public class DS {
|
||||
mainframe.pack();
|
||||
constraints.gridy = 1;
|
||||
makeRefreshButton(constraints);
|
||||
|
||||
|
||||
mainframe.pack();
|
||||
mainframe.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
private void makeModeButtons(GridBagConstraints constraints) {
|
||||
modePanel = new JPanel();
|
||||
modePanel.setLayout(new BoxLayout(modePanel, BoxLayout.PAGE_AXIS));
|
||||
|
||||
|
||||
modeListener = new ModeAction(this);
|
||||
JRadioButton teleop = new JRadioButton("Teleop");
|
||||
teleop.setActionCommand(State.Teleop.toString());
|
||||
@@ -85,7 +85,7 @@ public class DS {
|
||||
test.setActionCommand(State.Test.toString());
|
||||
test.addActionListener(modeListener);
|
||||
teleop.setSelected(true);
|
||||
|
||||
|
||||
modes = new ButtonGroup();
|
||||
modes.add(teleop);
|
||||
modes.add(auto);
|
||||
@@ -95,14 +95,14 @@ public class DS {
|
||||
modePanel.add(test);
|
||||
mainframe.add(modePanel, constraints);
|
||||
}
|
||||
|
||||
|
||||
private void makeEnableButton(GridBagConstraints constraints) {
|
||||
enable = new JButton("Enable");
|
||||
enable.addActionListener(new EnableAction(this));
|
||||
enable.setPreferredSize(new Dimension(modePanel.getSize().width, 50));
|
||||
mainframe.add(enable, constraints);
|
||||
}
|
||||
|
||||
|
||||
private void makeJoystickUI(GridBagConstraints constraints) {
|
||||
joysticks = new JoystickList(joystickProvider);
|
||||
mainframe.add(joysticks, constraints);
|
||||
@@ -117,19 +117,19 @@ public class DS {
|
||||
}
|
||||
joysticks.setListData(sticks);
|
||||
}
|
||||
|
||||
|
||||
private void makeRefreshButton(GridBagConstraints constraints) {
|
||||
refresh = new JButton("Refresh Joysticks");
|
||||
refresh.addActionListener(new RefreshAction(this));
|
||||
refresh.setPreferredSize(new Dimension(joysticks.getSize().width, 50));
|
||||
mainframe.add(refresh, constraints);
|
||||
}
|
||||
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
enable.setText(enabled ? "Disable" : "Enable");
|
||||
}
|
||||
|
||||
|
||||
public State getState() {
|
||||
return enabled ? state : State.Disabled;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.awt.event.ActionListener;
|
||||
|
||||
public class EnableAction implements ActionListener {
|
||||
private DS ds;
|
||||
|
||||
|
||||
public EnableAction(DS ds) {
|
||||
this.ds = ds;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class FakeJoystick implements ISimJoystick {
|
||||
public String getName() {
|
||||
return "Empty Joystick";
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class JoystickList extends JList<ISimJoystick> {
|
||||
int index = Integer.parseInt(indexString);
|
||||
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
|
||||
int dropTargetIndex = dl.getIndex();
|
||||
|
||||
|
||||
list.moveElement(index, dropTargetIndex);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -18,11 +18,11 @@ import net.java.games.input.ControllerEnvironment;
|
||||
|
||||
public class JoystickProvider {
|
||||
List<ISimJoystick> joysticks;
|
||||
|
||||
|
||||
public JoystickProvider() {
|
||||
scanForJoysticks();
|
||||
}
|
||||
|
||||
|
||||
public List<ISimJoystick> scanForJoysticks() {
|
||||
List<ISimJoystick> foundControllers = new ArrayList<>();
|
||||
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
|
||||
@@ -30,21 +30,21 @@ public class JoystickProvider {
|
||||
for(int i = 0; i < controllers.length; i++){
|
||||
Controller controller = controllers[i];
|
||||
if (controller.getType() == Controller.Type.STICK
|
||||
|| controller.getType() == Controller.Type.GAMEPAD
|
||||
|| controller.getType() == Controller.Type.GAMEPAD
|
||||
|| controller.getType() == Controller.Type.WHEEL
|
||||
|| controller.getType() == Controller.Type.FINGERSTICK) {
|
||||
foundControllers.add(new SimJoystick(controller));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
joysticks = foundControllers;
|
||||
return foundControllers;
|
||||
}
|
||||
|
||||
|
||||
public List<ISimJoystick> getJoysticks() {
|
||||
return joysticks;
|
||||
}
|
||||
|
||||
|
||||
public void setJoysticks(List<ISimJoystick> joysticks) {
|
||||
this.joysticks = joysticks;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.gazebosim.transport.SubscriberCallback;
|
||||
public class Main {
|
||||
private static double simTime = 0;
|
||||
private static Subscriber<Float64> sub;
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
Node node = new Node("frc");
|
||||
try {
|
||||
|
||||
@@ -12,11 +12,11 @@ import java.awt.event.ActionListener;
|
||||
|
||||
public class ModeAction implements ActionListener {
|
||||
private DS ds;
|
||||
|
||||
|
||||
public ModeAction(DS ds) {
|
||||
this.ds = ds;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ds.setState(DS.State.valueOf(e.getActionCommand()));
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SimJoystick implements ISimJoystick {
|
||||
return controller.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class SimJoystick implements ISimJoystick {
|
||||
prevNode = node;
|
||||
prevI = i;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void publish() {
|
||||
controller.poll();
|
||||
|
||||
Reference in New Issue
Block a user