Skip to content

Commit

Permalink
Added program icon to dialogs and alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxiHuHe04 committed Apr 18, 2022
1 parent bdb8ead commit 5ca3f5f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ public static void main(String[] args) {
public static Image getIcon(String name) {
return new Image(Objects.requireNonNull(ITunesBackupExplorer.class.getResourceAsStream(name)));
}

public static Image APP_ICON = getIcon("icon.png");
}
9 changes: 9 additions & 0 deletions src/main/java/me/maxih/itunes_backup_explorer/ui/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import me.maxih.itunes_backup_explorer.ITunesBackupExplorer;

import java.util.Optional;

Expand All @@ -22,6 +23,7 @@ public static Optional<String> askPassword() {
dialog.setTitle("Enter the password");
dialog.setHeaderText("This backup is encrypted with a password");
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
((Stage) dialog.getDialogPane().getScene().getWindow()).getIcons().add(ITunesBackupExplorer.APP_ICON);

PasswordField passwordField = new PasswordField();
dialog.setOnShown(event -> Platform.runLater(passwordField::requestFocus));
Expand All @@ -38,13 +40,20 @@ public static Optional<String> askPassword() {
return dialog.showAndWait();
}

public static Optional<ButtonType> showAlert(Alert.AlertType type, String message, ButtonType... buttonTypes) {
Alert alert = new Alert(type, message, buttonTypes);
((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(ITunesBackupExplorer.APP_ICON);
return alert.showAndWait();
}

public static class ProgressAlert extends Stage {

public ProgressAlert(String title, Task<?> task, EventHandler<WindowEvent> cancelEventHandler) {
this.initModality(Modality.APPLICATION_MODAL);
this.setTitle(title);
this.setResizable(false);
this.setOnCloseRequest(cancelEventHandler);
this.getIcons().add(ITunesBackupExplorer.APP_ICON);

ProgressBar bar = new ProgressBar();
bar.setPrefSize(250, 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void openFile(BackupFile file) {
} catch (IOException | UnsupportedCryptoException | NotUnlockedException |
BackupReadException exception) {
exception.printStackTrace();
new Alert(Alert.AlertType.ERROR, exception.getMessage(), ButtonType.OK).showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, exception.getMessage(), ButtonType.OK);
}
}

Expand All @@ -43,7 +43,7 @@ public static void extractFile(BackupFile file, Window chooserOwnerWindow) {
file.extract(destination);
} catch (IOException | BackupReadException | NotUnlockedException | UnsupportedCryptoException e) {
e.printStackTrace();
new Alert(Alert.AlertType.ERROR, e.getMessage(), ButtonType.OK).showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, e.getMessage(), ButtonType.OK);
}
}

Expand All @@ -61,7 +61,7 @@ public static void replaceFile(BackupFile file, Window chooserOwnerWindow) {
} catch (IOException | BackupReadException | NotUnlockedException | UnsupportedCryptoException |
DatabaseConnectionException e) {
e.printStackTrace();
new Alert(Alert.AlertType.ERROR, e.getMessage(), ButtonType.OK).showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, e.getMessage(), ButtonType.OK);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void exportMatching() {
backupFile.getFile().get().extractToFolder(destination, true);
} catch (IOException | BackupReadException | NotUnlockedException | UnsupportedCryptoException e) {
e.printStackTrace();
new Alert(Alert.AlertType.ERROR, e.getMessage(), ButtonType.OK).showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, e.getMessage(), ButtonType.OK);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ public boolean tryUnlock() {
selectedBackup.decryptDatabase();
return true;
} catch (InvalidKeyException e) {
new Alert(Alert.AlertType.ERROR, "The given password is not valid").showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, "The given password is not valid");
} catch (BackupReadException e) {
new Alert(Alert.AlertType.ERROR, "The backup could not be read").showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, "The backup could not be read");
} catch (UnsupportedCryptoException e) {
new Alert(Alert.AlertType.ERROR, "Your system doesn't support the necessary cryptography").showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, "Your system doesn't support the necessary cryptography");
} catch (NotUnlockedException e) {
e.printStackTrace();
} catch (IOException e) {
new Alert(Alert.AlertType.ERROR, e.getMessage()).showAndWait();
Dialogs.showAlert(Alert.AlertType.ERROR, e.getMessage());
}
return false;
}
Expand Down Expand Up @@ -178,11 +178,11 @@ public void openPreferences() {
Scene prefsScene = new Scene(root, 600, 400);
prefsWindow.setScene(prefsScene);
prefsWindow.setTitle("Preferences");
prefsWindow.getIcons().addAll(((Stage) tabPane.getScene().getWindow()).getIcons());
prefsWindow.getIcons().add(ITunesBackupExplorer.APP_ICON);
prefsWindow.show();
} catch (IOException e) {
e.printStackTrace();
new Alert(Alert.AlertType.ERROR, e.getMessage());
Dialogs.showAlert(Alert.AlertType.ERROR, e.getMessage());
}
}
}

0 comments on commit 5ca3f5f

Please sign in to comment.