Skip to content

Commit

Permalink
Fromating code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eng-Ziad7 committed Jun 20, 2024
1 parent 80042e5 commit 526a443
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 62 deletions.
7 changes: 4 additions & 3 deletions GUI/src/main/java/gui/preferences/Get.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static Get getInstance() {
return INSTANCE;
}

public String lastDwnldDir(){
public String lastDwnldDir() {
return "hello";
}

Expand All @@ -44,8 +44,9 @@ public Folders folders() {
public boolean mainAutoPaste() {
return preferences.getBoolean(MAIN_AUTO_PASTE.toString(), false);
}
public String mainTheme(){
return preferences.get(MAIT_THEME.toString() , "LIGHT");

public String mainTheme() {
return preferences.get(MAIT_THEME.toString(), "LIGHT");
}

public Jobs jobs() {
Expand Down
17 changes: 8 additions & 9 deletions GUI/src/main/java/main/Drifty_GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public void start(Stage primaryStage) {
this.primaryStage.show();
}

public static AnchorPane ap = new AnchorPane();
public static AnchorPane ap = new AnchorPane();

private void createScene() {
MainGridPane gridPane = new MainGridPane();
MenuBar menu = menuBar(getMenuItemsOfMenu(), getEditMenu(), getWindowMenu(), getHelpMenu());
Expand All @@ -75,7 +76,7 @@ private void createScene() {
placeControl(gridPane, 40, 40, 40, 40);
placeControl(menu, 0, 0, 0, -1);
scene = Constants.getScene(ap);
if(AppSettings.GET.mainTheme().toString().equals("Dark")){
if (AppSettings.GET.mainTheme().toString().equals("Dark")) {

Check notice

Code scanning / CodeQL

Useless toString on String Note

Redundant call to 'toString' on a String object.
scene.getStylesheets().add(Constants.DARK_THEME_CSS.toExternalForm());
}
scene.setOnContextMenuRequested(e -> getRightClickContextMenu().show(scene.getWindow(), e.getScreenX(), e.getScreenY()));
Expand Down Expand Up @@ -185,17 +186,14 @@ private Menu getHelpMenu() {
aboutRoot.getChildren().add(lblFfmpegVersion);
}
aboutRoot.getChildren().addAll(websiteLink, discordLink, githubLink);
aboutScene = Constants.getScene(aboutRoot );
if(AppSettings.GET.mainTheme().toString().equals("Dark")){
aboutScene = Constants.getScene(aboutRoot);
if (AppSettings.GET.mainTheme().toString().equals("Dark")) {

Check notice

Code scanning / CodeQL

Useless toString on String Note

Redundant call to 'toString' on a String object.
aboutScene.getStylesheets().add(Constants.DARK_THEME_CSS.toExternalForm());
for (Node node : Drifty_GUI.aboutRoot.getChildren()) {
if (node instanceof Label) {
((Label) node).setTextFill(Color.WHITE);
}
}
}
if(AppSettings.GET.mainTheme().toString().equals("Dark")){

}
stage.setMinHeight(Constants.SCREEN_HEIGHT * .55);
stage.setMinWidth(Constants.SCREEN_WIDTH * .5);
Expand All @@ -205,6 +203,7 @@ private Menu getHelpMenu() {
menu.getItems().setAll(contactUs, contribute, bug, securityVulnerability, feature, about);
return menu;
}

private Menu getEditMenu() {
Menu menu = new Menu("Edit");
MenuItem wipeHistory = new MenuItem("Clear Download History");
Expand All @@ -215,10 +214,10 @@ private Menu getEditMenu() {
UIController.clearJobHistory();
}
});
settings.setOnAction(e ->{
settings.setOnAction(e -> {
Settings settings1 = new Settings();

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'Settings settings1' is never read.
});
menu.getItems().addAll(wipeHistory , settings);
menu.getItems().addAll(wipeHistory, settings);
return menu;
}

Expand Down
90 changes: 44 additions & 46 deletions GUI/src/main/java/ui/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class Settings {
Scene settingsScene;
private ChoiceBox<String> darkLightTheme = new ChoiceBox<>();

Label lblDwnDir = new Label("Default Download Directory" );
Label lblDwnDir = new Label("Default Download Directory");

private TextField tfCurrDir = new TextField(UIController.form.tfDir.getText());
private TextField tfCurrDir = new TextField(UIController.form.tfDir.getText());

private final String nl = System.lineSeparator();
public static CheckBox autoPasteCheck = new CheckBox();

private void changeFormBtn(String theme){
if(theme.equals("Dark")){
private void changeFormBtn(String theme) {
if (theme.equals("Dark")) {
UIController.form.btnStart.setGraphic(null);
Image imageUp = new Image(Objects.requireNonNull(Constants.class.getResource("/Buttons/Start/StartUp Dark.png")).toExternalForm());
Image imageDown = new Image(Objects.requireNonNull(Constants.class.getResource("/Buttons/Start/StartDown Dark.png")).toExternalForm());
Expand All @@ -54,7 +54,7 @@ private void changeFormBtn(String theme){
UIController.form.btnStart.setOnMousePressed(ev -> UIController.form.btnStart.setGraphic(imageViewDn));
UIController.form.btnStart.setOnMouseReleased(ev -> UIController.form.btnStart.setGraphic(imageViewUp));
UIController.form.btnStart.setGraphic(imageViewUp);
}else{
} else {
UIController.form.btnStart.setGraphic(null);
Image imageUp = new Image(Objects.requireNonNull(Constants.class.getResource("/Buttons/Start/StartUp.png")).toExternalForm());
Image imageDown = new Image(Objects.requireNonNull(Constants.class.getResource("/Buttons/Start/StartDown.png")).toExternalForm());
Expand All @@ -70,12 +70,13 @@ private void changeFormBtn(String theme){
UIController.form.btnStart.setGraphic(imageViewUp);
}
}
Label lblTheme = new Label("Theme" );

Label settingsHeading = new Label("Settings" );
Label lblTheme = new Label("Theme");

Label settingsHeading = new Label("Settings");
private Button button = new Button("Select Directory");
private Stage stage = Constants.getStage("Settings", false);
Label lblAutoPaste = new Label("Auto-Paste" );
Label lblAutoPaste = new Label("Auto-Paste");

public Settings() {

Expand All @@ -94,22 +95,22 @@ public Settings() {
creatDarkThemeLogic();


root.getChildren().addAll(darkLightTheme,autoPasteCheck ,lblTheme , lblAutoPaste , settingsHeading, button , lblDwnDir , tfCurrDir);
settingsScene = Constants.getScene(root);
Constants.addCSS(settingsScene , Constants.SCENE_CSS);
root.getChildren().addAll(darkLightTheme, autoPasteCheck, lblTheme, lblAutoPaste, settingsHeading, button, lblDwnDir, tfCurrDir);
settingsScene = Constants.getScene(root);
Constants.addCSS(settingsScene, Constants.SCENE_CSS);
stage.setMinHeight(Constants.SCREEN_HEIGHT * .55);
stage.setMinWidth(Constants.SCREEN_WIDTH * .5);
stage.setScene(settingsScene);


if(AppSettings.GET.mainTheme().toString().equals("Dark")){
if (AppSettings.GET.mainTheme().toString().equals("Dark")) {

Check notice

Code scanning / CodeQL

Useless toString on String Note

Redundant call to 'toString' on a String object.
settingsScene.getStylesheets().add(Constants.DARK_THEME_CSS.toExternalForm());
lblAutoPaste.setTextFill(Color.WHITE);
lblTheme.setTextFill(Color.WHITE);
tfCurrDir.setStyle("-fx-text-fill: white ; -fx-font-weight: Bold");
settingsHeading.setTextFill(Color.WHITE);

}else{
} else {
tfCurrDir.setStyle("-fx-text-fill: black ; -fx-font-weight: Bold");

lblDwnDir.setTextFill(LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));
Expand All @@ -133,20 +134,20 @@ private void creatDarkThemeLogic() {
System.out.println("Selected: " + darkLightTheme.getItems().get(newValue.intValue()));
});

darkLightTheme.setValue(AppSettings.GET.mainTheme().equals("Dark")? "Dark Theme": "Ligh Theme");
darkLightTheme.setValue(AppSettings.GET.mainTheme().equals("Dark") ? "Dark Theme" : "Ligh Theme");


darkLightTheme.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if(AppSettings.GET.mainTheme().equals("LIGHT")){
if (AppSettings.GET.mainTheme().equals("LIGHT")) {
System.out.println("This is the light theme settings");
}else{
} else {
System.out.println("This is the dark theme settings");
AppSettings.SET.mainTheme("Dark");
}
});

darkLightTheme.setOnAction(e->{
if(darkLightTheme.getValue().equals("Dark Theme")){
darkLightTheme.setOnAction(e -> {
if (darkLightTheme.getValue().equals("Dark Theme")) {
AppSettings.SET.mainTheme("Dark");
settingsScene.getStylesheets().add(Constants.DARK_THEME_CSS.toExternalForm());
Drifty_GUI.scene.getStylesheets().add(Constants.DARK_THEME_CSS.toExternalForm());
Expand All @@ -157,7 +158,7 @@ private void creatDarkThemeLogic() {
lblTheme.setTextFill(Color.WHITE);
settingsHeading.setTextFill(Color.WHITE);
UIController.form.tfDir.setStyle("-fx-text-fill: White;");
if (Drifty_GUI.aboutScene != null){
if (Drifty_GUI.aboutScene != null) {
Drifty_GUI.aboutScene.getStylesheets().add(Constants.DARK_THEME_CSS.toExternalForm());

}
Expand All @@ -180,34 +181,34 @@ private void creatDarkThemeLogic() {
tfCurrDir.setStyle("-fx-text-fill: white ; -fx-font-weight: Bold");
lblDwnDir.setTextFill(Color.WHITE);
button.setStyle(" -fx-text-fill: white;\n" +
" -fx-font-weight: Bold;"+
" -fx-font-weight: Bold;" +
" -fx-background-color: linear-gradient(rgb(0, 53, 105) 20%, rgb(26, 21, 129) 65%, rgb(0, 0, 65) 100%);" +
" -fx-border-color: black;"
);
button.setOnMousePressed(ev->{
button.setOnMousePressed(ev -> {
button.setStyle(
"-fx-text-fill: white;" +
"-fx-font-weight: Bold;"+
"-fx-font-weight: Bold;" +
" -fx-background-color: linear-gradient(rgb(11, 118, 220) 20%, rgb(33, 31, 131) 65%, rgb(2, 2, 168) 100%);\n" +
"-fx-border-color: black;"

); });
button.setOnMouseReleased(ev->{
);
});
button.setOnMouseReleased(ev -> {
button.setStyle(" -fx-text-fill: white;\n" +
"-fx-font-weight: Bold;"+
"-fx-font-weight: Bold;" +
"-fx-background-color: linear-gradient(rgb(0, 53, 105) 20%, rgb(26, 21, 129) 65%, rgb(0, 0, 65) 100%);" +
" -fx-border-color: black;");
});

}
else {
} else {
AppSettings.SET.mainTheme("LIGHT");
lblAutoPaste.setTextFill(LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));
lblTheme.setTextFill(LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));
settingsScene.getStylesheets().remove(getClass().getResource("/CSS/DarkTheme.css").toExternalForm());
Drifty_GUI.scene.getStylesheets().remove(getClass().getResource("/CSS/DarkTheme.css").toExternalForm());
settingsHeading.setTextFill(LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));
if (Drifty_GUI.aboutScene != null){
if (Drifty_GUI.aboutScene != null) {
Drifty_GUI.aboutScene.getStylesheets().remove(getClass().getResource("/CSS/DarkTheme.css").toExternalForm());
}
for (Node node : Drifty_GUI.aboutRoot.getChildren()) {
Expand All @@ -222,7 +223,6 @@ private void creatDarkThemeLogic() {
changeFormBtn("Light");



Constants.IMG_MAIN_GUI_BANNER = new Image(Objects.requireNonNull(Constants.class.getResource("/Backgrounds/DriftyMain.png")).toExternalForm());
MainGridPane.ivLogo.setImage(Constants.IMG_MAIN_GUI_BANNER);

Expand All @@ -233,10 +233,10 @@ private void creatDarkThemeLogic() {

button.setStyle(" -fx-background-color: linear-gradient(rgb(54,151,225) 18%, rgb(121,218,232) 90%, rgb(126,223,255) 95%);\n" +
"-fx-border-color: black;");
button.setOnMousePressed(ev->{
button.setOnMousePressed(ev -> {
button.setStyle(" -fx-background-color: linear-gradient(rgb(126,223,255) 20%, rgb(121,218,232) 20%, rgb(54,151,225) 100%);\n");
});
button.setOnMouseReleased(ev->{
button.setOnMouseReleased(ev -> {
button.setStyle(" -fx-background-color: linear-gradient(rgb(54,151,225) 18%, rgb(121,218,232) 90%, rgb(126,223,255) 95%);\n" +
"-fx-border-color: black;");
});
Expand All @@ -255,7 +255,7 @@ private void creatAutoPasteCheck() {
autoPasteCheck.setMaxWidth(5.0);
autoPasteCheck.setSelected(UIController.isAutoPaste());
autoPasteCheck.selectedProperty().addListener(((observable, oldValue, newValue) -> AppSettings.SET.mainAutoPaste(newValue)));
autoPasteCheck.setOnAction( e-> {
autoPasteCheck.setOnAction(e -> {
UIController.form.cbAutoPaste.setSelected(autoPasteCheck.isSelected());
});
}
Expand All @@ -273,7 +273,6 @@ private void creatLabels() {
lblAutoPaste.setTextFill(LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));



lblTheme.setAlignment(Pos.TOP_CENTER);
lblTheme.setFont(Font.font("Arial", FontWeight.EXTRA_BOLD, 20));
lblTheme.setTextFill(LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));
Expand All @@ -287,8 +286,7 @@ private void creatLabels() {
lblDwnDir.setStyle(
"-fx-font-weight: Bold ; -fx-font-size:20px"
);
lblDwnDir.setTextFill(AppSettings.GET.mainTheme().equals("Dark")? Color.WHITE : LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));

lblDwnDir.setTextFill(AppSettings.GET.mainTheme().equals("Dark") ? Color.WHITE : LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)"));


}
Expand All @@ -299,33 +297,33 @@ private void creatTfDir() {
tfCurrDir.setTranslateX(150);



}

private void creatDirBtn() {
button.setTranslateY(50);
if(AppSettings.GET.mainTheme().equals("Dark")){
if (AppSettings.GET.mainTheme().equals("Dark")) {
button.setStyle(" -fx-text-fill: white;\n" +
" -fx-font-weight: Bold;"+
" -fx-font-weight: Bold;" +
" -fx-background-color: linear-gradient(rgb(0, 53, 105) 20%, rgb(26, 21, 129) 65%, rgb(0, 0, 65) 100%);" +
" -fx-border-color: black;"
);
button.setOnMousePressed(e->{
button.setOnMousePressed(e -> {
button.setStyle(
"-fx-text-fill: white;" +
"-fx-font-weight: Bold;"+
"-fx-font-weight: Bold;" +
" -fx-background-color: linear-gradient(rgb(11, 118, 220) 20%, rgb(33, 31, 131) 65%, rgb(2, 2, 168) 100%);\n" +
"-fx-border-color: black;"

); });
button.setOnMouseReleased(e->{
);
});
button.setOnMouseReleased(e -> {
button.setStyle(" -fx-text-fill: white;\n" +
"-fx-font-weight: Bold;"+
"-fx-font-weight: Bold;" +
"-fx-background-color: linear-gradient(rgb(0, 53, 105) 20%, rgb(26, 21, 129) 65%, rgb(0, 0, 65) 100%);" +
" -fx-border-color: black;");
});

}else{
} else {
button.getStyleClass().add("button");

}
Expand All @@ -335,12 +333,12 @@ private void creatDirBtn() {
DirectoryChooser chooser = new DirectoryChooser();
chooser.setInitialDirectory(new File(System.getProperty("user.home")));
File selectedDirectory = chooser.showDialog(this.stage);
if(selectedDirectory!=null){
if (selectedDirectory != null) {
UIController.form.tfDir.setText(selectedDirectory.getAbsolutePath());
tfCurrDir.setText(UIController.form.tfDir.getText());


}else{
} else {
UIController.form.tfDir.setText(Get.lastDownloadFolder());
tfCurrDir.setText(UIController.form.tfDir.getText());

Expand Down
9 changes: 5 additions & 4 deletions GUI/src/main/java/ui/UIController.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private void start(MainGridPane pane) {
form.tfLink.requestFocus();
commitJobListToListView();
}
public void refresh(){

public void refresh() {
MainGridPane form = new MainGridPane();
UIController.initLogic(form);
}
Expand All @@ -97,7 +98,7 @@ private void setControlProperties() {
form.tfDir.disableProperty().bind(disableInputs);
form.tfFilename.disableProperty().bind(disableInputs);
form.tfLink.disableProperty().bind(disableInputs);
if(AppSettings.GET.mainTheme().equals("Dark")){
if (AppSettings.GET.mainTheme().equals("Dark")) {
form.tfDir.setStyle("-fx-text-fill: White;");
form.tfFilename.setStyle("-fx-text-fill: White;");
form.tfLink.setStyle("-fx-text-fill: White;");
Expand All @@ -122,7 +123,7 @@ private void setControlProperties() {
form.cbAutoPaste.selectedProperty().addListener(((observable, oldValue, newValue) ->
AppSettings.SET.mainAutoPaste(newValue)
));
form.cbAutoPaste.setOnAction( e -> {
form.cbAutoPaste.setOnAction(e -> {
Settings.autoPasteCheck.setSelected(form.cbAutoPaste.isSelected());
});
form.tfDir.textProperty().addListener(((observable, oldValue, newValue) -> {
Expand Down Expand Up @@ -622,7 +623,7 @@ public static void resetDownloadFoldersToActiveList() {
}

public static boolean isAutoPaste() {
return form.cbAutoPaste.isSelected() || AppSettings.GET.alwaysAutoPaste() ;
return form.cbAutoPaste.isSelected() || AppSettings.GET.alwaysAutoPaste();
}

public static void clearJobHistory() {
Expand Down

0 comments on commit 526a443

Please sign in to comment.