Skip to content

Commit

Permalink
Add Source View return Messsage from exception
Browse files Browse the repository at this point in the history
  • Loading branch information
JLLeitschuh committed Dec 9, 2015
1 parent 664bda4 commit af47ce7
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions ui/src/main/java/edu/wpi/grip/ui/pipeline/AddSourceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.FileChooser;

Expand Down Expand Up @@ -42,6 +45,25 @@ private interface SupplierWithIO<T> {
T getWithIO() throws IOException;
}

private class SourceDialog extends Dialog<ButtonType> {
private final Text errorText = new Text();

private SourceDialog(final Parent root, Control inputField) {
final GridPane gridContent = new GridPane();
gridContent.setMaxWidth(Double.MAX_VALUE);
GridPane.setHgrow(inputField, Priority.ALWAYS);
GridPane.setHgrow(errorText, Priority.NEVER);
errorText.wrappingWidthProperty().bind(inputField.widthProperty());
gridContent.add(errorText, 0, 0);
gridContent.add(inputField, 0, 1);

getDialogPane().setContent(gridContent);
getDialogPane().setStyle(root.getStyle());
getDialogPane().getStylesheets().addAll(root.getStylesheets());
getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
}
}

public AddSourceView(EventBus eventBus) {
this.eventBus = checkNotNull(eventBus, "Event Bus can not be null");

Expand Down Expand Up @@ -76,32 +98,28 @@ public AddSourceView(EventBus eventBus) {
final Parent root = this.getScene().getRoot();

// Show a dialog for the user to pick a camera index
final Dialog<ButtonType> dialog = new Dialog<>();
final Spinner<Integer> cameraIndex = new Spinner<Integer>(0, Integer.MAX_VALUE, 0);
final SourceDialog dialog = new SourceDialog(root, cameraIndex);

dialog.setTitle("Add Webcam");
dialog.setHeaderText("Choose a camera");
dialog.setContentText("index");
dialog.getDialogPane().setContent(cameraIndex);
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
dialog.getDialogPane().setStyle(root.getStyle());
dialog.getDialogPane().getStylesheets().addAll(root.getStylesheets());

// If the user clicks OK, add a new camera source
loadCamera(dialog,
() -> new CameraSource(eventBus, cameraIndex.getValue()).start(eventBus),
e -> {
// TODO: Indicate to user that the camera source was invalid
dialog.errorText.setText(e.getMessage());
});
});

addButton("Add IP\nCamera", getClass().getResource("/edu/wpi/grip/ui/icons/add-webcam.png"), mouseEvent -> {
final Parent root = this.getScene().getRoot();

// Show a dialog for the user to pick a camera URL
final Dialog<ButtonType> dialog = new Dialog<>();

final TextField cameraAddress = new TextField();
final SourceDialog dialog = new SourceDialog(root, cameraAddress);
cameraAddress.setPromptText("Ex: http://10.1.90.11/mjpg/video.mjpg");
cameraAddress.textProperty().addListener(observable -> {
boolean validURL = true;
Expand All @@ -119,17 +137,13 @@ public AddSourceView(EventBus eventBus) {
dialog.setTitle("Add IP Camera");
dialog.setHeaderText("Enter the IP camera URL");
dialog.setContentText("URL");
dialog.getDialogPane().setContent(cameraAddress);
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
dialog.getDialogPane().setStyle(root.getStyle());
dialog.getDialogPane().getStylesheets().addAll(root.getStylesheets());

// If the user clicks OK, add a new camera source
loadCamera(dialog,
() -> new CameraSource(eventBus, cameraAddress.getText()).start(eventBus),
e -> {
// TODO: Indicate to user that the camera source was invalid
dialog.errorText.setText(e.getMessage());
});
});
}
Expand Down

0 comments on commit af47ce7

Please sign in to comment.