-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/data/AlertsData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package edu.wpi.first.shuffleboard.plugin.base.data; | ||
|
||
import edu.wpi.first.shuffleboard.api.data.ComplexData; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import java.util.Map; | ||
|
||
public final class AlertsData extends ComplexData<AlertsData> { | ||
|
||
private final String[] errors; | ||
private final String[] warnings; | ||
private final String[] infos; | ||
|
||
/** | ||
* Creates a new AlertsData object. | ||
* | ||
* @param errors List of active error alerts | ||
* @param warnings List of active warning alerts | ||
* @param infos List of active info alerts | ||
*/ | ||
public AlertsData(String[] errors, String[] warnings, String[] infos) { | ||
this.errors = errors; | ||
this.warnings = warnings; | ||
this.infos = infos; | ||
} | ||
|
||
/** | ||
* Gets the list of error alerts. | ||
*/ | ||
public String[] getErrors() { | ||
return errors; | ||
} | ||
|
||
/** | ||
* Gets the list of warning alerts. | ||
*/ | ||
public String[] getWarnings() { | ||
return warnings; | ||
} | ||
|
||
/** | ||
* Gets the list of info alerts. | ||
*/ | ||
public String[] getInfos() { | ||
return infos; | ||
} | ||
|
||
/** | ||
* Gets a collection of all alerts. | ||
*/ | ||
public ObservableList<AlertItem> getCollection() { | ||
ObservableList<AlertItem> collection = FXCollections.observableArrayList(); | ||
for (String text : errors) { | ||
collection.add(new AlertItem(AlertType.ERROR, text)); | ||
} | ||
for (String text : warnings) { | ||
collection.add(new AlertItem(AlertType.WARNING, text)); | ||
} | ||
for (String text : infos) { | ||
collection.add(new AlertItem(AlertType.INFO, text)); | ||
} | ||
return collection; | ||
} | ||
|
||
@Override | ||
public String toHumanReadableString() { | ||
return Integer.toString(errors.length) + " error(s), " + Integer.toString(warnings.length) + " warning(s), " | ||
+ Integer.toString(infos.length) + " info(s)"; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> asMap() { | ||
return Map.of("errors", errors, "warnings", warnings, "infos", infos); | ||
} | ||
|
||
public static class AlertItem { | ||
public final AlertType type; | ||
public final String text; | ||
|
||
public AlertItem(AlertType type, String text) { | ||
this.type = type; | ||
this.text = text; | ||
} | ||
} | ||
|
||
public static enum AlertType { | ||
ERROR, WARNING, INFO | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/data/types/AlertsType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package edu.wpi.first.shuffleboard.plugin.base.data.types; | ||
|
||
import edu.wpi.first.shuffleboard.api.data.ComplexDataType; | ||
import edu.wpi.first.shuffleboard.api.util.Maps; | ||
import edu.wpi.first.shuffleboard.plugin.base.data.AlertsData; | ||
|
||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public final class AlertsType extends ComplexDataType<AlertsData> { | ||
|
||
/** | ||
* The name of data of this type as it would appear in a WPILib sendable's | ||
* {@code .type} entry; a differential drive base a {@code .type} of | ||
* "DifferentialDrive", a sendable chooser has it set to "String Chooser"; a | ||
* hypothetical 2D point would have it set to "Point2D". | ||
*/ | ||
private static final String TYPE_NAME = "Alerts"; | ||
|
||
/** | ||
* The single instance of the point type. By convention, this is a | ||
* {@code public static final} field and the constructor is private to ensure | ||
* only a single instance of the data type exists. | ||
*/ | ||
public static final AlertsType Instance = new AlertsType(); | ||
|
||
private AlertsType() { | ||
super(TYPE_NAME, AlertsData.class); | ||
} | ||
|
||
@Override | ||
public Function<Map<String, Object>, AlertsData> fromMap() { | ||
return map -> new AlertsData( | ||
Maps.getOrDefault(map, "errors", new String[0]), | ||
Maps.getOrDefault(map, "warnings", new String[0]), | ||
Maps.getOrDefault(map, "infos", new String[0]) | ||
); | ||
} | ||
|
||
@Override | ||
public AlertsData getDefaultValue() { | ||
return new AlertsData(new String[] {}, new String[] {}, new String[] {}); | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
plugins/base/src/main/java/edu/wpi/first/shuffleboard/plugin/base/widget/AlertsWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package edu.wpi.first.shuffleboard.plugin.base.widget; | ||
|
||
import edu.wpi.first.shuffleboard.api.widget.Description; | ||
import edu.wpi.first.shuffleboard.api.widget.ParametrizedController; | ||
import edu.wpi.first.shuffleboard.api.widget.SimpleAnnotatedWidget; | ||
import edu.wpi.first.shuffleboard.plugin.base.data.AlertsData; | ||
import edu.wpi.first.shuffleboard.plugin.base.data.AlertsData.AlertItem; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.fxml.FXML; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.control.ListCell; | ||
import javafx.scene.control.ListView; | ||
import javafx.scene.control.MultipleSelectionModel; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.text.TextAlignment; | ||
|
||
@Description(name = "Alerts", dataTypes = AlertsData.class, summary = "Displays a list of alerts.") | ||
@ParametrizedController("AlertsWidget.fxml") | ||
public final class AlertsWidget extends SimpleAnnotatedWidget<AlertsData> { | ||
|
||
private Image errorIcon = new Image(getClass().getResourceAsStream("icons/error.png")); | ||
private Image warningIcon = new Image(getClass().getResourceAsStream("icons/warning.png")); | ||
private Image infoIcon = new Image(getClass().getResourceAsStream("icons/info.png")); | ||
|
||
@FXML | ||
private Pane root; | ||
|
||
@FXML | ||
private ListView<AlertItem> list; | ||
|
||
@FXML | ||
private GridPane placeholder; | ||
|
||
@FXML | ||
private void initialize() { | ||
list.setCellFactory(param -> new ListCell<AlertItem>() { | ||
@Override | ||
protected void updateItem(AlertItem item, boolean empty) { | ||
super.updateItem(item, empty); | ||
if (empty || item == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setMinWidth(param.getWidth() - 32); | ||
setMaxWidth(param.getWidth() - 32); | ||
setPrefWidth(param.getWidth() - 32); | ||
|
||
setWrapText(true); | ||
setText(item.text); | ||
setTextAlignment(TextAlignment.LEFT); | ||
|
||
ImageView imageView = new ImageView(); | ||
switch (item.type) { | ||
case ERROR: | ||
imageView.setImage(errorIcon); | ||
break; | ||
case WARNING: | ||
imageView.setImage(warningIcon); | ||
break; | ||
case INFO: | ||
imageView.setImage(infoIcon); | ||
break; | ||
default: | ||
break; | ||
} | ||
imageView.setFitHeight(20); | ||
imageView.setFitWidth(20); | ||
imageView.setTranslateX(-3); | ||
imageView.setSmooth(true); | ||
setGraphic(imageView); | ||
} | ||
} | ||
}); | ||
|
||
list.setSelectionModel(new NoSelectionModel<AlertItem>()); | ||
list.itemsProperty().bind(dataOrDefault.map(AlertsData::getCollection)); | ||
placeholder.setAlignment(Pos.TOP_CENTER); | ||
} | ||
|
||
@Override | ||
public Pane getView() { | ||
return root; | ||
} | ||
|
||
private static class NoSelectionModel<T> extends MultipleSelectionModel<T> { | ||
|
||
@Override | ||
public ObservableList<Integer> getSelectedIndices() { | ||
return FXCollections.emptyObservableList(); | ||
} | ||
|
||
@Override | ||
public ObservableList<T> getSelectedItems() { | ||
return FXCollections.emptyObservableList(); | ||
} | ||
|
||
@Override | ||
public void selectIndices(int index, int... indices) { | ||
} | ||
|
||
@Override | ||
public void selectAll() { | ||
} | ||
|
||
@Override | ||
public void selectFirst() { | ||
} | ||
|
||
@Override | ||
public void selectLast() { | ||
} | ||
|
||
@Override | ||
public void clearAndSelect(int index) { | ||
} | ||
|
||
@Override | ||
public void select(int index) { | ||
} | ||
|
||
@Override | ||
public void select(T obj) { | ||
} | ||
|
||
@Override | ||
public void clearSelection(int index) { | ||
} | ||
|
||
@Override | ||
public void clearSelection() { | ||
} | ||
|
||
@Override | ||
public boolean isSelected(int index) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void selectPrevious() { | ||
} | ||
|
||
@Override | ||
public void selectNext() { | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...s/base/src/main/resources/edu/wpi/first/shuffleboard/plugin/base/widget/AlertsWidget.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.ListView?> | ||
<?import javafx.scene.image.ImageView?> | ||
<?import javafx.scene.image.Image?> | ||
<?import javafx.scene.layout.*?> | ||
<VBox xmlns="http://javafx.com/javafx" | ||
xmlns:fx="http://javafx.com/fxml" | ||
fx:controller="edu.wpi.first.shuffleboard.plugin.base.widget.AlertsWidget" | ||
fx:id="root" | ||
stylesheets="@alerts-widget.css"> | ||
<ListView fx:id="list"> | ||
<placeholder> | ||
<GridPane fx:id="placeholder"> | ||
<Label text="(Nothing to report)"/> | ||
</GridPane> | ||
</placeholder> | ||
</ListView> | ||
</VBox> |
3 changes: 3 additions & 0 deletions
3
...s/base/src/main/resources/edu/wpi/first/shuffleboard/plugin/base/widget/alerts-widget.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.list-view .list-cell { | ||
-fx-background-color: transparent; | ||
} |
Binary file added
BIN
+20.6 KB
...rc/main/resources/edu/wpi/first/shuffleboard/plugin/base/widget/icons/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.6 KB
...src/main/resources/edu/wpi/first/shuffleboard/plugin/base/widget/icons/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.3 KB
.../main/resources/edu/wpi/first/shuffleboard/plugin/base/widget/icons/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.