diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java index fc06e509aa22b39fe9ecbdf4b19c139c88ecd4a2..3c84ec8eca08b12bd82a9d3a7cf75f9d2125ea2b 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameDescription.java @@ -94,5 +94,14 @@ public class ChaosGameDescription { return maxCoords; } + /** + * Getter method for the name of the chaos game. + * + * @return the name of the chaos game description. + */ + public String getName() { + return name; + } + } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java index 671d08d19572f8a5fd61cb3ff0a4f639adb8afc5..f4d4a100f61e71d414a0a56aaae49c3287c54122 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGameFileHandler.java @@ -64,7 +64,6 @@ public class ChaosGameFileHandler { } - // Read the transforms while (scanner.hasNextDouble()) { double a00 = scanner.nextDouble(); diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java index 5c06b2bafd001525e511aa4e6758eda57d1632ff..ca8b5e046ca230d8f4a02ad59db43193ebfeddf8 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/GuiButtonController.java @@ -176,6 +176,7 @@ public class GuiButtonController { * Clear the image view. */ public void clearImageView() { + chaosCanvas.clearCanvas(); GraphicsContext gc = gui.getCanvas().getGraphicsContext2D(); gc.clearRect(0, 0, gui.getCanvas().getWidth(), gui.getCanvas().getHeight()); gui.getImageView().setImage(null); diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java b/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java index 11cd36fd04b70d5aca8f543d07867af279216988..73555b781ebb99f163c2439e521cad03d605bbf4 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/generators/ChaosGameDescriptionFactory.java @@ -30,7 +30,7 @@ public class ChaosGameDescriptionFactory { /** * The directory where the descriptions are located. */ - String directory1 = "src/main/resources/descriptions/factory/"; + String directory1 = "src/main/resources/descriptions/saved_descriptions/"; this.descriptions = new ArrayList<>(); ChaosGameFileHandler handler = new ChaosGameFileHandler(); File directory = new File(directory1); 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 5b1db2df705ba6140f402d684ce132c11275fd92..c6f3aba3bb344648462ca04250cbe4a9ad658a2e 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java @@ -19,7 +19,6 @@ import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.image.WritableImage; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.text.Font; @@ -32,9 +31,7 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.stage.Window; import javafx.util.Duration; -import javafx.scene.control.ToolBar; -import javax.tools.Tool; import java.io.IOException; // todo: look through GUI and get rid of redundancies, clean up code public class ChaosGameGui implements ChaosGameObserver { @@ -166,6 +163,9 @@ public class ChaosGameGui implements ChaosGameObserver { */ private RadioButton improvedBarnsleyButton; + /** + * A description ComboBox for choosing different fractal descriptions. + */ private ComboBox<String> descriptionComboBox; /** @@ -212,12 +212,12 @@ public class ChaosGameGui implements ChaosGameObserver { resizeCanvas(); }); -// Bind the width of the sideMenu to the width of the scene -sideMenu.prefWidthProperty().bind(scene.widthProperty().multiply(0.2)); // 20% of the scene width + // Bind the width of the sideMenu to the width of the scene + sideMenu.prefWidthProperty().bind(scene.widthProperty().multiply(0.2)); // 20% of the scene width -// Bind the height of the sideMenu to the height of the scene -sideMenu.prefHeightProperty().bind(scene.heightProperty()); -} + // Bind the height of the sideMenu to the height of the scene + sideMenu.prefHeightProperty().bind(scene.heightProperty()); + } /** @@ -230,7 +230,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); this.initializeImageView(); //this.initializeMainButtons(); - this.initializeFractalButtons(); + this.initializeFractalComponents(); this.initializeSideMenu(); this.scene = new Scene(this.borderPane,1700,1000); @@ -290,7 +290,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); /** * Initialize the buttons related to managing the fractals. */ - private void initializeFractalButtons() { + private void initializeFractalComponents() { // Radio buttons for choosing fractal type ToggleGroup group = new ToggleGroup(); @@ -304,7 +304,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); this.improvedBarnsleyButton = new RadioButton("Improved Barnsley"); improvedBarnsleyButton.setToggleGroup(group); - this.descriptionComboBox = new ComboBox<>(); @@ -327,6 +326,26 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); controller.updateDescription(3); }); + // Recreate the ChaosGameDescriptionFactory and update the ComboBox items each time the ComboBox is shown + descriptionComboBox.setOnShowing(event -> { + factory = new ChaosGameDescriptionFactory(); + descriptionComboBox.getItems().clear(); + for (ChaosGameDescription description : factory.getDescriptions()) { + descriptionComboBox.getItems().add(description.getName()); + } + }); + + // Update the controller's description when a new item is selected in the ComboBox + descriptionComboBox.getSelectionModel().selectedItemProperty() + .addListener((observable, oldValue, newValue) -> { + for (int i = 0; i < factory.getDescriptions().size(); i++) { + if (description.getName().equals(newValue)) { + controller.updateDescription(i); + break; + } + } + }); + // 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"); @@ -379,9 +398,9 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); VBox controlButtonBox = new VBox(); controlButtonBox.setBorder(blackBorder); controlButtonBox.setPadding(new Insets(5,5,5,5)); - VBox radioButtonBox = new VBox(); - radioButtonBox.setBorder(blackBorder); - radioButtonBox.setPadding(new Insets(5,5,5,5)); + VBox descriptionBox = new VBox(); + descriptionBox.setBorder(blackBorder); + descriptionBox.setPadding(new Insets(5,5,5,5)); VBox bottomButtonBox = new VBox(); // Step Count GUI @@ -491,16 +510,15 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty()); sideMenu.getChildren().addAll(startButton,stopButton, clearButton); - //Radio Button header label Label chaosGameTypeLabel = new Label("Chaos Game Selection"); chaosGameTypeLabel.setFont(new Font("Arial",20)); chaosGameTypeLabel.setAlignment(Pos.CENTER); // Add fractal radio buttons - radioButtonBox.getChildren().addAll(chaosGameTypeLabel,sierpinskiRadioButton, barnsleyRadioButton, juliaRadioButton, - improvedBarnsleyButton); - radioButtonBox.setSpacing(5); - sideMenu.getChildren().add(radioButtonBox); + descriptionBox.getChildren().addAll(chaosGameTypeLabel,sierpinskiRadioButton, barnsleyRadioButton, juliaRadioButton, + improvedBarnsleyButton, descriptionComboBox); + descriptionBox.setSpacing(5); + sideMenu.getChildren().add(descriptionBox); sideMenu.getChildren().addAll(separator1, colorVBox, separator2); //this.initializeColorButtonHandler(); diff --git a/src/main/resources/descriptions/factory/desc_1.txt b/src/main/resources/descriptions/saved_descriptions/desc_1.txt similarity index 96% rename from src/main/resources/descriptions/factory/desc_1.txt rename to src/main/resources/descriptions/saved_descriptions/desc_1.txt index 1981cb8536d68a2c4082bbb2c654b8a6c4b73b21..9962b6f0e4c2a02c1bc8552d5ecc869c4b698737 100644 --- a/src/main/resources/descriptions/factory/desc_1.txt +++ b/src/main/resources/descriptions/saved_descriptions/desc_1.txt @@ -1,5 +1,5 @@ Affine2D # Type of transform -Test1 +Sierpinski 0, 0 # Lower left 1, 1 # Upper right .5, 0, 0, .5, 0, 0 # 1st transform (a00, a01, a10, a11, b0, b1) diff --git a/src/main/resources/descriptions/factory/desc_2.txt b/src/main/resources/descriptions/saved_descriptions/desc_2.txt similarity index 96% rename from src/main/resources/descriptions/factory/desc_2.txt rename to src/main/resources/descriptions/saved_descriptions/desc_2.txt index 43a4dd63b770ba417890b59594cc9a0d011ea7e0..e0f91d7966dea3096e89abc654b5efe46b732380 100644 --- a/src/main/resources/descriptions/factory/desc_2.txt +++ b/src/main/resources/descriptions/saved_descriptions/desc_2.txt @@ -1,5 +1,5 @@ Affine2D # Type of transform -Test2 +Barnsley -2.65, 0 # lower left 2.65, 10 # upper right 0, 0, 0, .16, 0, 0 # transforms diff --git a/src/main/resources/descriptions/factory/desc_3.txt b/src/main/resources/descriptions/saved_descriptions/desc_3.txt similarity index 96% rename from src/main/resources/descriptions/factory/desc_3.txt rename to src/main/resources/descriptions/saved_descriptions/desc_3.txt index 8fdd084fd7d681792c6f1c52b03ac5bacfb92aba..9201507c867e30da0b214b0f528f41764d70a10d 100644 --- a/src/main/resources/descriptions/factory/desc_3.txt +++ b/src/main/resources/descriptions/saved_descriptions/desc_3.txt @@ -1,5 +1,5 @@ Julia # Type of transform -Test3 +Julia -1.6, -1 # Lower left 1.6, 1 # Upper right -.74543, .11301 # Real and imaginary parts of the constant c \ No newline at end of file diff --git a/src/main/resources/descriptions/factory/desc_4.txt b/src/main/resources/descriptions/saved_descriptions/desc_4.txt similarity index 100% rename from src/main/resources/descriptions/factory/desc_4.txt rename to src/main/resources/descriptions/saved_descriptions/desc_4.txt diff --git a/src/main/resources/descriptions/factory/desc_5.txt b/src/main/resources/descriptions/saved_descriptions/desc_5.txt similarity index 100% rename from src/main/resources/descriptions/factory/desc_5.txt rename to src/main/resources/descriptions/saved_descriptions/desc_5.txt