diff --git a/build.gradle b/build.gradle
index c3819f093c..0779b5080e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,6 +19,7 @@ allprojects {
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'jacoco'
+ apply plugin: 'checkstyle'
repositories {
@@ -29,7 +30,6 @@ allprojects {
toolVersion = "0.7.5.201505241946"
}
-
dependencies {
testCompile group: 'net.jodah', name: 'concurrentunit', version: '0.4.2'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
@@ -49,6 +49,12 @@ allprojects {
}
}
+ checkstyle {
+ configFile = file("${project.rootDir}/google_checks.xml")
+ reportsDir = file("${project.rootDir}/build/reports/checkstyle/")
+ toolVersion = '6.14'
+ }
+
check.dependsOn jacocoTestReport
tasks.withType(Javadoc) {
diff --git a/google_checks.xml b/google_checks.xml
new file mode 100644
index 0000000000..d4308361aa
--- /dev/null
+++ b/google_checks.xml
@@ -0,0 +1,208 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ui/src/main/java/edu/wpi/grip/ui/pipeline/AddSourceView.java b/ui/src/main/java/edu/wpi/grip/ui/pipeline/AddSourceView.java
index ce506a2ab9..2a94977d9f 100644
--- a/ui/src/main/java/edu/wpi/grip/ui/pipeline/AddSourceView.java
+++ b/ui/src/main/java/edu/wpi/grip/ui/pipeline/AddSourceView.java
@@ -1,9 +1,5 @@
package edu.wpi.grip.ui.pipeline;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.eventbus.EventBus;
-import com.google.inject.Inject;
-import com.google.common.net.InetAddresses;
import edu.wpi.grip.core.events.SourceAddedEvent;
import edu.wpi.grip.core.events.UnexpectedThrowableEvent;
import edu.wpi.grip.core.sources.CameraSource;
@@ -11,10 +7,33 @@
import edu.wpi.grip.core.sources.MultiImageFileSource;
import edu.wpi.grip.ui.util.DPIUtility;
import edu.wpi.grip.ui.util.SupplierWithIO;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.eventbus.EventBus;
+import com.google.common.net.InetAddresses;
+import com.google.inject.Inject;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.Parent;
-import javafx.scene.control.*;
+import javafx.scene.control.Button;
+import javafx.scene.control.ButtonBar;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.ContentDisplay;
+import javafx.scene.control.Control;
+import javafx.scene.control.Dialog;
+import javafx.scene.control.Spinner;
+import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
@@ -25,20 +44,10 @@
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
/**
- * A box of buttons that let the user add different kinds of {@link edu.wpi.grip.core.Source Source}s. Depending on which button is pressed,
- * a different dialog is presented for the user to construct that source. As an example, the image file source results
- * in a file picker that the user can use to browse for an image.
+ * A box of buttons that let the user add different kinds of {@link edu.wpi.grip.core.Source Source}s. Depending on
+ * which button is pressed, a different dialog is presented for the user to construct that source. As an example, the
+ * image file source results in a file picker that the user can use to browse for an image.
*/
public class AddSourceView extends HBox {
@@ -111,7 +120,9 @@ public interface Factory {
final List imageFiles = fileChooser.showOpenMultipleDialog(this.getScene().getWindow());
- if (imageFiles == null) return;
+ if (imageFiles == null) {
+ return;
+ }
// Add a new source for each image .
if (imageFiles.size() == 1) {
@@ -119,96 +130,93 @@ public interface Factory {
final ImageFileSource imageFileSource = imageSourceFactory.create(imageFiles.get(0));
imageFileSource.initialize();
eventBus.post(new SourceAddedEvent(imageFileSource));
- } catch (IOException e) {
- eventBus.post(new UnexpectedThrowableEvent(e, "The image selected was invalid"));
+ } catch (IOException exception) {
+ eventBus.post(new UnexpectedThrowableEvent(exception, "The image selected was invalid"));
}
} else {
try {
final MultiImageFileSource multiImageFileSource = multiImageSourceFactory.create(imageFiles);
multiImageFileSource.initialize();
eventBus.post(new SourceAddedEvent(multiImageFileSource));
- } catch (IOException e) {
- eventBus.post(new UnexpectedThrowableEvent(e, "One of the images selected was invalid"));
+ } catch (IOException exception) {
+ eventBus.post(new UnexpectedThrowableEvent(exception, "One of the images selected was invalid"));
}
}
});
- webcamButton = addButton("Add\nWebcam", 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 index
- final Spinner cameraIndex = new Spinner(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().lookupButton(ButtonType.OK).requestFocus();
-
- // If the user clicks OK, add a new camera source
- loadCamera(dialog,
- () -> {
- final CameraSource cameraSource = cameraSourceFactory.create(cameraIndex.getValue());
- cameraSource.initialize();
- return cameraSource;
- },
- e -> {
- dialog.errorText.setText(e.getMessage());
- });
- });
+ webcamButton = addButton("Add\nWebcam", getClass().getResource("/edu/wpi/grip/ui/icons/add-webcam.png"),
+ mouseEvent -> {
+ final Parent root = this.getScene().getRoot();
- ipcamButton = 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 index
+ final Spinner cameraIndex = new Spinner(0, Integer.MAX_VALUE, 0);
+ final SourceDialog dialog = new SourceDialog(root, cameraIndex);
- // Show a dialog for the user to pick a camera URL
+ dialog.setTitle("Add Webcam");
+ dialog.setHeaderText("Choose a camera");
+ dialog.setContentText("index");
- 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;
+ dialog.getDialogPane().lookupButton(ButtonType.OK).requestFocus();
- try {
- new URL(cameraAddress.getText()).toURI();
- } catch (MalformedURLException e) {
- validURL = false;
- if (InetAddresses.isInetAddress(cameraAddress.getText()) || cameraAddress.getText().endsWith(".local")) {
- cameraAddress.setText("http://" + cameraAddress.getText());
- validURL = true;
+ // If the user clicks OK, add a new camera source
+ loadCamera(dialog, () -> {
+ final CameraSource cameraSource = cameraSourceFactory.create(cameraIndex.getValue());
+ cameraSource.initialize();
+ return cameraSource;
+ }, e -> { dialog.errorText.setText(e.getMessage()); });
+ });
+
+ ipcamButton = 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 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;
+
+ try {
+ new URL(cameraAddress.getText()).toURI();
+ } catch (MalformedURLException exception) {
+ validUrl = false;
+ if (InetAddresses.isInetAddress(cameraAddress.getText())
+ || cameraAddress.getText().endsWith(".local")) {
+ cameraAddress.setText("http://" + cameraAddress.getText());
+ validUrl = true;
+ }
+ } catch (URISyntaxException exception) {
+ validUrl = false;
}
- } catch (URISyntaxException e) {
- validURL = false;
- }
- // Enable the "OK" button only if the user has entered a valid URL
- dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(!validURL);
+ // Enable the "OK" button only if the user has entered a valid URL
+ dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(!validUrl);
+ });
+
+ dialog.setTitle("Add IP Camera");
+ dialog.setHeaderText("Enter the IP camera URL");
+ dialog.setContentText("URL");
+ dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
+
+ // If the user clicks OK, add a new camera source
+ loadCamera(dialog, () -> {
+ final CameraSource cameraSource = cameraSourceFactory.create(cameraAddress.getText());
+ cameraSource.initialize();
+ return cameraSource;
+ }, e -> { dialog.errorText.setText(e.getMessage()); });
});
-
- dialog.setTitle("Add IP Camera");
- dialog.setHeaderText("Enter the IP camera URL");
- dialog.setContentText("URL");
- dialog.getDialogPane().lookupButton(ButtonType.OK).setDisable(true);
-
- // If the user clicks OK, add a new camera source
- loadCamera(dialog,
- () -> {
- final CameraSource cameraSource = cameraSourceFactory.create(cameraAddress.getText());
- cameraSource.initialize();
- return cameraSource;
- },
- e -> {
- dialog.errorText.setText(e.getMessage());
- });
- });
}
/**
+ * Load a new camera source.
+ *
* @param dialog The dialog to load the camera with
* @param cameraSourceSupplier The supplier that will create the camera
* @param failureCallback The handler for when the camera source supplier throws an IO Exception
*/
- private void loadCamera(Dialog dialog, SupplierWithIO cameraSourceSupplier, Consumer failureCallback) {
+ private void loadCamera(Dialog dialog, SupplierWithIO cameraSourceSupplier,
+ Consumer failureCallback) {
assert Platform.isFxApplicationThread() : "Should only run in FX thread";
activeDialog = Optional.of(dialog);
dialog.showAndWait().filter(Predicate.isEqual(ButtonType.OK)).ifPresent(result -> {
@@ -216,9 +224,9 @@ private void loadCamera(Dialog dialog, SupplierWithIO
// Will try to create the camera with the values from the supplier
final CameraSource source = cameraSourceSupplier.getWithIO();
eventBus.post(new SourceAddedEvent(source));
- } catch (IOException e) {
+ } catch (IOException exception) {
// This will run it again with the new values retrieved by the supplier
- failureCallback.accept(e);
+ failureCallback.accept(exception);
loadCamera(dialog, cameraSourceSupplier, failureCallback);
}
});
@@ -229,8 +237,8 @@ private void loadCamera(Dialog dialog, SupplierWithIO
/**
* Add a new button for adding a source. This method takes care of setting the event handler.
*/
- private Button addButton(String text, URL graphicURL, EventHandler super MouseEvent> onMouseClicked) {
- final ImageView graphic = new ImageView(graphicURL.toString());
+ private Button addButton(String text, URL graphicUrl, EventHandler super MouseEvent> onMouseClicked) {
+ final ImageView graphic = new ImageView(graphicUrl.toString());
graphic.setFitWidth(DPIUtility.SMALL_ICON_SIZE);
graphic.setFitHeight(DPIUtility.SMALL_ICON_SIZE);