Skip to content

Commit

Permalink
fix: implemented all the reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
SaptarshiSarkar12 committed Jun 25, 2024
1 parent 574e60c commit c996294
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 54 deletions.
11 changes: 0 additions & 11 deletions GUI/src/main/java/gui/utils/UIComponentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,10 @@ public Label buildLabel() {
}

public Label buildLabel(String text, Font font, Paint textFill) {
Label label = new Label(text);
label.setFont(font);
label.setTextFill(textFill);
return label;
}

public Label buildLabel(String text, Font font, Paint textFill, double translateX, double translateY) {
Label label = new Label(text);
label.setAlignment(Pos.TOP_CENTER);
label.setFont(font);
label.setTextFill(textFill);
label.setTranslateY(translateY);
if (translateX != 0) {
label.setTranslateX(translateX);
}
return label;
}

Expand Down
74 changes: 55 additions & 19 deletions GUI/src/main/java/ui/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import gui.preferences.AppSettings;
import gui.support.Constants;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Paint;
Expand All @@ -31,6 +34,7 @@ public class Settings {
private Label lblAutoPaste;
private ChoiceBox<String> themeChoiceBox;
private Stage stage;
private GridPane root;

private void initializeComponents() {
initializeUIComponents();
Expand All @@ -49,15 +53,29 @@ private void configureScene() {
stage = Constants.getStage("Settings", false);
stage.setMinHeight(Constants.SCREEN_HEIGHT * .55);
stage.setMinWidth(Constants.SCREEN_WIDTH * .5);
VBox root = new VBox(10);
root.setPadding(new Insets(10));
root.setAlignment(Pos.TOP_CENTER);
root.getChildren().addAll(themeChoiceBox, autoPasteCheckbox, lblTheme, lblAutoPaste, lblSettingsHeading, selectDirectoryButton, lblDefaultDownloadDir, tfCurrentDirectory);
stage.setMaxHeight(Constants.SCREEN_HEIGHT * .6);
stage.setMaxWidth(Constants.SCREEN_WIDTH * .6);
configureLayout();
settingsScene = Constants.getScene(root);
Constants.addCSS(settingsScene, Constants.LIGHT_THEME_CSS);
setInitialTheme(AppSettings.GET.mainTheme());
}

private void configureLayout() {
root = new GridPane();
ColumnConstraints column1 = new ColumnConstraints(); // For the first column, it will take 50% the width of the window
column1.setPercentWidth(50);
ColumnConstraints column2 = new ColumnConstraints(); // For the second column, it will take 50% the width of the window
column2.setPercentWidth(50);
root.getColumnConstraints().addAll(column1, column2);
root.setHgap(20);
root.setVgap(10);
root.setPadding(new Insets(10, 20, 20, 20));
addComponents();
setHAlignments();
setHGrowsAlways(lblSettingsHeading, lblAutoPaste, autoPasteCheckbox, lblTheme, themeChoiceBox, lblDefaultDownloadDir, tfCurrentDirectory, selectDirectoryButton);
}

public void show() {
if (stage != null && stage.isShowing()) {
stage.toFront();
Expand All @@ -68,6 +86,31 @@ public void show() {
}
}

private void setHAlignments() {
GridPane.setHalignment(lblSettingsHeading, HPos.CENTER);
GridPane.setHalignment(lblAutoPaste, HPos.RIGHT);
GridPane.setHalignment(lblTheme, HPos.RIGHT);
GridPane.setHalignment(lblDefaultDownloadDir, HPos.RIGHT);
GridPane.setHalignment(selectDirectoryButton, HPos.CENTER);
}

private void setHGrowsAlways(Node... nodes) {
for (Node node : nodes) {
GridPane.setHgrow(node, Priority.ALWAYS);
}
}

private void addComponents() {
root.add(lblSettingsHeading, 0, 0, 2, 1);
root.add(lblAutoPaste, 0, 1);
root.add(autoPasteCheckbox, 1, 1);
root.add(lblTheme, 0, 2);
root.add(themeChoiceBox, 1, 2);
root.add(lblDefaultDownloadDir, 0, 3);
root.add(tfCurrentDirectory, 1, 3);
root.add(selectDirectoryButton, 1, 4, 2, 1);
}

private void setInitialTheme(String theme) {
boolean isDark = theme.equals("Dark");
Constants.addCSS(settingsScene, isDark ? Constants.DARK_THEME_CSS : Constants.LIGHT_THEME_CSS);
Expand All @@ -86,40 +129,33 @@ private void applyStyleToLabels(boolean isDark, Label... labels) {
private void setupThemeChoice() {
themeChoiceBox = new ChoiceBox<>();
themeChoiceBox.getItems().addAll("Dark Theme", "Light Theme");
themeChoiceBox.setTranslateY(210);
themeChoiceBox.setTranslateX(130);
themeChoiceBox.setValue(AppSettings.GET.mainTheme().equals("Dark") ? "Dark Theme" : "Light Theme");
themeChoiceBox.setOnAction(e -> Theme.applyTheme(themeChoiceBox.getValue().equals("Dark Theme") ? "Dark" : "Light", settingsScene, Drifty_GUI.getScene(), About.getScene(), ConfirmationDialog.getScene()));
}

private void createAutoPasteCheck() {
autoPasteCheckbox = new CheckBox();
autoPasteCheckbox.setSelected(AppSettings.GET.mainAutoPaste());
autoPasteCheckbox.setTranslateX(160);
autoPasteCheckbox.setTranslateY(115);
autoPasteCheckbox.setMaxWidth(5.0);
autoPasteCheckbox.selectedProperty().addListener(((observable, oldValue, newValue) -> AppSettings.SET.mainAutoPaste(newValue)));
}

private void createLabels() {
Paint textFill = LinearGradient.valueOf("linear-gradient(to right, #0f0c29, #302b63, #24243e)");
lblSettingsHeading = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Settings", Font.font("monospace", FontWeight.EXTRA_BOLD, 100), textFill, 0, -150);
lblAutoPaste = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Auto-Paste", Font.font("Arial", FontWeight.EXTRA_BOLD, 20), textFill, 0, 45);
lblTheme = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Theme", Font.font("Arial", FontWeight.EXTRA_BOLD, 20), textFill, -20, 130);
lblDefaultDownloadDir = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Default Download Directory", Font.font("Arial", FontWeight.BOLD, 20), textFill, -160, -50);
lblDefaultDownloadDir.setTranslateX(-160);
lblSettingsHeading = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Settings", Font.font("monospace", FontWeight.EXTRA_BOLD, 100), textFill);
lblAutoPaste = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Auto-Paste", Font.font("Arial", FontWeight.EXTRA_BOLD, 20), textFill);
lblTheme = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Theme", Font.font("Arial", FontWeight.EXTRA_BOLD, 20), textFill);
lblDefaultDownloadDir = UI_COMPONENT_BUILDER_INSTANCE.buildLabel("Default Download Directory", Font.font("Arial", FontWeight.BOLD, 20), textFill);
}

private void createTfDirectory() {
tfCurrentDirectory = new TextField(UIController.form.tfDir.getText());
tfCurrentDirectory.setMaxWidth(200);
tfCurrentDirectory.setTranslateY(-85);
tfCurrentDirectory.setTranslateX(150);
tfCurrentDirectory.setMaxWidth(Double.MAX_VALUE);
tfCurrentDirectory.setEditable(false);
}

private void createDirectoryButton() {
selectDirectoryButton = new Button("Select Directory");
selectDirectoryButton.setTranslateY(50);
if (AppSettings.GET.mainTheme().equals("Dark")) {
selectDirectoryButton.setStyle(Constants.BUTTON_RELEASED);
selectDirectoryButton.setOnMousePressed(e -> selectDirectoryButton.setStyle(Constants.BUTTON_PRESSED));
Expand Down
20 changes: 18 additions & 2 deletions GUI/src/main/resources/META-INF/native-image/jni-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@
"name":"com.sun.javafx.geom.Path2D",
"methods":[{"name":"<init>","parameterTypes":["int","byte[]","int","float[]","int"] }]
},
{
"name":"java.lang.Boolean",
"fields":[{"name":"FALSE"}, {"name":"TRUE"}]
},
{
"name":"java.lang.Iterable",
"methods":[{"name":"iterator","parameterTypes":[] }]
},
{
"name":"java.lang.Object",
"methods":[{"name":"equals","parameterTypes":["java.lang.Object"] }]
},
{
"name":"java.lang.Runnable",
"methods":[{"name":"run","parameterTypes":[] }]
Expand All @@ -84,9 +92,13 @@
"name":"java.util.ArrayList",
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"<init>","parameterTypes":["int"] }, {"name":"add","parameterTypes":["java.lang.Object"] }, {"name":"get","parameterTypes":["int"] }]
},
{
"name":"java.util.Collections",
"methods":[{"name":"unmodifiableMap","parameterTypes":["java.util.Map"] }]
},
{
"name":"java.util.HashMap",
"methods":[{"name":"containsKey","parameterTypes":["java.lang.Object"] }, {"name":"get","parameterTypes":["java.lang.Object"] }, {"name":"put","parameterTypes":["java.lang.Object","java.lang.Object"] }]
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"containsKey","parameterTypes":["java.lang.Object"] }, {"name":"get","parameterTypes":["java.lang.Object"] }, {"name":"put","parameterTypes":["java.lang.Object","java.lang.Object"] }]
},
{
"name":"java.util.HashSet",
Expand All @@ -98,10 +110,14 @@
},
{
"name":"java.util.Map",
"methods":[{"name":"containsKey","parameterTypes":["java.lang.Object"] }, {"name":"get","parameterTypes":["java.lang.Object"] }, {"name":"keySet","parameterTypes":[] }]
"methods":[{"name":"containsKey","parameterTypes":["java.lang.Object"] }, {"name":"get","parameterTypes":["java.lang.Object"] }, {"name":"keySet","parameterTypes":[] }, {"name":"put","parameterTypes":["java.lang.Object","java.lang.Object"] }]
},
{
"name":"java.util.Set",
"methods":[{"name":"add","parameterTypes":["java.lang.Object"] }, {"name":"size","parameterTypes":[] }, {"name":"toArray","parameterTypes":["java.lang.Object[]"] }]
},
{
"name":"javafx.scene.paint.Color",
"methods":[{"name":"rgb","parameterTypes":["int","int","int","double"] }]
}
]
15 changes: 11 additions & 4 deletions GUI/src/main/resources/META-INF/native-image/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"name":"com.sun.prism.shader.Mask_TextureSuper_Loader",
"methods":[{"name":"loadShader","parameterTypes":["com.sun.prism.ps.ShaderFactory","java.io.InputStream"] }]
},
{
"name":"com.sun.prism.shader.Solid_Color_Loader",
"methods":[{"name":"loadShader","parameterTypes":["com.sun.prism.ps.ShaderFactory","java.io.InputStream"] }]
},
{
"name":"com.sun.prism.shader.Solid_TextureFirstPassLCD_Loader",
"methods":[{"name":"loadShader","parameterTypes":["com.sun.prism.ps.ShaderFactory","java.io.InputStream"] }]
Expand All @@ -131,6 +135,10 @@
"name":"com.sun.scenario.effect.impl.prism.PrRenderer",
"methods":[{"name":"createRenderer","parameterTypes":["com.sun.scenario.effect.FilterContext"] }]
},
{
"name":"com.sun.scenario.effect.impl.prism.ps.PPSBlend_SRC_INPeer",
"methods":[{"name":"<init>","parameterTypes":["com.sun.scenario.effect.FilterContext","com.sun.scenario.effect.impl.Renderer","java.lang.String"] }]
},
{
"name":"com.sun.scenario.effect.impl.prism.ps.PPSLinearConvolveShadowPeer",
"methods":[{"name":"<init>","parameterTypes":["com.sun.scenario.effect.FilterContext","com.sun.scenario.effect.impl.Renderer","java.lang.String"] }]
Expand Down Expand Up @@ -264,6 +272,9 @@
{
"name":"javafx.scene.control.Control"
},
{
"name":"javafx.scene.control.Labeled"
},
{
"name":"javafx.scene.effect.Effect"
},
Expand Down Expand Up @@ -418,10 +429,6 @@
"name":"sun.security.rsa.RSASignature$SHA256withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSASignature$SHA384withRSA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.KeyManagerFactoryImpl$SunX509",
"methods":[{"name":"<init>","parameterTypes":[] }]
Expand Down
Loading

0 comments on commit c996294

Please sign in to comment.