From 1418898a611a9dbc5051840c2252088fcd922b66 Mon Sep 17 00:00:00 2001 From: Joe Ross Date: Tue, 30 Dec 2014 18:13:16 -0800 Subject: Add Live Window widget for 3 axis acclerometer. Needed to fix artf3902 Change-Id: Ie38fb81a818b7607fabf7f7855249d0e7ea78147 --- .../elements/LiveWindowWidgetRegistrar.java | 1 + .../elements/ThreeAxisAccelerometer.java | 78 ++++++++++++++++++++++ .../types/named/ThreeAxisAccelerometerType.java | 30 +++++++++ 3 files changed, 109 insertions(+) create mode 100644 smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java create mode 100644 smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java (limited to 'smartdashboard') diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java index d6b660f..0faa69d 100644 --- a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java +++ b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/LiveWindowWidgetRegistrar.java @@ -22,6 +22,7 @@ public class LiveWindowWidgetRegistrar { DisplayElementRegistry.registerWidget(EncoderDisplay.class); DisplayElementRegistry.registerWidget(ServoController.class); DisplayElementRegistry.registerWidget(PowerDistributionPanel.class); + DisplayElementRegistry.registerWidget(ThreeAxisAccelerometer.class); } } diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java new file mode 100644 index 0000000..1d54cf6 --- /dev/null +++ b/smartdashboard/src/edu/wpi/first/smartdashboard/livewindow/elements/ThreeAxisAccelerometer.java @@ -0,0 +1,78 @@ +package edu.wpi.first.smartdashboard.livewindow.elements; + +import edu.wpi.first.smartdashboard.gui.elements.bindings.AbstractTableWidget; +import edu.wpi.first.smartdashboard.properties.Property; +import edu.wpi.first.smartdashboard.types.DataType; +import edu.wpi.first.smartdashboard.types.named.ThreeAxisAccelerometerType; +import edu.wpi.first.wpilibj.tables.ITableListener; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import javax.swing.JLabel; + + +/** + * Displays the X, Y and Z accelerations from a 3 axis accelerometer + */ +public class ThreeAxisAccelerometer extends AbstractTableWidget implements ITableListener { + + public static final DataType[] TYPES = {ThreeAxisAccelerometerType.get()}; + + private final UneditableNumberField x = new UneditableNumberField(); + private final UneditableNumberField y = new UneditableNumberField(); + private final UneditableNumberField z = new UneditableNumberField(); + private JLabel xLabel; + private JLabel yLabel; + private JLabel zLabel; + + /** + * @inheritdoc + */ + public void init() { + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + + nameTag = new NameTag(getFieldName()); + add(nameTag); + + c.gridy=1; + c.gridx=0; + xLabel = new JLabel("X"); + add(xLabel, c); + c.gridx=1; + x.setFocusable(false); + setNumberBinding("X", x); + x.setColumns(10); + add(x,c); + + c.gridy=2; + c.gridx=0; + yLabel = new JLabel("Y"); + add(yLabel, c); + c.gridx=1; + y.setFocusable(false); + setNumberBinding("Y", y); + y.setColumns(10); + add(y,c); + + c.gridy=3; + c.gridx=0; + zLabel = new JLabel("Z"); + add(zLabel, c); + c.gridx=1; + z.setFocusable(false); + setNumberBinding("Z", z); + z.setColumns(10); + add(z,c); + + setMaximumSize(new Dimension(Integer.MAX_VALUE, getPreferredSize().height)); + + revalidate(); + repaint(); + } + + @Override + public void propertyChanged(Property property) { + } + +} diff --git a/smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java b/smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java new file mode 100644 index 0000000..d79a690 --- /dev/null +++ b/smartdashboard/src/edu/wpi/first/smartdashboard/types/named/ThreeAxisAccelerometerType.java @@ -0,0 +1,30 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package edu.wpi.first.smartdashboard.types.named; + +import edu.wpi.first.smartdashboard.livewindow.elements.ThreeAxisAccelerometer; +import edu.wpi.first.smartdashboard.types.NamedDataType; + +/** + * + * @author Sam + */ +public class ThreeAxisAccelerometerType extends NamedDataType { + + public static final String LABEL = "3AxisAccelerometer"; + + private ThreeAxisAccelerometerType() { + super(LABEL, ThreeAxisAccelerometer.class); + } + + public static NamedDataType get() { + if (NamedDataType.get(LABEL) != null) { + return NamedDataType.get(LABEL); + } else { + return new ThreeAxisAccelerometerType(); + } + } + +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf