|
30 | 30 | import javafx.scene.control.*; |
31 | 31 | import javafx.scene.effect.DropShadow; |
32 | 32 | import javafx.scene.input.MouseEvent; |
| 33 | +import javafx.scene.layout.HBox; |
33 | 34 | import javafx.scene.layout.VBox; |
34 | 35 | import javafx.scene.paint.Color; |
35 | 36 | import javafx.stage.DirectoryChooser; |
|
48 | 49 | import java.net.URL; |
49 | 50 | import java.util.ArrayList; |
50 | 51 | import java.util.Arrays; |
| 52 | +import java.util.prefs.BackingStoreException; |
51 | 53 | import java.util.prefs.Preferences; |
52 | 54 | import java.util.zip.ZipEntry; |
53 | 55 | import java.util.zip.ZipInputStream; |
@@ -254,6 +256,7 @@ public void initialize() { |
254 | 256 | } else { |
255 | 257 | path = path + "/Blobs"; |
256 | 258 | } |
| 259 | + path = path.replaceAll("%20", " "); |
257 | 260 | pathField.setText(path); |
258 | 261 |
|
259 | 262 | } |
@@ -851,26 +854,36 @@ public void backgroundSettingsHandler() { |
851 | 854 | } |
852 | 855 |
|
853 | 856 | public void chooseTimeToRunHandler() { |
854 | | - TextInputDialog textInputDialog = new TextInputDialog(Integer.toString(appPrefs.getInt("Time to run", 7))); |
855 | | - textInputDialog.setTitle("Every when should I check new blobs?"); |
856 | | - textInputDialog.setHeaderText("Frequency to check"); |
857 | | - textInputDialog.setContentText("In days:"); |
| 857 | + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); |
| 858 | + alert.setTitle("Frequency to check for new blobs"); |
| 859 | + alert.setHeaderText("Frequency to check"); |
| 860 | + TextField textField = new TextField(Integer.toString(appPrefs.getInt("Time to run", 1))); |
858 | 861 | // make it so user can only enter integers |
859 | | - textInputDialog.getEditor().textProperty().addListener((observable, oldValue, newValue) -> { |
| 862 | + textField.textProperty().addListener((observable, oldValue, newValue) -> { |
860 | 863 | if (!newValue.matches("\\d*")) { |
861 | | - textInputDialog.getEditor().setText(newValue.replaceAll("[^\\d]", "")); |
| 864 | + textField.setText(newValue.replaceAll("[^\\d]", "")); |
862 | 865 | } |
863 | 866 | }); |
864 | | - textInputDialog.showAndWait(); |
865 | | - String result = textInputDialog.getResult(); |
866 | | - if (result != null && !result.equals("")) { |
867 | | - appPrefs.putInt("Time to run", Integer.valueOf(result)); |
| 867 | + ChoiceBox<String> choiceBox = new ChoiceBox<>(FXCollections.observableArrayList("Minutes", "Hours", "Days", "Weeks")); |
| 868 | + choiceBox.setValue(appPrefs.get("Time unit for background", "Days")); |
| 869 | + HBox hBox = new HBox(); |
| 870 | + hBox.getChildren().addAll(textField, choiceBox); |
| 871 | + alert.getDialogPane().setContent(hBox); |
| 872 | + alert.showAndWait(); |
| 873 | + if ((alert.getResult() != null) && !ButtonType.CANCEL.equals(alert.getResult()) && !"".equals(textField.getText()) && (choiceBox.getValue() != null)) { |
| 874 | + log("info given"); |
| 875 | + appPrefs.putInt("Time to run", Integer.valueOf(textField.getText())); |
| 876 | + appPrefs.put("Time unit for background", choiceBox.getValue()); |
| 877 | + } else { |
| 878 | + log("alert menu canceled"); |
| 879 | + backgroundSettingsButton.fire(); |
| 880 | + return; |
868 | 881 | } |
869 | 882 | if (Background.inBackground) { |
870 | 883 | ButtonType stopBackgroundButtonType = new ButtonType("Stop Background"); |
871 | | - Alert alert = new Alert(Alert.AlertType.INFORMATION, |
| 884 | + Alert restartBackgroundAlert = new Alert(Alert.AlertType.INFORMATION, |
872 | 885 | "You will need to restart the background for changes to take effect.", stopBackgroundButtonType); |
873 | | - alert.showAndWait(); |
| 886 | + restartBackgroundAlert.showAndWait(); |
874 | 887 | startBackgroundButton.fire(); |
875 | 888 | } |
876 | 889 | } |
@@ -915,9 +928,30 @@ public void startBackgroundHandler() { |
915 | 928 | } |
916 | 929 | } |
917 | 930 |
|
| 931 | + public void resetApp() { |
| 932 | + try { |
| 933 | + Alert confirmationAlert = new Alert(Alert.AlertType.CONFIRMATION, "Are you sure you would like to reset this application to defaults?", ButtonType.NO, ButtonType.YES); |
| 934 | + confirmationAlert.showAndWait(); |
| 935 | + if ((confirmationAlert.getResult() == null) || ButtonType.CANCEL.equals(confirmationAlert.getResult()) || ButtonType.NO.equals(confirmationAlert.getResult())) { |
| 936 | + return; |
| 937 | + } |
| 938 | + Preferences prefs = Preferences.userRoot().node("airsquared/blobsaver"); |
| 939 | + prefs.flush(); |
| 940 | + prefs.clear(); |
| 941 | + prefs.removeNode(); |
| 942 | + prefs.flush(); |
| 943 | + Alert applicationCloseAlert = new Alert(Alert.AlertType.INFORMATION, "The application will now exit.", ButtonType.OK); |
| 944 | + applicationCloseAlert.showAndWait(); |
| 945 | + Platform.exit(); |
| 946 | + System.exit(0); |
| 947 | + } catch (BackingStoreException e) { |
| 948 | + newReportableError("There was an error resetting the application.", e.getMessage()); |
| 949 | + } |
| 950 | + } |
| 951 | + |
918 | 952 | @SuppressWarnings("unused") |
919 | 953 | private void log(String msg) { |
920 | | -// System.out.println(msg); |
| 954 | + System.out.println(msg); |
921 | 955 | } |
922 | 956 |
|
923 | 957 | public void go() { |
|
0 commit comments