Conversation
SamCarlberg
left a comment
There was a problem hiding this comment.
Thanks for contributing! This looks pretty good, but there are a few things (mostly small) that will need to be addressed
| final var array = new Boolean[newBooleans.length]; | ||
| IntStream.range(0, newBooleans.length).forEach(i -> array[i] = newBooleans[i]); |
There was a problem hiding this comment.
newBooleans.clone() would do this better
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/control/ArrayTableView.java
Show resolved
Hide resolved
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/control/ArrayTableView.java
Outdated
Show resolved
Hide resolved
...ins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/BooleanArrayWidget.java
Outdated
Show resolved
Hide resolved
| final var array = new Double[newDoubles.length]; | ||
| IntStream.range(0, newDoubles.length).forEach(i -> array[i] = newDoubles[i]); |
There was a problem hiding this comment.
Use newDoubles.clone() instead
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/NumberArrayWidget.java
Outdated
Show resolved
Hide resolved
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/StringArrayWidget.java
Show resolved
Hide resolved
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/StringArrayWidget.java
Outdated
Show resolved
Hide resolved
|
|
||
| @Description( | ||
| name = "Number Array", | ||
| dataTypes = double[].class, |
There was a problem hiding this comment.
float[] and long[] will need to be supported, too
There was a problem hiding this comment.
When I try to change the type from double[] to Number[],
diff --git a/plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/NumberArrayWidget.java b/plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/NumberArrayWidget.java
@@ -10,21 +10,19 @@
@Description(
name = "Number Array",
- dataTypes = double[].class,
+ dataTypes = Number[].class,
summary = "Displays an array of numbers"
)
-public final class NumberArrayWidget extends SimpleAnnotatedWidget<double[]> {
+public final class NumberArrayWidget extends SimpleAnnotatedWidget<Number[]> {
private final StackPane pane = new StackPane();
- private final ArrayTableView<Double> table = new ArrayTableView<>();
+ private final ArrayTableView<Number> table = new ArrayTableView<>();
@SuppressWarnings("JavadocMethod")
public NumberArrayWidget() {
pane.getChildren().add(table);
- dataOrDefault.addListener((observableValue, oldDoubles, newDoubles) -> {
- final var array = new Double[newDoubles.length];
- IntStream.range(0, newDoubles.length).forEach(i -> array[i] = newDoubles[i]);
- table.setItems(array);
+ dataOrDefault.addListener((observableValue, oldNumbers, newNumbers) -> {
+ table.setItems(newNumbers);
});
}I get a strange exception:
edu.wpi.first.shuffleboard.api.data.IncompatibleSourceException: Expected one of (LW Subsystem), but found type NumberArray instead
at edu.wpi.first.shuffleboard.api.widget.SingleSourceWidget.addSource(SingleSourceWidget.java:55)
at edu.wpi.first.shuffleboard.app.components.ProcedurallyDefinedTab.populateLayout(ProcedurallyDefinedTab.java:112)
at edu.wpi.first.shuffleboard.app.components.ProcedurallyDefinedTab.populate(ProcedurallyDefinedTab.java:98)
at edu.wpi.first.shuffleboard.api.util.FxUtils.lambda$runOnFxThread$0(FxUtils.java:64)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:290)
at java.base/java.lang.Thread.run(Thread.java:840)
Shuffleboard seems to think that NumberArrayWidget now accepts a SubsystemType, but I never specified that type anywhere.
There was a problem hiding this comment.
Depending on what commit your bench is based on, this may be a different bug that's fixed in #815, where data types aren't correctly loaded. LW Subsystem is interesting though, what does your robot code Shuffleboard setup look like?
There was a problem hiding this comment.
What does your robot code Shuffleboard setup look like?
I have the following in robotInit:
final var tab = Shuffleboard.getTab("Test");
tab.addBooleanArray("BooleanArray", () -> new boolean[]{false, true, false, true, true, false, true, false})
.withSize(3, 3);
tab.addDoubleArray("DoubleArray", () -> new double[]{0.0, 1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, 0.00001, -0.00001})
.withSize(3, 3);
tab.addFloatArray("FloatArray", () -> new float[]{0.0f, 1.0f, -1.0f, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NaN, 0.00001f, -0.00001f})
.withSize(3, 3);
tab.addIntegerArray("IntegerArray", () -> new long[]{0L, 1L, -1L, Long.MAX_VALUE, Long.MIN_VALUE})
.withSize(3, 3);
tab.addStringArray("StringArray", () -> new String[]{"Hello", "The quick brown fox jumps over the lazy dog.", "Extra long extra long Extra long extra long Extra long extra long Extra long extra long Extra long extra long", "", "newlines!\nnewlines!\nnewlines!"})
.withSize(3, 3);
tab.addBoolean("Boolean", () -> true);
tab.addDouble("Double", () -> 0.123456f);
tab.addFloat("Float", () -> 0.123f);
tab.addInteger("Integer", () -> 123);
tab.addString("String", () -> "String");Depending on what commit your branch is based on, this may be a different bug that's fixed in #815.
My branch (Martysh12/shuffleboard:array-widgets) is based on wpilibsuite/shuffleboard:main (commit cdd5e7a, specifically).
I actually did try merging SamCarlberg/shuffleboard:nt-fixes into my branch and seeing if doing so fixes anything; it looks like it didn't:

All entries in my robot-created Test tab can only display as a Network Table Tree (when I right click on them), and only the primitives types are auto-populated.
Entries under FMSInfo seem to display fine, however, and all widgets are available for them:

Overview
Add widgets for array types:
BooleanArrayWidget,NumberArrayWidgetandStringArrayWidgetScreenshots
Fixes #305