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

Created basic combobox solution. Not yet fully functional.

parent ed328721
No related branches found
No related tags found
No related merge requests found
Showing
with 51 additions and 24 deletions
......@@ -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;
}
}
......@@ -64,7 +64,6 @@ public class ChaosGameFileHandler {
}
// Read the transforms
while (scanner.hasNextDouble()) {
double a00 = scanner.nextDouble();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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();
......
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)
......
Affine2D # Type of transform
Test2
Barnsley
-2.65, 0 # lower left
2.65, 10 # upper right
0, 0, 0, .16, 0, 0 # transforms
......
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
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