diff --git a/src/main/java/edu/ntnu/idatt2003/controller/ButtonObserver.java b/src/main/java/edu/ntnu/idatt2003/controller/ButtonObserver.java index 6194986209db9e463ea5adf27cf221a9ced776d3..16c1c3addaf713940d120d6220815980ca73dbbf 100644 --- a/src/main/java/edu/ntnu/idatt2003/controller/ButtonObserver.java +++ b/src/main/java/edu/ntnu/idatt2003/controller/ButtonObserver.java @@ -1,27 +1,33 @@ package edu.ntnu.idatt2003.controller; +import edu.ntnu.idatt2003.model.*; import edu.ntnu.idatt2003.view.components.Buttons; import edu.ntnu.idatt2003.view.components.FractalOperations; import edu.ntnu.idatt2003.view.components.TextFields; -import java.io.File; import javafx.application.Platform; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.stage.FileChooser; -import java.io.File; import javafx.stage.Stage; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import javafx.scene.layout.VBox; +import javafx.scene.layout.HBox; +import javafx.scene.Node; /** * This class is responsible for handling button events. */ -public class ButtonObserver implements Observer{ +public class ButtonObserver implements Observer { private ExceptionHandler exceptionHandler = new ExceptionHandler(); private Buttons buttons; private FractalOperations fractalOperations; private TextFields textFields; private Label iterationsLabel; + private VBox inputContainer; // Add this line to include inputContainer /** * Constructs a ButtonObserver with the given buttons, fractalOperations, @@ -33,11 +39,12 @@ public class ButtonObserver implements Observer{ * @param iterationsLabel the iterationsLabel */ public ButtonObserver(Buttons buttons, FractalOperations fractalOperations, - TextFields textFields, Label iterationsLabel) { + TextFields textFields, Label iterationsLabel, VBox inputContainer) { this.buttons = buttons; this.fractalOperations = fractalOperations; this.textFields = textFields; this.iterationsLabel = iterationsLabel; + this.inputContainer = inputContainer; // Add this line to include inputContainer buttons.attach(this); } @@ -109,8 +116,101 @@ public class ButtonObserver implements Observer{ } break; + case "btnUpdateAll": + try { + double xMin = Double.parseDouble(textFields.getxMinInput().getText()); + double yMin = Double.parseDouble(textFields.getyMinInput().getText()); + double xMax = Double.parseDouble(textFields.getxMaxInput().getText()); + double yMax = Double.parseDouble(textFields.getyMaxInput().getText()); + //updateMinAndMax(new Vector2D(xMin, yMin), new Vector2D(xMax, yMax)); + + String selectedFractal = fractalOperations.getChaosGame().getChaosGameDescription().getTransforms().getFirst().getTransformType(); + if ("Julia".equals(selectedFractal)) { + double realPart = Double.parseDouble(textFields.getRealPartInput().getText()); + double imaginaryPart = Double.parseDouble(textFields.getImaginaryPartInput().getText()); + fractalOperations.updateJuliaSet(new Complex(realPart, imaginaryPart), -1, new Vector2D(xMin, yMin), new Vector2D(xMax, yMax)); + fractalOperations.updateMinAndMaxFractal(new Vector2D(xMin, yMin), new Vector2D(xMax, yMax)); + fractalOperations.resetIterations(); + } else if ("Affine2D".equals(selectedFractal)) { + updateAffineTransforms(inputContainer); + fractalOperations.resetIterations(); + } + } catch (NumberFormatException e) { + System.out.println("Invalid input for min or max values."); + } + break; + default: break; } } -} \ No newline at end of file + + private void updateMinAndMax(Vector2D minCoords, Vector2D maxCoords) { + fractalOperations.updateMinAndMaxFractal(minCoords, maxCoords); + } + + private void updateAffineTransforms(VBox inputContainer) { + List<Transform2D> transforms = new ArrayList<>(); + for (Node node : inputContainer.getChildren()) { + if (node instanceof HBox) { + HBox matrixVectorBox = (HBox) node; + VBox matrixBox = (VBox) matrixVectorBox.getChildren().get(0); + VBox vectorBox = (VBox) matrixVectorBox.getChildren().get(1); + + TextField matrixInput1 = (TextField) ((HBox) matrixBox.getChildren().get(1)).getChildren().get(0); + TextField matrixInput2 = (TextField) ((HBox) matrixBox.getChildren().get(1)).getChildren().get(1); + TextField matrixInput3 = (TextField) ((HBox) matrixBox.getChildren().get(2)).getChildren().get(0); + TextField matrixInput4 = (TextField) ((HBox) matrixBox.getChildren().get(2)).getChildren().get(1); + TextField vectorInput1 = (TextField) vectorBox.getChildren().get(1); + TextField vectorInput2 = (TextField) vectorBox.getChildren().get(2); + + try { + double m00 = Double.parseDouble(matrixInput1.getText()); + double m01 = Double.parseDouble(matrixInput2.getText()); + double m10 = Double.parseDouble(matrixInput3.getText()); + double m11 = Double.parseDouble(matrixInput4.getText()); + double v0 = Double.parseDouble(vectorInput1.getText()); + double v1 = Double.parseDouble(vectorInput2.getText()); + + Transform2D transform = new AffineTransform2D(new Matrix2x2(m00, m01, m10, m11), new Vector2D(v0, v1)); + transforms.add(transform); + } catch (NumberFormatException e) { + System.out.println("Invalid input for matrix or vector values."); + } + } + } + + double xMin, yMin, xMax, yMax; + + try { + xMin = Double.parseDouble(textFields.getxMinInput().getText()); + yMin = Double.parseDouble(textFields.getyMinInput().getText()); + xMax = Double.parseDouble(textFields.getxMaxInput().getText()); + yMax = Double.parseDouble(textFields.getyMaxInput().getText()); + } catch (NumberFormatException e) { + // Set to default values if parsing fails + if ("Barnsley Fern".equals(fractalOperations.getCurrentFractal())) { + xMin = -2.5; + yMin = 0; + xMax = 2.5; + yMax = 10; + } else { + xMin = 0; + yMin = 0; + xMax = 1; + yMax = 1; + } + } + + Vector2D lowerLeft = new Vector2D(xMin, yMin); + Vector2D upperRight = new Vector2D(xMax, yMax); + + ChaosGameDescription description = new ChaosGameDescription(transforms, lowerLeft, upperRight); + System.out.println("Transforms updated: " + transforms.size()); + fractalOperations.updateMatrixAndVector(description); + } + + public void setInputContainer(VBox inputContainer) { + this.inputContainer = inputContainer; + } +} diff --git a/src/main/java/edu/ntnu/idatt2003/view/components/Buttons.java b/src/main/java/edu/ntnu/idatt2003/view/components/Buttons.java index 51f8283a31fa9062bd723f8ccc6c661d135d9e28..014158a32c95723b8ebd93c25dfe0d07999027b4 100644 --- a/src/main/java/edu/ntnu/idatt2003/view/components/Buttons.java +++ b/src/main/java/edu/ntnu/idatt2003/view/components/Buttons.java @@ -19,7 +19,6 @@ public class Buttons extends Subject { private Button btnAddFractalFromFile; private Button btnSaveFractalToFile; private Button btnExitApplication; - private Button btnUpdateAll; /** @@ -81,7 +80,7 @@ public class Buttons extends Subject { notifyObservers("btnSaveFractalToFile"); }); - btnUpdateAll = new Button("Update All"); + btnUpdateAll = new Button("Update all values"); btnUpdateAll.setOnAction(e -> { System.out.println("Update All"); notifyObservers("btnUpdateAll"); diff --git a/src/main/java/edu/ntnu/idatt2003/view/components/FractalOperations.java b/src/main/java/edu/ntnu/idatt2003/view/components/FractalOperations.java index 107190553865532fcd7448dbfd2343473281dc76..31332fff0fc3dbb67fb970f19f48fae3e49529a6 100644 --- a/src/main/java/edu/ntnu/idatt2003/view/components/FractalOperations.java +++ b/src/main/java/edu/ntnu/idatt2003/view/components/FractalOperations.java @@ -58,9 +58,11 @@ public class FractalOperations implements ChaosGameObserver { } public void resetIterations() { - chaosGame.getCanvas().clear(); - this.chaosGame.addObserver(this); - drawFractal(0); + if (chaosGame != null) { + chaosGame.getCanvas().clear(); + this.chaosGame.addObserver(this); + drawFractal(0); + } } /** @@ -83,7 +85,7 @@ public class FractalOperations implements ChaosGameObserver { */ public void setFractalToSierpinskiTriangle() { this.chaosGame = new ChaosGame(ChaosGameDescriptionFactory.createSierpinskiTriangle(), - 400, 400); + 400, 400); this.chaosGame.addObserver(this); drawFractal(0); } @@ -93,7 +95,7 @@ public class FractalOperations implements ChaosGameObserver { */ public void setFractalToJuliaSet() { this.chaosGame = new ChaosGame(ChaosGameDescriptionFactory.createJuliaSet(new Complex(-0.74543, 0.11301), - 1), 400, 400); + 1), 400, 400); this.chaosGame.addObserver(this); drawFractal(0); } @@ -104,7 +106,7 @@ public class FractalOperations implements ChaosGameObserver { public void setFractalToBransleysFern() { this.chaosGame = new ChaosGame(ChaosGameDescriptionFactory.createBarnsleyFern(), 400, 400); this.chaosGame.addObserver(this); - //drawFractal(0); + drawFractal(0); } /** @@ -118,7 +120,7 @@ public class FractalOperations implements ChaosGameObserver { ChaosGameDescription description = fileHandler.readFile(); this.chaosGame = new ChaosGame(description, 400, 400); this.chaosGame.addObserver(this); - //drawFractal(0); + drawFractal(0); } catch (IOException e) { e.printStackTrace(); } @@ -133,10 +135,10 @@ public class FractalOperations implements ChaosGameObserver { Vector2D defaultUpperRight = new Vector2D(0, 0); ChaosGameDescription description = new ChaosGameDescription(Arrays.asList(defaultTransforms), - defaultLowerLeft, defaultUpperRight); + defaultLowerLeft, defaultUpperRight); this.chaosGame = new ChaosGame(description, 400, 400); this.chaosGame.addObserver(this); - //drawFractal(0); + drawFractal(0); } /** @@ -147,6 +149,7 @@ public class FractalOperations implements ChaosGameObserver { public void updateC(Complex complex) { this.chaosGame = new ChaosGame(createJuliaSet(complex, -1), 400, 400); this.chaosGame.addObserver(this); + drawFractal(0); } /** @@ -157,17 +160,17 @@ public class FractalOperations implements ChaosGameObserver { public void updateMatrixAndVector(ChaosGameDescription description) { this.chaosGame = new ChaosGame(description, 400, 400); this.chaosGame.addObserver(this); - //drawFractal(0); + drawFractal(0); } - public void updateJuliaSet(Complex complex, int sign, Vector2D minCoords, Vector2D maxCoords) { JuliaTransform[] transforms = new JuliaTransform[2]; transforms[0] = new JuliaTransform(complex, sign); transforms[1] = new JuliaTransform(complex, -sign); ChaosGameDescription newChaosGame = new ChaosGameDescription(Arrays.asList(transforms), - minCoords, maxCoords); + minCoords, maxCoords); this.chaosGame = new ChaosGame(newChaosGame, 400, 400); + drawFractal(0); } public String getCurrentFractal() { @@ -191,7 +194,7 @@ public class FractalOperations implements ChaosGameObserver { */ public void updateMinAndMaxFractal(Vector2D minCoords, Vector2D maxCoords) { ChaosGameDescription newChaosGame = new ChaosGameDescription( - chaosGame.getChaosGameDescription().getTransforms(), minCoords, maxCoords); + chaosGame.getChaosGameDescription().getTransforms(), minCoords, maxCoords); this.chaosGame = new ChaosGame(newChaosGame, 400, 400); this.chaosGame.addObserver(this); } @@ -208,6 +211,7 @@ public class FractalOperations implements ChaosGameObserver { public ChaosGameDescription getDescription() { return chaosGame.getDescription(); } + @Override public void update(ChaosGame chaosGame) { updateImage(); diff --git a/src/main/java/edu/ntnu/idatt2003/view/components/TextFields.java b/src/main/java/edu/ntnu/idatt2003/view/components/TextFields.java index 839c84aa83f98ddc3aa341d4c1c7b1b6abc4dfe2..ed7e354458c583560e5448786ea8e2fac1909603 100644 --- a/src/main/java/edu/ntnu/idatt2003/view/components/TextFields.java +++ b/src/main/java/edu/ntnu/idatt2003/view/components/TextFields.java @@ -12,6 +12,8 @@ public class TextFields extends Subject { private TextField yminInput; private TextField xmaxInput; private TextField ymaxInput; + private TextField realPartInput; + private TextField imaginaryPartInput; /** * Constructs a TextFields object. @@ -39,6 +41,11 @@ public class TextFields extends Subject { xmaxInput.setPromptText("X max"); ymaxInput = new TextField(); ymaxInput.setPromptText("Y max"); + + realPartInput = new TextField(); + realPartInput.setPromptText("Real part"); + imaginaryPartInput = new TextField(); + imaginaryPartInput.setPromptText("Imaginary part"); } public TextField getAddIterationInput() { @@ -60,5 +67,14 @@ public class TextFields extends Subject { public TextField getyMaxInput() { return ymaxInput; } + + public TextField getRealPartInput() { + return realPartInput; + } + + public TextField getImaginaryPartInput() { + return imaginaryPartInput; + } + } diff --git a/src/main/java/edu/ntnu/idatt2003/view/scenes/Scene.java b/src/main/java/edu/ntnu/idatt2003/view/scenes/Scene.java index c6efe6d157bdc2ad0f129ad50d1a3009b0544509..66500eeb3d8cfe7bae0fe9fcee7780f9489867a8 100644 --- a/src/main/java/edu/ntnu/idatt2003/view/scenes/Scene.java +++ b/src/main/java/edu/ntnu/idatt2003/view/scenes/Scene.java @@ -1,7 +1,6 @@ package edu.ntnu.idatt2003.view.scenes; import edu.ntnu.idatt2003.controller.*; -import edu.ntnu.idatt2003.controller.LabelObserver; import edu.ntnu.idatt2003.model.*; import edu.ntnu.idatt2003.view.components.*; import javafx.geometry.Insets; @@ -38,6 +37,7 @@ public class Scene { private VBox inputBox; // Container for all input fields private VBox matrixVectorBox; // Container for the matrix and vector input fields private HBox topBox; + private VBox inputContainer; private ButtonObserver buttonObserver; private ComboBoxObserver comboBoxObserver; private LabelObserver labelObserver; @@ -53,11 +53,10 @@ public class Scene { textFields = new TextFields(); initializeComponents(); fractalOperations = new FractalOperations(imageView, fractalType); - buttonObserver = new ButtonObserver(buttons, fractalOperations, textFields, iterationsLabel); + buttonObserver = new ButtonObserver(buttons, fractalOperations, textFields, iterationsLabel, inputContainer); comboBoxObserver = new ComboBoxObserver(comboBoxes, fractalOperations); labelObserver = new LabelObserver(buttons, comboBoxes, textFields, iterationsLabel); textFieldObserver = new TextFieldObserver(fractalOperations, textFields); - createMaxMinVectorInput(); // Add listener to ComboBox to handle dynamic addition of C input fields comboBoxes.getComboBoxFractal().getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { @@ -66,20 +65,22 @@ public class Scene { removeFractalFromFileBox(); addSaveFractalToFileButton(); addCInputBox(); + buttonObserver.setInputContainer(inputContainer); } else if ("Sierpinski Triangle".equals(newValue)) { removeMatrixVectorInputBoxes(); removeCInputBox(); removeFractalFromFileBox(); addMatrixVectorInputBoxes(); addSaveFractalToFileButton(); - } else if ( "Barnsley Fern".equals(newValue)) { + buttonObserver.setInputContainer(inputContainer); + } else if ("Barnsley Fern".equals(newValue)) { removeMatrixVectorInputBoxes(); removeCInputBox(); removeFractalFromFileBox(); addMatrixVectorInputBoxes(); addSaveFractalToFileButton(); - } - else if ("Fractal From File".equals(newValue)) { + buttonObserver.setInputContainer(inputContainer); + } else if ("Fractal From File".equals(newValue)) { removeCInputBox(); removeMatrixVectorInputBoxes(); addFractalFromFileBox(); @@ -96,6 +97,8 @@ public class Scene { } else if ("Fractal From File".equals(fractalType)) { addFractalFromFileBox(); } + + createMaxMinVectorInputAndUpdateAll(); } private void initializeComponents() { @@ -130,7 +133,6 @@ public class Scene { // Initialize TextFields TextField addIterationInput = textFields.getAddIterationInput(); - // Set the style of the labels iterationsLabel.getStyleClass().add("iterationLabel"); addIterationInput.getStyleClass().add("addIterationInput"); @@ -190,13 +192,12 @@ public class Scene { // Create a scene with the root and set the CSS style scene = new javafx.scene.Scene(root, 1400, 830); scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm()); - } private void addCInputBox() { if (cBox == null) { cBox = createCInputBox(); - inputBox.getChildren().add(cBox); + inputBox.getChildren().addFirst(cBox); } } @@ -208,14 +209,12 @@ public class Scene { } private VBox createCInputBox() { - Label cLabel = new Label("Update constant C"); - // Initialize the update C button Button updateCButton = new Button("Update C"); Button resetToDefaultButton = new Button("Reset to Default fractal"); - // Initialize TextFields - TextField realPartInput = new TextField(); - TextField imaginaryPartInput = new TextField(); + + TextField realPartInput = textFields.getRealPartInput(); + TextField imaginaryPartInput = textFields.getImaginaryPartInput(); realPartInput.getStyleClass().add("cInput"); imaginaryPartInput.getStyleClass().add("cInput"); @@ -223,6 +222,11 @@ public class Scene { realPartInput.setPromptText("Real part of C"); imaginaryPartInput.setPromptText("Imaginary part of C"); + JuliaTransform julia = (JuliaTransform) fractalOperations.getChaosGame().getDescription().getTransforms().getFirst(); + + realPartInput.setText(String.valueOf(julia.getPoint().getReal())); + imaginaryPartInput.setText(String.valueOf(julia.getPoint().getImaginary())); + VBox cBox = new VBox(5); cBox.getChildren().addAll(cLabel, realPartInput, imaginaryPartInput, updateCButton, resetToDefaultButton); cBox.setPadding(new Insets(0, 0, 0, 0)); @@ -241,13 +245,13 @@ public class Scene { Vector2D upperRight = new Vector2D(xMax, yMax); fractalOperations.updateMinAndMaxFractal(lowerLeft, upperRight); } catch (NumberFormatException e) { - // Handle invalid input System.out.println("Invalid input for real or imaginary part of C."); } }); resetToDefaultButton.setOnAction(event -> { fractalOperations.setFractalToJuliaSet(); + updateVectorInputFields(); }); return cBox; @@ -301,9 +305,7 @@ public class Scene { lowerMatrixRow.getChildren().addAll(matrixInput3, matrixInput4); matrixBox.getChildren().addAll(upperMatrixRow, lowerMatrixRow); - vectorBox.getChildren().addAll(vectorInput1, vectorInput2); - matrixVectorBox.getChildren().addAll(matrixBox, vectorBox); return matrixVectorBox; } @@ -312,29 +314,25 @@ public class Scene { if (matrixVectorBox == null) { matrixVectorBox = new VBox(5); matrixVectorBox.setPadding(new Insets(5)); - VBox inputContainer = new VBox(5); + inputContainer = new VBox(5); inputContainer.setPadding(new Insets(0)); Button addMoreButton = new Button("Add More"); addMoreButton.setOnAction(event -> { - HBox newInputBox = createMatrixVectorInputBox(new AffineTransform2D(new Matrix2x2(0,0,0,0), new Vector2D(0,0))); + HBox newInputBox = createMatrixVectorInputBox(new AffineTransform2D(new Matrix2x2(0, 0, 0, 0), new Vector2D(0, 0))); inputContainer.getChildren().add(0, newInputBox); }); - Button updateMatrixVectorButton = new Button("Update Matrix and Vector"); - updateMatrixVectorButton.setOnAction(event -> { - // Handle updating the matrix and vector - updateAffineTransforms(inputContainer); - }); - Button resetToDefaultButton = new Button("Reset to Default fractal"); resetToDefaultButton.setOnAction(event -> { - resetToDefaultFractal(inputContainer, addMoreButton, updateMatrixVectorButton, resetToDefaultButton); + resetToDefaultFractal(inputContainer, addMoreButton, resetToDefaultButton); + updateVectorInputFields(); }); - resetToDefaultFractal(inputContainer, addMoreButton, updateMatrixVectorButton, resetToDefaultButton); + resetToDefaultFractal(inputContainer, addMoreButton, resetToDefaultButton); matrixVectorBox.getChildren().add(inputContainer); - inputBox.getChildren().add(matrixVectorBox); + inputBox.getChildren().addFirst(matrixVectorBox); + } } @@ -359,81 +357,16 @@ public class Scene { } } - private void updateAffineTransforms(VBox inputContainer) { - List<AffineTransform2D> transforms = new ArrayList<>(); - for (int i = 0; i < inputContainer.getChildren().size() - 3; i++) { // exclude the last three buttons - HBox matrixVectorBox = (HBox) inputContainer.getChildren().get(i); - VBox matrixBox = (VBox) matrixVectorBox.getChildren().get(0); - VBox vectorBox = (VBox) matrixVectorBox.getChildren().get(1); - - HBox upperMatrixRow = (HBox) matrixBox.getChildren().get(1); - HBox lowerMatrixRow = (HBox) matrixBox.getChildren().get(2); - - TextField matrixInput1 = (TextField) upperMatrixRow.getChildren().get(0); - TextField matrixInput2 = (TextField) upperMatrixRow.getChildren().get(1); - TextField matrixInput3 = (TextField) lowerMatrixRow.getChildren().get(0); - TextField matrixInput4 = (TextField) lowerMatrixRow.getChildren().get(1); - - TextField vectorInput1 = (TextField) vectorBox.getChildren().get(1); // corrected index - TextField vectorInput2 = (TextField) vectorBox.getChildren().get(2); // corrected index - - try { - double m00 = Double.parseDouble(matrixInput1.getText()); - double m01 = Double.parseDouble(matrixInput2.getText()); - double m10 = Double.parseDouble(matrixInput3.getText()); - double m11 = Double.parseDouble(matrixInput4.getText()); - double v0 = Double.parseDouble(vectorInput1.getText()); - double v1 = Double.parseDouble(vectorInput2.getText()); - - AffineTransform2D transform = new AffineTransform2D(new Matrix2x2(m00, m01, m10, m11), new Vector2D(v0, v1)); - transforms.add(transform); - } catch (NumberFormatException e) { - System.out.println("Invalid input for matrix or vector values."); - // You can also add a dialog box here to notify the user - } - } - - double xMin, yMin, xMax, yMax; - - try { - xMin = Double.parseDouble(textFields.getxMinInput().getText()); - yMin = Double.parseDouble(textFields.getyMinInput().getText()); - xMax = Double.parseDouble(textFields.getxMaxInput().getText()); - yMax = Double.parseDouble(textFields.getyMaxInput().getText()); - } catch (NumberFormatException e) { - // Set to default values if parsing fails - if ("Barnsley Fern".equals(comboBoxes.getComboBoxFractal().getValue())) { - xMin = -2.5; - yMin = 0; - xMax = 2.5; - yMax = 10; - } else { - xMin = 0; - yMin = 0; - xMax = 1; - yMax = 1; - } - - Vector2D lowerLeft = new Vector2D(xMin, yMin); - Vector2D upperRight = new Vector2D(xMax, yMax); - - ChaosGameDescription description = new ChaosGameDescription(Arrays.asList(transforms.toArray(new AffineTransform2D[0])), lowerLeft, upperRight); - -// Update the fractal operations with the new description - fractalOperations.updateMatrixAndVector(description); - } - } - - private void resetToDefaultFractal(VBox inputContainer, Button addMoreButton, Button updateMatrixVectorButton, Button resetToDefaultButton) { + private void resetToDefaultFractal(VBox inputContainer, Button addMoreButton, Button resetToDefaultButton) { inputContainer.getChildren().clear(); if ("Barnsley Fern".equals(comboBoxes.getComboBoxFractal().getValue())) { fractalOperations.setFractalToBransleysFern(); - AffineTransform2D[] transforms = fractalOperations.getDescription().getTransforms().toArray(new AffineTransform2D[0]); - inputContainer.getChildren().addAll(createMatrixVectorInputBox(transforms[0]), createMatrixVectorInputBox(transforms[1]), createMatrixVectorInputBox(transforms[2]), createMatrixVectorInputBox(transforms[3]), addMoreButton, updateMatrixVectorButton, resetToDefaultButton); + AffineTransform2D[] transforms = fractalOperations.getDescription().getTransforms().toArray(new AffineTransform2D[0]); + inputContainer.getChildren().addAll(createMatrixVectorInputBox(transforms[0]), createMatrixVectorInputBox(transforms[1]), createMatrixVectorInputBox(transforms[2]), createMatrixVectorInputBox(transforms[3]), addMoreButton, resetToDefaultButton); } else if ("Sierpinski Triangle".equals(comboBoxes.getComboBoxFractal().getValue())) { fractalOperations.setFractalToSierpinskiTriangle(); - AffineTransform2D[] transforms = fractalOperations.getDescription().getTransforms().toArray(new AffineTransform2D[0]); - inputContainer.getChildren().addAll(createMatrixVectorInputBox(transforms[0]), createMatrixVectorInputBox(transforms[1]), createMatrixVectorInputBox(transforms[2]), addMoreButton, updateMatrixVectorButton, resetToDefaultButton); + AffineTransform2D[] transforms = fractalOperations.getDescription().getTransforms().toArray(new AffineTransform2D[0]); + inputContainer.getChildren().addAll(createMatrixVectorInputBox(transforms[0]), createMatrixVectorInputBox(transforms[1]), createMatrixVectorInputBox(transforms[2]), addMoreButton, resetToDefaultButton); } } @@ -441,14 +374,14 @@ public class Scene { fractalOperations.updateMinAndMaxFractal(minCoords, maxCoords); } - public void addSaveFractalToFileButton(){ - Button saveFractalToFileButton = buttons.getBtnSaveFractalToFile(); + public void addSaveFractalToFileButton() { + Button saveFractalToFileButton = buttons.getBtnSaveFractalToFile(); if (saveFractalToFileButton != null && !topBox.getChildren().contains(saveFractalToFileButton)) { topBox.getChildren().add(saveFractalToFileButton); - } + } } - public void createMaxMinVectorInput(){ + public void createMaxMinVectorInputAndUpdateAll() { TextField xMinInput = textFields.getxMinInput(); TextField yMinInput = textFields.getyMinInput(); TextField xMaxInput = textFields.getxMaxInput(); @@ -468,32 +401,34 @@ public class Scene { xMaxInput.setText(String.valueOf(maxCoords.getX0())); yMaxInput.setText(String.valueOf(maxCoords.getX1())); + updateVectorInputFields(); + HBox MinBox = new HBox(5); HBox MaxBox = new HBox(5); MinBox.getChildren().addAll(xMinInput, yMinInput); MaxBox.getChildren().addAll(xMaxInput, yMaxInput); - Button updateMinMaxButton = new Button("Update Min and Max vector"); + buttonObserver.setInputContainer(inputBox); - VBox MinMaxAll = new VBox(5); - MinMaxAll.getChildren().addAll(MaxLabel, MaxBox, MinLabel, MinBox, updateMinMaxButton); + Button updateAllButton = buttons.getBtnUpdateAll(); - updateMinMaxButton.setOnAction(event -> { - try { - fractalOperations.resetIterations(); - double xMin = Double.parseDouble(xMinInput.getText()); - double yMin = Double.parseDouble(yMinInput.getText()); - double xMax = Double.parseDouble(xMaxInput.getText()); - double yMax = Double.parseDouble(yMaxInput.getText()); - updateMinAndMax(new Vector2D(xMin, yMin), new Vector2D(xMax, yMax)); - } catch (NumberFormatException e) { - System.out.println("Invalid input for min or max values."); - } - }); + VBox MinMaxAll = new VBox(5); + MinMaxAll.getChildren().addAll(MaxLabel, MaxBox, MinLabel, MinBox, updateAllButton); inputBox.getChildren().add(MinMaxAll); } + public void removeMaxMinVectorInput() { + inputBox.getChildren().remove(1); + } + + public void updateVectorInputFields() { + textFields.getxMinInput().setText(String.valueOf(fractalOperations.getChaosGame().getDescription().getMinCoords().getX0())); + textFields.getyMinInput().setText(String.valueOf(fractalOperations.getChaosGame().getDescription().getMinCoords().getX1())); + textFields.getxMaxInput().setText(String.valueOf(fractalOperations.getChaosGame().getDescription().getMaxCoords().getX0())); + textFields.getyMaxInput().setText(String.valueOf(fractalOperations.getChaosGame().getDescription().getMaxCoords().getX1())); + } + public void setUpStage(Stage primaryStage) { primaryStage.setTitle("ChaosGame"); primaryStage.setScene(scene);