Skip to content
Snippets Groups Projects
Commit 3127a10d authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Rebased

parent b90e5086
No related branches found
No related tags found
No related merge requests found
...@@ -40,12 +40,16 @@ import java.io.IOException; ...@@ -40,12 +40,16 @@ import java.io.IOException;
public class ChaosGameGui implements ChaosGameObserver { public class ChaosGameGui implements ChaosGameObserver {
private int currentLine = 0; private int currentLine = 0;
/**
* The primary stage for the GUI.
*/
private Stage primaryStage; private Stage primaryStage;
/**
* The aspect ratio of the GUI.
*/
private double aspectRatio; private double aspectRatio;
/** /**
* The canvas for this GUI. * The canvas for this GUI.
*/ */
...@@ -122,13 +126,24 @@ public class ChaosGameGui implements ChaosGameObserver { ...@@ -122,13 +126,24 @@ public class ChaosGameGui implements ChaosGameObserver {
*/ */
private Button clearButton; private Button clearButton;
/**
* The quit button for the GUI.
*/
private Button quitButton; private Button quitButton;
/**
* The side menu button for the GUI.
*/
private Button sideMenuButton; private Button sideMenuButton;
/** /**
* The load fractal from file and write fractal to file buttons for the GUI. * The load fractal from file and write fractal to file buttons for the GUI.
*/ */
private Button loadFractalFromFileButton; private Button loadFractalFromFileButton;
/**
* The write fractal to file button for the GUI.
*/
private Button writeFractalToFileButton; private Button writeFractalToFileButton;
/** /**
...@@ -172,23 +187,24 @@ public class ChaosGameGui implements ChaosGameObserver { ...@@ -172,23 +187,24 @@ public class ChaosGameGui implements ChaosGameObserver {
* @param primaryStage the primary stage for the GUI. * @param primaryStage the primary stage for the GUI.
* @throws IOException if the GUI fails to initialize. * @throws IOException if the GUI fails to initialize.
*/ */
public ChaosGameGui(Stage primaryStage) throws IOException { public ChaosGameGui(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
this.initializeComponents(); this.initializeComponents();
this.initializeGameComponents(); this.initializeGameComponents();
this.controller = new GuiButtonController(game, this); // Initialize controller here this.controller = new GuiButtonController(game, this); // Initialize controller here
primaryStage.setTitle("Fractal Chaos Game"); primaryStage.setTitle("Fractal Chaos Game");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.setOnShown(event -> this.imageView.requestFocus()); primaryStage.setOnShown(event -> this.imageView.requestFocus());
primaryStage.show(); primaryStage.show();
// Initialize aspect ratio based on initial dimensions // Initialize aspect ratio based on initial dimensions
this.aspectRatio = (double) width / height; this.aspectRatio = (double) width / height;
// Add listeners to handle window size changes // Add listeners to handle window size changes
scene.widthProperty().addListener((observable, oldValue, newValue) -> { scene.widthProperty().addListener((observable, oldValue, newValue) -> {
resizeCanvas(); resizeCanvas();
}); });
scene.heightProperty().addListener((observable, oldValue, newValue) -> { scene.heightProperty().addListener((observable, oldValue, newValue) -> {
resizeCanvas(); resizeCanvas();
...@@ -200,6 +216,8 @@ sideMenu.prefWidthProperty().bind(scene.widthProperty().multiply(0.2)); // 20% o ...@@ -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 // Bind the height of the sideMenu to the height of the scene
sideMenu.prefHeightProperty().bind(scene.heightProperty()); sideMenu.prefHeightProperty().bind(scene.heightProperty());
} }
/** /**
* Initialize the components of the GUI. * Initialize the components of the GUI.
*/ */
...@@ -226,35 +244,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); ...@@ -226,35 +244,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
return textField; 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. * Initialize the components related to the chaos game itself.
*/ */
...@@ -313,8 +302,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); ...@@ -313,8 +302,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
this.improvedBarnsleyButton = new RadioButton("Improved Barnsley"); this.improvedBarnsleyButton = new RadioButton("Improved Barnsley");
improvedBarnsleyButton.setToggleGroup(group); improvedBarnsleyButton.setToggleGroup(group);
// Load fractal file button and tooltip // Load fractal file button and tooltip
this.loadFractalFromFileButton = new Button("Load Fractal"); this.loadFractalFromFileButton = new Button("Load Fractal");
Tooltip loadFractalFromFileButtonTooltip = new Tooltip("Load a text file describing a new fractal chaos game"); Tooltip loadFractalFromFileButtonTooltip = new Tooltip("Load a text file describing a new fractal chaos game");
...@@ -354,7 +341,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); ...@@ -354,7 +341,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
Tooltip clearButtonTooltip = new Tooltip("Clear the current fracal"); Tooltip clearButtonTooltip = new Tooltip("Clear the current fracal");
Tooltip quitButtonTooltip = new Tooltip("Quit the application"); Tooltip quitButtonTooltip = new Tooltip("Quit the application");
// Attach Tooltips to Buttons // Attach Tooltips to Buttons
Tooltip.install(startButton,startButtonTooltip); Tooltip.install(startButton,startButtonTooltip);
Tooltip.install(stopButton,stopButtonTooltip); Tooltip.install(stopButton,stopButtonTooltip);
...@@ -362,6 +348,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); ...@@ -362,6 +348,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
Tooltip.install(quitButton, quitButtonTooltip); Tooltip.install(quitButton, quitButtonTooltip);
this.sideMenu = new VBox(); this.sideMenu = new VBox();
//this.sideMenu.setAlignment(Pos.CENTER);
// Parameters // Parameters
VBox parameterBox = new VBox(); VBox parameterBox = new VBox();
VBox controlButtonBox = new VBox(); VBox controlButtonBox = new VBox();
...@@ -466,9 +453,9 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); ...@@ -466,9 +453,9 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
parameterBox.setPadding(new Insets(10)); parameterBox.setPadding(new Insets(10));
// Add basic control buttons // Add basic control buttons
controlButtonBox.getChildren().addAll(canvasLabel,startButton, stopButton,clearButton);
controlButtonBox.setAlignment(Pos.CENTER); controlButtonBox.setAlignment(Pos.CENTER);
controlButtonBox.getChildren().addAll(canvasLabel,startButton, stopButton,clearButton);
controlButtonBox.setSpacing(5); controlButtonBox.setSpacing(5);
sideMenu.getChildren().add(controlButtonBox); sideMenu.getChildren().add(controlButtonBox);
...@@ -580,7 +567,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); ...@@ -580,7 +567,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
return this.chaosCanvas; return this.chaosCanvas;
} }
public int getWidth(){ public int getWidth(){
return this.width; return this.width;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment