Skip to content

Commit

Permalink
Fix style violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Martysh12 committed Oct 19, 2024
1 parent 4fcb776 commit 7393aee
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,39 @@
import edu.wpi.first.shuffleboard.plugin.base.layout.GridLayoutSaver;
import edu.wpi.first.shuffleboard.plugin.base.layout.ListLayout;
import edu.wpi.first.shuffleboard.plugin.base.layout.SubsystemLayout;
import edu.wpi.first.shuffleboard.plugin.base.widget.*;
import edu.wpi.first.shuffleboard.plugin.base.widget.AccelerometerWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.AlertsWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.BasicFmsInfoWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.BasicSubsystemWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.BooleanArrayWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.BooleanBoxWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.ComboBoxChooserWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.CommandWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.DifferentialDriveWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.EncoderWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.FieldWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.GraphWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.GyroWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.MecanumDriveWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.NumberArrayWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.NumberBarWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.NumberSliderWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.PIDCommandWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.PIDControllerWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.PowerDistributionPanelWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.ProfiledPIDControllerWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.RelayWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.RobotPreferencesWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.SimpleDialWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.SpeedControllerWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.SplitButtonChooserWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.StringArrayWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.TextViewWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.ThreeAxisAccelerometerWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.ToggleButtonWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.ToggleSwitchWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.UltrasonicWidget;
import edu.wpi.first.shuffleboard.plugin.base.widget.VoltageViewWidget;
import javafx.beans.InvalidationListener;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,53 @@
import javafx.util.Callback;

public class ArrayTableView<T> extends TableView<ArrayTableView.ArrayTableEntry<T>> {
private final TableColumn<ArrayTableEntry<T>, String> indexCol = new TableColumn<>("Index");
private final TableColumn<ArrayTableEntry<T>, T> valueCol = new TableColumn<>("Value");
private final TableColumn<ArrayTableEntry<T>, String> indexCol = new TableColumn<>("Index");
private final TableColumn<ArrayTableEntry<T>, T> valueCol = new TableColumn<>("Value");

private final ObservableList<ArrayTableEntry<T>> list = FXCollections.observableArrayList();
private final ObservableList<ArrayTableEntry<T>> list = FXCollections.observableArrayList();

public ArrayTableView() {
super();
@SuppressWarnings("JavadocMethod")
public ArrayTableView() {
super();

indexCol.setCellValueFactory(p -> new ReadOnlyStringWrapper(String.valueOf(p.getValue().index)));
indexCol.setResizable(false);
indexCol.setPrefWidth(50);
indexCol.setCellValueFactory(p -> new ReadOnlyStringWrapper(String.valueOf(p.getValue().index)));
indexCol.setResizable(false);
indexCol.setPrefWidth(50);

valueCol.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().value));
valueCol.prefWidthProperty().bind(widthProperty().subtract(50).subtract(2));
valueCol.setCellValueFactory(p -> new ReadOnlyObjectWrapper<>(p.getValue().value));
valueCol.prefWidthProperty().bind(widthProperty().subtract(50).subtract(2));

//noinspection unchecked
getColumns().addAll(indexCol, valueCol);
//noinspection unchecked
getColumns().addAll(indexCol, valueCol);

setItems(list);
}
setItems(list);
}

public void setValueCellFactory(Callback<TableColumn<ArrayTableEntry<T>, T>, TableCell<ArrayTableEntry<T>, T>> callback) {
valueCol.setCellFactory(callback);
}
public void setValueCellFactory(
Callback<TableColumn<ArrayTableEntry<T>, T>, TableCell<ArrayTableEntry<T>, T>> callback
) {
valueCol.setCellFactory(callback);
}

public void setItems(T[] items) {
final var entries = new ArrayTableEntry[items.length];
for (int i = 0; i < items.length; i++) {
entries[i] = new ArrayTableEntry<>(i, items[i]);
}
//noinspection unchecked
list.setAll(entries);
/**
* Convenience method to set the table's items.
*/
public void setItems(T[] items) {
final var entries = new ArrayTableEntry[items.length];
for (int i = 0; i < items.length; i++) {
entries[i] = new ArrayTableEntry<>(i, items[i]);
}
//noinspection unchecked
list.setAll(entries);
}

public static class ArrayTableEntry<S> {
public final int index;
public final S value;
public static class ArrayTableEntry<S> {
public final int index;
public final S value;

public ArrayTableEntry(int index, S value) {
this.index = index;
this.value = value;
}
public ArrayTableEntry(int index, S value) {
this.index = index;
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,59 @@
import java.util.stream.IntStream;

@Description(
name = "Boolean Array",
dataTypes = boolean[].class,
summary = "Displays an array of booleans"
name = "Boolean Array",
dataTypes = boolean[].class,
summary = "Displays an array of booleans"
)
public final class BooleanArrayWidget extends SimpleAnnotatedWidget<boolean[]> {
private final StackPane pane = new StackPane();
private final ArrayTableView<Boolean> table = new ArrayTableView<>();
private final StackPane pane = new StackPane();
private final ArrayTableView<Boolean> table = new ArrayTableView<>();

private final Property<Color> trueColor
= new SimpleObjectProperty<>(this, "colorWhenTrue", Color.LAWNGREEN);
private final Property<Color> falseColor
= new SimpleObjectProperty<>(this, "colorWhenFalse", Color.DARKRED);
private final Property<Color> trueColor
= new SimpleObjectProperty<>(this, "colorWhenTrue", Color.LAWNGREEN);
private final Property<Color> falseColor
= new SimpleObjectProperty<>(this, "colorWhenFalse", Color.DARKRED);

public BooleanArrayWidget() {
pane.getChildren().add(table);
@SuppressWarnings("JavadocMethod")
public BooleanArrayWidget() {
pane.getChildren().add(table);

table.setValueCellFactory(tableColumn -> new BooleanTableCell<>());
table.setValueCellFactory(tableColumn -> new BooleanTableCell<>());

dataOrDefault.addListener((observableValue, oldBooleans, newBooleans) -> {
final var array = new Boolean[newBooleans.length];
IntStream.range(0, newBooleans.length).forEach(i -> array[i] = newBooleans[i]);
table.setItems(array);
});
}
dataOrDefault.addListener((observableValue, oldBooleans, newBooleans) -> {
final var array = new Boolean[newBooleans.length];
IntStream.range(0, newBooleans.length).forEach(i -> array[i] = newBooleans[i]);
table.setItems(array);
});
}

@Override
public List<Group> getSettings() {
return List.of(
Group.of("Colors",
Setting.of("Color when true", "The color to use when a value is `true`", trueColor, Color.class),
Setting.of("Color when false", "The color to use when a value is `false`", falseColor, Color.class)
)
);
}
@Override
public List<Group> getSettings() {
return List.of(
Group.of("Colors",
Setting.of("Color when true", "The color to use when a value is `true`", trueColor, Color.class),
Setting.of("Color when false", "The color to use when a value is `false`", falseColor, Color.class)
)
);
}

@Override
public Pane getView() {
return pane;
}
@Override
public Pane getView() {
return pane;
}

private class BooleanTableCell<S> extends TableCell<S, Boolean> {
private Background createBooleanBackground(boolean value) {
return new Background(new BackgroundFill(value ? trueColor.getValue() : falseColor.getValue(), null, null));
}
private class BooleanTableCell<S> extends TableCell<S, Boolean> {
private Background createBooleanBackground(boolean value) {
return new Background(new BackgroundFill(value ? trueColor.getValue() : falseColor.getValue(), null, null));
}

@Override
protected void updateItem(Boolean t, boolean empty) {
if (empty || t == null)
setBackground(null);
else
setBackground(createBooleanBackground(t));
}
@Override
protected void updateItem(Boolean t, boolean empty) {
if (empty || t == null) {
setBackground(null);
} else {
setBackground(createBooleanBackground(t));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
import java.util.stream.IntStream;

@Description(
name = "Number Array",
dataTypes = double[].class,
summary = "Displays an array of numbers"
name = "Number Array",
dataTypes = double[].class,
summary = "Displays an array of numbers"
)
public final class NumberArrayWidget extends SimpleAnnotatedWidget<double[]> {
private final StackPane pane = new StackPane();
private final ArrayTableView<Double> table = new ArrayTableView<>();
private final StackPane pane = new StackPane();
private final ArrayTableView<Double> table = new ArrayTableView<>();

public NumberArrayWidget() {
pane.getChildren().add(table);
@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, oldDoubles, newDoubles) -> {
final var array = new Double[newDoubles.length];
IntStream.range(0, newDoubles.length).forEach(i -> array[i] = newDoubles[i]);
table.setItems(array);
});
}

@Override
public Pane getView() {
return pane;
}
@Override
public Pane getView() {
return pane;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
import javafx.scene.layout.StackPane;

@Description(
name = "String Array",
dataTypes = String[].class,
summary = "Displays an array of strings"
name = "String Array",
dataTypes = String[].class,
summary = "Displays an array of strings"
)
public final class StringArrayWidget extends SimpleAnnotatedWidget<String[]> {
private final StackPane pane = new StackPane();
private final ArrayTableView<String> table = new ArrayTableView<>();
private final StackPane pane = new StackPane();
private final ArrayTableView<String> table = new ArrayTableView<>();

public StringArrayWidget() {
pane.getChildren().add(table);
@SuppressWarnings("JavadocMethod")
public StringArrayWidget() {
pane.getChildren().add(table);

dataOrDefault.addListener((observableValue, oldStrings, newStrings) -> table.setItems(newStrings));
}
dataOrDefault.addListener((observableValue, oldStrings, newStrings) -> table.setItems(newStrings));
}

@Override
public Pane getView() {
return pane;
}
@Override
public Pane getView() {
return pane;
}
}

0 comments on commit 7393aee

Please sign in to comment.