Skip to content
Snippets Groups Projects
Commit dac97811 authored by Magnus Eik's avatar Magnus Eik
Browse files

Improve GUI layout

parent 0a705642
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
......@@ -21,11 +22,9 @@ import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration;
......@@ -149,7 +148,14 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
scene.heightProperty().addListener((observable, oldValue, newValue) -> {
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 height of the sideMenu to the height of the scene
sideMenu.prefHeightProperty().bind(scene.heightProperty());
}
/**
* Initialize the components of the GUI.
*/
......@@ -285,7 +291,18 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
*/
private void initializeSideMenu() {
// Create Buttons
// Create a Border style
Border blackBorder = new Border(new BorderStroke(Color.BLACK,
BorderStrokeStyle.SOLID,
new CornerRadii(10),
new BorderWidths(5)));
// Create Canvas Header
Label canvasLabel = new Label("Play Controls");
canvasLabel.setAlignment(Pos.CENTER);
canvasLabel.setFont(new Font("Arial",20));
// Create Canvas Buttons
this.startButton = new Button("Start");
this.stopButton = new Button("Stop");
this.newButton = new Button("New");
......@@ -312,23 +329,43 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
// Parameters
VBox parameterBox = new VBox();
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 bottomButtonBox = new VBox();
// Step Count GUI
VBox stepCountBox = new VBox();
Label stepCountLabel = new Label("Step Count");
stepCountLabel.setFont(new Font("Arial",20));
stepCountLabel.setAlignment(Pos.CENTER);
this.stepCountTextField = new TextField();
this.stepCountTextField.setTextFormatter(Formatter.getIntFormatter()); // Set formatter
this.stepCountTextField.setTextFormatter(Formatter.getIntFormatter());
stepCountTextField.setPrefHeight(5);
stepCountTextField.setPrefWidth(50);
stepCountBox.getChildren().addAll(stepCountLabel,stepCountTextField);
stepCountBox.setAlignment(Pos.CENTER);
stepCountBox.setPadding(new Insets(5,5,5,5));
stepCountBox.setBorder(blackBorder);
// Create a Box for Coordinate Controls
VBox coordinateControlBox = new VBox();
coordinateControlBox.setPadding(new Insets(5, 5, 5, 5));
// Coordinate Control GUI
Label coordinateHeader = new Label("Coordinate Control");
coordinateHeader.setFont(new Font("Arial", 20));
coordinateHeader.setAlignment(Pos.CENTER);
coordinateControlBox.getChildren().add(coordinateHeader);
// Minimum Coordinates GUI
VBox minCoordinatesBox = new VBox();
Label minCoordinatesLabel = new Label("Min. Coordinates");
Label minCoordinatesLabel = new Label("Min. Coordinates");
VBox minCoordinatesBox = new VBox();
TextField minimumCoordinatesTextFieldX = createCoordinateTextField("x");
TextField minimumCoordinatesTextFieldY = createCoordinateTextField("y");
......@@ -354,51 +391,80 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
Tooltip.install(changeMaximumCoordinatesButton,changeMaximumCoordinatesButtonTooltip);
maxCoordinatesBox.getChildren().addAll(maxCoordinatesLabel,
maxCoordsHBox,changeMaximumCoordinatesButton);
coordinateControlBox.getChildren().addAll(minCoordinatesBox,maxCoordinatesBox);
coordinateControlBox.setAlignment(Pos.CENTER);
coordinateControlBox.setBorder(blackBorder);
Label colorHeaderLabel = new Label("Color Control");
colorHeaderLabel.setFont(new Font("Arial",20));
colorHeaderLabel.setAlignment(Pos.CENTER);
VBox colorVBox = new VBox();
HBox colorBox = new HBox();
Label colorLabel = new Label("Use color");
Label colorLabel = new Label("Show Redrawn Pixels");
this.colorCheckBox = new CheckBox();
Tooltip colorCheckBoxTooltip = new Tooltip("Change pixel color for pixels drawn multiple times");
Tooltip.install(colorCheckBox,colorCheckBoxTooltip);
Region colorRegion = new Region();
colorRegion.setMinWidth(30);
colorBox.getChildren().addAll(colorCheckBox, colorRegion, colorLabel);
colorVBox.setPadding(new Insets(5,5,5,5));
colorVBox.getChildren().addAll(colorHeaderLabel,colorBox);
colorVBox.setAlignment(Pos.CENTER);
colorVBox.setBorder(blackBorder);
Region separator1 = new Region();
separator1.setMinHeight(10);
Region separator2 = new Region();
separator2.setMinHeight(10);
//Create spacing
Region space = new Region();
Region spacer = new Region();
space.setMinHeight(10);
spacer.setMinHeight(10);
// Fill parameter box
parameterBox.getChildren().addAll(stepCountBox, minCoordinatesBox, maxCoordinatesBox);
parameterBox.getChildren().addAll(stepCountBox, spacer, coordinateControlBox);
parameterBox.setPadding(new Insets(10));
// Add basic control buttons
controlButtonBox.getChildren().addAll(startButton,stopButton,newButton,clearButton);
controlButtonBox.getChildren().addAll(canvasLabel,startButton, stopButton,newButton,clearButton);
controlButtonBox.setAlignment(Pos.CENTER);
controlButtonBox.setSpacing(5);
sideMenu.getChildren().add(controlButtonBox);
// Add spacing
Region space = new Region();
space.setMinHeight(10);
sideMenu.getChildren().add(space);
// Add fractal radio buttons
radioButtonBox.getChildren().addAll(sierpinskiRadioButton, barnsleyRadioButton, juliaRadioButton,
//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);
sideMenu.getChildren().addAll(separator1, colorBox, separator2);
sideMenu.getChildren().addAll(separator1, colorVBox, separator2);
//this.initializeColorButtonHandler();
// Add parameter VBox
sideMenu.getChildren().add(parameterBox);
// Add file buttons and quit button
bottomButtonBox.getChildren().addAll(loadFractalFromFileButton,writeFractalToFileButton,quitButton);
Label menuButtonLabel = new Label("Menu Controls");
menuButtonLabel.setFont(new Font("Arial",20));
menuButtonLabel.setAlignment(Pos.CENTER);
bottomButtonBox.getChildren().addAll(menuButtonLabel,loadFractalFromFileButton,writeFractalToFileButton,quitButton);
bottomButtonBox.setSpacing(5);
bottomButtonBox.setBorder(blackBorder);
bottomButtonBox.setAlignment(Pos.CENTER);
bottomButtonBox.setPadding(new Insets(5,5,5,5));
sideMenu.getChildren().add(bottomButtonBox);
// Add padding
......@@ -420,7 +486,7 @@ public ChaosGameGui(Stage primaryStage) throws IOException {
VBox rightVBox = new VBox();
rightVBox.getChildren().addAll(sideMenuButtonBox, sideMenu);
this.sideMenu.setStyle("-fx-background-color: lightgrey; -fx-background-radius: 3;");
this.sideMenu.setStyle("-fx-background-color: lightblue; -fx-background-radius: 5;");
this.borderPane = new BorderPane();
this.borderPane.setCenter(imageView);
......
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