diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java index 7a62aee18db1ac770ff154bb86ec7cd6e026ecbd..b0b8d79e565ad6474cad484058a9f2dafb8f0e25 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java @@ -40,12 +40,16 @@ import java.io.IOException; public class ChaosGameGui implements ChaosGameObserver { private int currentLine = 0; + /** + * The primary stage for the GUI. + */ private Stage primaryStage; + /** + * The aspect ratio of the GUI. + */ private double aspectRatio; - - /** * The canvas for this GUI. */ @@ -122,13 +126,24 @@ public class ChaosGameGui implements ChaosGameObserver { */ private Button clearButton; + /** + * The quit button for the GUI. + */ private Button quitButton; + + /** + * The side menu button for the GUI. + */ private Button sideMenuButton; /** * The load fractal from file and write fractal to file buttons for the GUI. */ private Button loadFractalFromFileButton; + + /** + * The write fractal to file button for the GUI. + */ private Button writeFractalToFileButton; /** @@ -172,23 +187,24 @@ public class ChaosGameGui implements ChaosGameObserver { * @param primaryStage the primary stage for the GUI. * @throws IOException if the GUI fails to initialize. */ -public ChaosGameGui(Stage primaryStage) throws IOException { - this.primaryStage = primaryStage; - this.initializeComponents(); - this.initializeGameComponents(); - this.controller = new GuiButtonController(game, this); // Initialize controller here - - primaryStage.setTitle("Fractal Chaos Game"); - primaryStage.setScene(scene); - primaryStage.setOnShown(event -> this.imageView.requestFocus()); - primaryStage.show(); - // Initialize aspect ratio based on initial dimensions - this.aspectRatio = (double) width / height; - - // Add listeners to handle window size changes - scene.widthProperty().addListener((observable, oldValue, newValue) -> { - resizeCanvas(); - }); + public ChaosGameGui(Stage primaryStage) throws IOException { + this.primaryStage = primaryStage; + this.initializeComponents(); + this.initializeGameComponents(); + this.controller = new GuiButtonController(game, this); // Initialize controller here + + primaryStage.setTitle("Fractal Chaos Game"); + primaryStage.setScene(scene); + primaryStage.setOnShown(event -> this.imageView.requestFocus()); + primaryStage.show(); + // Initialize aspect ratio based on initial dimensions + this.aspectRatio = (double) width / height; + + // Add listeners to handle window size changes + scene.widthProperty().addListener((observable, oldValue, newValue) -> { + resizeCanvas(); + }); + scene.heightProperty().addListener((observable, oldValue, newValue) -> { resizeCanvas(); @@ -200,6 +216,8 @@ sideMenu.prefWidthProperty().bind(scene.widthProperty().multiply(0.2)); // 20% o // Bind the height of the sideMenu to the height of the scene sideMenu.prefHeightProperty().bind(scene.heightProperty()); } + + /** * Initialize the components of the GUI. */ @@ -226,35 +244,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); return textField; } - /** - * Initialize the main buttons for the GUI. - */ -// private void initializeMainButtons() { -// this.startButton = new Button("Start"); -// startButton.setOnAction(event -> controller.startGame()); -// this.stopButton = new Button("Stop"); -// stopButton.setOnAction(event -> controller.stopGame()); -// -// this.newButton = new Button("New"); -// -// newButton.setOnAction(event ->{ -// this.canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); -// chaosCanvas.clearCanvas(); -// }); -// -// this.clearButton = new Button("Clear"); -// -// clearButton.setOnAction(event -> { -// getImageView().setImage(null); -// setCurrentLine(0); -// }); -// -// // Quit button -// this.quitButton = new Button("Quit"); -// quitButton.setOnAction(event -> Platform.exit()); -// -// } - /** * Initialize the components related to the chaos game itself. */ @@ -313,8 +302,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); this.improvedBarnsleyButton = new RadioButton("Improved Barnsley"); improvedBarnsleyButton.setToggleGroup(group); - - // Load fractal file button and tooltip this.loadFractalFromFileButton = new Button("Load Fractal"); Tooltip loadFractalFromFileButtonTooltip = new Tooltip("Load a text file describing a new fractal chaos game"); @@ -354,7 +341,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); Tooltip clearButtonTooltip = new Tooltip("Clear the current fracal"); Tooltip quitButtonTooltip = new Tooltip("Quit the application"); - // Attach Tooltips to Buttons Tooltip.install(startButton,startButtonTooltip); Tooltip.install(stopButton,stopButtonTooltip); @@ -362,6 +348,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); Tooltip.install(quitButton, quitButtonTooltip); this.sideMenu = new VBox(); + //this.sideMenu.setAlignment(Pos.CENTER); // Parameters VBox parameterBox = new VBox(); VBox controlButtonBox = new VBox(); @@ -466,9 +453,9 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); parameterBox.setPadding(new Insets(10)); // Add basic control buttons - - controlButtonBox.getChildren().addAll(canvasLabel,startButton, stopButton,clearButton); controlButtonBox.setAlignment(Pos.CENTER); + controlButtonBox.getChildren().addAll(canvasLabel,startButton, stopButton,clearButton); + controlButtonBox.setSpacing(5); sideMenu.getChildren().add(controlButtonBox); @@ -580,7 +567,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); return this.chaosCanvas; } - public int getWidth(){ return this.width; }