summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johnson <johnson.peter@gmail.com>2016-01-04 16:06:35 -0800
committerPeter Johnson <johnson.peter@gmail.com>2016-01-04 16:06:35 -0800
commit1f95428675411449cfbc4d7c55b9cbabb7deb15e (patch)
tree048996bcf718747a2482c8404aa2176824151ffb
parent8792ee04d0405df10386706e4eb138e475c20737 (diff)
CANSpeedController: Use CardLayout.
This fixes formatting and resize issues that resulted from manually adding and removing individual panel components. Change-Id: Ic507dc0f92ce4e3e6560bd31ea83129958a460ed
-rw-r--r--smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/CANSpeedController.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/CANSpeedController.java b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/CANSpeedController.java
index faad078..a9e8489 100644
--- a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/CANSpeedController.java
+++ b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/CANSpeedController.java
@@ -61,8 +61,12 @@ public class CANSpeedController extends AbstractTableWidget implements Controlle
* Control panel containing the PID editor / speed controller editor.
*/
private JPanel controlPanel;
+ private JPanel disabledControlPanel;
private PIDEditor pidControlPanel;
private SpeedController normalControlPanel;
+ private static final String DISABLED_PANEL = "Disabled";
+ private static final String PID_PANEL = "PID";
+ private static final String NORMAL_PANEL = "Normal";
private ActionListener modeSelection = e -> {
int m = modeBox.getSelectedIndex();
@@ -80,10 +84,13 @@ public class CANSpeedController extends AbstractTableWidget implements Controlle
public void init() {
nameTag = new NameTag(getFieldName());
headerPanel = new JPanel();
- controlPanel = new JPanel();
+ controlPanel = new JPanel(new CardLayout());
+ disabledControlPanel = new JPanel();
createPIDControlPanel();
createNormalControlPanel();
- controlPanel.add(normalControlPanel);
+ controlPanel.add(disabledControlPanel, DISABLED_PANEL);
+ controlPanel.add(normalControlPanel, NORMAL_PANEL);
+ controlPanel.add(pidControlPanel, PID_PANEL);
headerPanel.setLayout(new GridBagLayout());
GridBagConstraints headerConstraints = new GridBagConstraints();
@@ -192,23 +199,18 @@ public class CANSpeedController extends AbstractTableWidget implements Controlle
// empty (follower or disabled)
normalControlPanel.reset();
pidControlPanel.reset();
- controlPanel.removeAll();
- controlPanel.setSize(0, 0);
+ ((CardLayout)controlPanel.getLayout()).show(controlPanel, DISABLED_PANEL);
} else if (isPID()) {
- if (pidControlPanel.getParent() != controlPanel) {
- // set control to PID and resize
+ if (!pidControlPanel.isVisible()) {
+ // set control to PID
normalControlPanel.reset();
- controlPanel.removeAll();
- controlPanel.add(pidControlPanel);
- controlPanel.setSize(pidControlPanel.getSize());
+ ((CardLayout)controlPanel.getLayout()).show(controlPanel, PID_PANEL);
}
} else {
- if (normalControlPanel.getParent() != controlPanel) {
- // set control to normal and resize
+ if (!normalControlPanel.isVisible()) {
+ // set control to normal
pidControlPanel.reset();
- controlPanel.removeAll();
- controlPanel.add(normalControlPanel);
- controlPanel.setSize(normalControlPanel.getSize());
+ ((CardLayout)controlPanel.getLayout()).show(controlPanel, NORMAL_PANEL);
}
// set the range on the slider depending on the mode
switch(mode) {